<summary>
Web download file
</summary>
<param name= "Downloadpath" > Target address </param>
<param name= "Fullfilepath" > Original address </param>
<param name= "filename" > file name </param>
<returns></returns>
public static bool Downloadsoft (string Downloadpath, String Fullfilepath, String FileName)
{
BOOL flag = FALSE;
Try
{
if (! Directory.Exists (Downloadpath))
{
Directory.CreateDirectory (Downloadpath);
}
using (FileStream fs = new FileStream (Downloadpath + "/" + FileName, FileMode.Create))
{
Create request
WebRequest request = WebRequest.Create (Fullfilepath + FileName);
Receive response
WebResponse response = Request. GetResponse ();
Output stream
Stream Responsestream = Response. GetResponseStream ();
byte[] bufferbytes = new byte[10000];//buffer byte array
int bytesread =-1;
while ((Bytesread = Responsestream.read (bufferbytes, 0, bufferbytes.length)) > 0)
{
Fs. Write (bufferbytes, 0, bytesread);
}
if (fs. Length > 0)
{
Flag = true;
}
Turn off write
Fs. Flush ();
Fs. Close ();
}
}
catch (Exception exp)
{
return error message
}
return flag;
}
C # ASP. NET download file to local