private void DownLoadFile()
{
try
{
// string ophos = "&OPHOS=OPHOS";
// string opcd = "&OPCD=OPCD";
string ophos = "";
string opcd = "";
string FileURL = ImageURL + fileName + ophos + opcd;
if(!Directory.Exists(Application.StartupPath+" //update"))
{
Directory.CreateDirectory(Application.StartupPath+" //update");
}
pathName = Application.StartupPath+" //update";
HttpWebRequest hwr = (HttpWebRequest)HttpWebRequest.Create(FileURL);
hwr.Timeout = 30000;
this.label1.Text = "正在连接。。。";
HttpWebResponse hwrs = (HttpWebResponse)hwr.GetResponse();
Stream receiveStream = hwrs.GetResponseStream();
this.label1.Text = "已连接,正在下载更新文件("+fileName+"),请稍侯。。。";
MemoryStream ms = new MemoryStream();
byte[] bt;
while(true)
{
bt = new byte[1024];
int cnt = receiveStream.Read(bt, 0, 1024);
ms.Write(bt,0,cnt);
if (cnt == 0)
break;
}
byte[] byteImage = new byte[ms.Length];
byteImage = ms.ToArray();
FileStream outStream = new FileStream(pathName.Trim() + "//" + fileName.Trim() , FileMode.Create);
outStream.Write(byteImage,0,(int)byteImage.Length);
outStream.Flush();
outStream.Close();
this.label1.Text = "完成下栽,是否现在更新?";
this.button1.Visible = true;
this.button2.Visible = true;
}
catch(Exception ex)
{
this.label1.Text = ex.ToString();
}
}
{
try
{
// string ophos = "&OPHOS=OPHOS";
// string opcd = "&OPCD=OPCD";
string ophos = "";
string opcd = "";
string FileURL = ImageURL + fileName + ophos + opcd;
if(!Directory.Exists(Application.StartupPath+" //update"))
{
Directory.CreateDirectory(Application.StartupPath+" //update");
}
pathName = Application.StartupPath+" //update";
HttpWebRequest hwr = (HttpWebRequest)HttpWebRequest.Create(FileURL);
hwr.Timeout = 30000;
this.label1.Text = "正在连接。。。";
HttpWebResponse hwrs = (HttpWebResponse)hwr.GetResponse();
Stream receiveStream = hwrs.GetResponseStream();
this.label1.Text = "已连接,正在下载更新文件("+fileName+"),请稍侯。。。";
MemoryStream ms = new MemoryStream();
byte[] bt;
while(true)
{
bt = new byte[1024];
int cnt = receiveStream.Read(bt, 0, 1024);
ms.Write(bt,0,cnt);
if (cnt == 0)
break;
}
byte[] byteImage = new byte[ms.Length];
byteImage = ms.ToArray();
FileStream outStream = new FileStream(pathName.Trim() + "//" + fileName.Trim() , FileMode.Create);
outStream.Write(byteImage,0,(int)byteImage.Length);
outStream.Flush();
outStream.Close();
this.label1.Text = "完成下栽,是否现在更新?";
this.button1.Visible = true;
this.button2.Visible = true;
}
catch(Exception ex)
{
this.label1.Text = ex.ToString();
}
}