Shihan Khan
Shihan Khan

Reputation: 2188

Download a file in Dropbox using asp.net mvc

I'm using ASP.net MVC 4 and Dropbox API to download a file from my Dropbox account. I've successfully installed the api in my project and I'm following this tutorial to understand the functionalities but I'm getting an error if I run:

Specified argument was out of the range of valid values. Parameter name: path

Here is my code:

    public async Task<ActionResult> DropDls()
    {
        var dbx = new DropboxClient("MY-TOKEN");
        string folder = "My Folder";
        string file = "My File.rar";

        using (var response = await dbx.Files.DownloadAsync(folder + "/" + file))
        {
            await response.GetContentAsStringAsync();
        }

        return View();
    }

I'm a beginner to API related work, so can't figure it out what is wrong in here. What can I try next?

Upvotes: 0

Views: 2956

Answers (1)

Greg
Greg

Reputation: 16940

Non-root paths for the Dropbox API should start with "/". Your code is:

    string folder = "My Folder";
    string file = "My File.rar";

...

    using (var response = await dbx.Files.DownloadAsync(folder + "/" + file))

That will result in a path "My Folder/My File.rar", but it should actually be "/My Folder/My File.rar". So, instead, you probably want code like this instead:

    using (var response = await dbx.Files.DownloadAsync("/" + folder + "/" + file))

Upvotes: 1

Related Questions