Download a Folder or File from .NET
Hi All,
The below code is used to download the files from our .net coding...
#region downloadfile
public static bool downloadfile(string filename, string path)
{
try
{
FileStream sourceFile;
HttpResponse response = HttpContext.Current.Response;
response.ContentType = "application/x-rar-compressed";
response.AddHeader("content-disposition", "attachment; filename=" + filename + Path.GetExtension(path).ToString());
sourceFile = new FileStream(path, FileMode.Open);
long FileSize;
FileSize = sourceFile.Length;
byte[] getContent = new byte[(int)FileSize];
sourceFile.Read(getContent, 0, (int)sourceFile.Length);
sourceFile.Close();
sourceFile.Dispose();
response.BinaryWrite(getContent);
response.Flush();
response.Clear();
response.Close();
return true;
}
catch (Exception ex)
{
return false;
}
}
#endregion
Happy Coding!!!!!!!
1 comments:
Nice Start up!! Go ahead the journey with lots of .net, sql, etc like a valuable flowers.
Post a Comment