Click here to Skip to main content
16,004,924 members
Please Sign up or sign in to vote.
1.00/5 (2 votes)
See more:
I try to downlaod .msi file, its downloaded but (it size is 0 byte).I cannot understand why its happen? please suggest me correct code its urgent. And also suggest how to install downloaded file through c# code.

What I have tried:

private void btnUpdate_Click(object sender, EventArgs e)
{
string url = @"http://www.http://careusa.co/update_files/PC_Cleaner.msi";
// Create an instance of WebClient
WebClient client = new WebClient();
// Hookup DownloadFileCompleted Event
client.DownloadFileCompleted += new AsyncCompletedEventHandler(client_DownloadFileCompleted);

// Start the download and copy the file to c:\temp
client.DownloadFileAsync(new Uri(url), @"C:\NewFolder\PC_Cleaner.msi");//path-where i want to download---

}

void client_DownloadFileCompleted(object sender, AsyncCompletedEventArgs e)
{
MessageBox.Show("File downloaded");

string installerFilePath; //For install
installerFilePath = @"C:\NewFolder\PC_Cleaner.msi";
System.Diagnostics.Process installerProcess;
installerProcess = System.Diagnostics.Process.Start(installerFilePath, "/q");
while (installerProcess.HasExited == false)
{
//indicate progress to user
Application.DoEvents();
System.Threading.Thread.Sleep(250);
}
MessageBox.Show("done installing");
}
Posted
Updated 20-Apr-16 2:52am
Comments
Sergey Alexandrovich Kryukov 20-Apr-16 3:38am    
If the size of the file is 0, the statement "its downloaded" is a great exaggeration. :-)
It may be not downloaded by very many reasons.
—SA
Member 11868117 20-Apr-16 5:58am    
I mean to say that file is downloaded but when I check the size it is 0 KB why? and my file is 937 kb
Sergey Alexandrovich Kryukov 20-Apr-16 6:43am    
I can only repeat what I just said. If the file is really downloaded, its size is exactly the same as original. :-)
—SA
Richard MacCutchan 20-Apr-16 5:41am    
If is is urgent then just do it manually via your browser.
Member 11868117 20-Apr-16 5:55am    
Plz send me correct answer.if you have any idea to download MSI file from server in c#.

1 solution

write a correct URL then try again... http://www.http://[^]
 
Share this answer
 
v2
Comments
Richard MacCutchan 20-Apr-16 8:54am    
Do you know what a correct URL looks like?
Richard Deeming 20-Apr-16 9:01am    
Well the OP doesn't - that's the start of the URL in the question. :)
Richard MacCutchan 20-Apr-16 9:31am    
If the above is supposed to be a solution then it should show the correction.
Philippe Mori 20-Apr-16 10:48am    
One cannot know the right address if he does not know web site structure!
Member 11868117 20-Apr-16 11:11am    
Sorry I knew this URL is incorrect by mistake I wrote this URL in solution but in my project I wrote correct.plz anybody know solution of this question then reply me

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900