Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

.NET OneDrive Api Create Folder issue

I'm trying to create a folder withing my Apps/[appName] folder.

Here is the code:

var request = OneDriveService.Drive.Special.AppRoot.Request().CreateAsync(new Item()
{
    Name = name,
});

request.Wait();

But I keep getting the error message:

{Code: invalidRequest Throw site: 1c0e.2859 Message: The name in the provided oneDrive.item does not match the name in the URL }

Does anyone know what it means?

like image 456
Krika Avatar asked Apr 08 '26 03:04

Krika


1 Answers

Instead of CreateAsync I write this code:

        try
        {
            var documentsBuilder = this.oneDriveClient.Drive.Root.ItemWithPath("Documents");
            var children = await documentsBuilder.Children.Request().GetAsync();
            // try to find existing folder
            var folder = children.FirstOrDefault(c => c.Name.Equals("Some folder"));

            // create it if it doesn't exist
            if (folder == null)
            {
                var newFolder = new Item { Name = "Some folder", Folder = new Folder() };
                await documentsBuilder.Children.Request().AddAsync(newFolder);
            }
        }
        catch (OneDriveException exception)
        {
            throw;
        }
like image 144
Barabas Avatar answered Apr 10 '26 15:04

Barabas



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!