Friday, September 16, 2011

Download file in C#.Net

You can download text file in the way as shown in the below in c#.Net.
string fileName = @"E:\Filename.txt";
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();

No comments:

Post a Comment