Reputation: 13992
I've got a URL to a OneDrive folder (https://1drv.ms/f/s!AtXoQFW327DIyMwPjZhmauUCSSHXUA). Everyone with that link can access the folder via browser.
Now, my goal is to create an .NET application that, given that link, is able to get a list of the files/folders inside that folder.
Is that even possible?
Upvotes: 2
Views: 4143
Reputation: 4202
The best way to do this is to use the OneDrive API exposed via Graph.
You can read the "Using Sharing Links" documentation for full details, but you'd essentially make a call to:
https://graph.microsoft.com/v1.0/shares/u!aHR0cHM6Ly8xZHJ2Lm1zL2YvcyFBdFhvUUZXMzI3REl5TXdQalpobWF1VUNTU0hYVUE/driveItem/children
You can also use the .NET SDK to avoid making the calls to the API yourself, in which case your code would look something like:
client.Shares["u!aHR0cHM6Ly8xZHJ2Lm1zL2YvcyFBdFhvUUZXMzI3REl5TXdQalpobWF1VUNTU0hYVUE"].DriveItem.Children.Request().GetAsync();
Upvotes: 2
Reputation: 657
Selenium Web Driver is good option for tasks like that.
Selenium.Chrome.WebDriver
and Selenium.WebDriver
.So now, we need to create a driver service, and find needed elements in our website.
As far as i see, filenames are stored as a span class named signalFieldValue_03700093
.
But "Last Modified infos" are stored under this class too, i needed to skip "Last Modified infos" using the code below:
bool skip = false;
List<string> myFiles = new List<string>();
ChromeDriverService service = ChromeDriverService.CreateDefaultService();
ChromeOptions option = new ChromeOptions();
var driver = new ChromeDriver(service, option);
driver.Url = "https://1drv.ms/f/s!AtXoQFW327DIyMwPjZhmauUCSSHXUA";
driver.Manage().Timeouts().ImplicitWait = TimeSpan.FromSeconds(10);
foreach (IWebElement element in driver.FindElements(By.XPath("//span[@class='signalFieldValue_03700093']")))
{
if (!skip)
{
myFiles.Add(element.Text);
skip = true;
}
else
skip = false;
}
As a result, we have our filenames in string array named myFiles
.
Hope this helps!
Upvotes: 0