private void button2_Click(object sender, EventArgs e)
{
Stream inStream = null;
FileStream filestream = null;
try
{
HttpWebRequest req = (HttpWebRequest)System.Net.WebRequest.Create("http://192.168.38.38/XXX/Demo.CAB");
HttpWebResponse resp = (HttpWebResponse)req.GetResponse();
inStream = resp.GetResponseStream();
long filesizeBytes = resp.ContentLength;
filestream = new FileStream("Program Files\\Demo.CAB", FileMode.OpenOrCreate, FileAccess.Write);
int length = 1024;
byte[] buffer = new byte[1025];
int bytesread = 0;
while ((bytesread = inStream.Read(buffer, 0, length)) > 0)
{
filestream.Write(buffer, 0, bytesread);
}
MessageBox.Show("Finish");
System.Diagnostics.Process mypro = new System.Diagnostics.Process();
mypro.StartInfo.FileName = "Program Files\\Demo.EXE";
mypro.StartInfo.Verb = "Open";
mypro.Start();
}
catch(Exception ex)
{
MessageBox.Show(ex.Message.ToString());
}
finally
{
if(inStream!=null)
inStream.Close();
if(filestream!=null)
filestream.Close();
Application.Exit();
}
}