0
votes

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?

2
We do not need to download files, right? Core Package 1.0.0 (old).zip and Core Package 1.1.0.zip are enough?isydmr
I'm implementing an "update checker", so first I need to list the contents to discover which files are inside. After I know the latest version, I will need to download it (to disk).SuperJMN
Yes :) and I intend to use C# to create the app.SuperJMN

2 Answers

1
votes

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();
0
votes

Selenium Web Driver is good option for tasks like that.

  1. Open Solution Explorer.
  2. Right Click on your project.
  3. Select Manage NuGet Packages..
  4. Browse and install these two : Selenium.Chrome.WebDriver and Selenium.WebDriver.
  5. You have just installed selenium to your project!

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!