Frikha Ahmad
Frikha Ahmad

Reputation: 17

WebClient downloads corrupted files

I'm trying to download a Graph.zip file from a certain URL : https://www.dropbox.com/s/erc6ke9k1x2nle0/Graph.zip Using this code:

WebClient webClient = new WebClient();
webClient.DownloadFile("https://www.dropbox.com/s/erc6ke9k1x2nle0/Graph.zip",
                        @"Graph.zip");

Whenever I execute the code, its either corrupted and/or 0 bytes in size. Am i doing something wrong?

Upvotes: 1

Views: 229

Answers (1)

Athanasios Kataras
Athanasios Kataras

Reputation: 26362

Try to open the url from your browser: https://www.dropbox.com/s/erc6ke9k1x2nle0/Graph.zip

You'll notice that you are redirected to an intermediary page. If you save it to a zip file extention, then since the file is not really zip, it appears as corrupted to zip clients. To download dropbox files, you either need to use the rest api, or the sdk.

Check the sample console application here for an example: https://www.dropbox.com/developers/documentation/dotnet#tutorial

async Task Download(DropboxClient dbx, string folder, string file)
{
    using (var response = await dbx.Files.DownloadAsync(folder + "/" + file))
    {
        Console.WriteLine(await response.GetContentAsStringAsync());
    }
}

Upvotes: 4

Related Questions