In this article we will discuss about how to download a file in C#.Net. There are different approaches to download file in C#.Net.
Also check out:
- Delete record using enterprise library in Asp.Net
- Constraints in SQL Server 2008
- Exception Class in C#.Net
string fileName = @"E:\Filename.txt";
1st Approach:
Response.Clear();
Response.ContentType = "application/octet-stream";// "application/ms-word";
Response.AddHeader("Content-Disposition", "attachment;filename=abc.txt);
Response.WriteFile(fileName);
Response.Flush();
Response.Close();
2nd Approach:
Response.Clear();
Response.ContentType = "application/octet-stream";// "application/ms-word";
Response.AppendHeader("Content-Disposition", "attachment;filename=" + tempFile);
Response.TransmitFile(fileName);
Response.Flush();
Response.Close();
3rd Approach:
Response.Buffer = true;
Response.ContentType = "application/octet-stream";
Response.AppendHeader("Content-Disposition", "attachment; filename=" + strFileName);
Response.WriteFile(strFilePath);
Response.Flush();
Response.End();
Also check out:
- Delete record using enterprise library in Asp.Net
- Constraints in SQL Server 2008
- Exception Class in C#.Net
string fileName = @"E:\Filename.txt";
1st Approach:
Response.Clear();
Response.ContentType = "application/octet-stream";// "application/ms-word";
Response.AddHeader("Content-Disposition", "attachment;filename=abc.txt);
Response.WriteFile(fileName);
Response.Flush();
Response.Close();
2nd Approach:
Response.Clear();
Response.ContentType = "application/octet-stream";// "application/ms-word";
Response.AppendHeader("Content-Disposition", "attachment;filename=" + tempFile);
Response.TransmitFile(fileName);
Response.Flush();
Response.Close();
3rd Approach:
Response.Buffer = true;
Response.ContentType = "application/octet-stream";
Response.AppendHeader("Content-Disposition", "attachment; filename=" + strFileName);
Response.WriteFile(strFilePath);
Response.Flush();
Response.End();