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");
}