質問

I am trying to use webclient to download a file from codeplex.com. I can download a file but it ends up being the html file not the .zip. It looks like they have a script that redirects to the download file.

Anyone have any experience with this?

Here's my code:

protected void Page_Load(object sender, EventArgs e)
        {

        }

        protected void Download_Click(object sender, EventArgs e)
        {
            WebClient webClient = new WebClient();
            webClient.DownloadFileCompleted += new AsyncCompletedEventHandler(Completed);
            webClient.DownloadProgressChanged += new DownloadProgressChangedEventHandler(ProgressChanged);
            webClient.DownloadFileAsync(new Uri("http://dotnetnuke.codeplex.com/downloads/get/815672"), @"C:\DNN_Platform_07.02.02_Install.zip");
        }

        private void ProgressChanged(object sender, DownloadProgressChangedEventArgs e)
        {
            progressBar.Value = e.ProgressPercentage;
        }

        private void Completed(object sender, AsyncCompletedEventArgs e)
        {
            txtStatus.Text("Download completed!");
        }
役に立ちましたか?

解決

Modify the download URL to this and check if you are able to download.

webClient.DownloadFileAsync(new Uri("http://download-codeplex.sec.s-msft.com/Download/Release?ProjectName=dotnetnuke&DownloadId=815672&FileTime=130397249034130000&Build=20885"), @"C:\DNN_Platform_07.02.02_Install.zip");

That is the actual URL obtained by inspecting the site with Firebug, when the download request is fired off from the previous URL. While this works for the current release, I'm not really sure if this will fetch the latest builds over time. I suspect that the FileTime will change.

ライセンス: CC-BY-SA帰属
所属していません StackOverflow
scroll top