»Dotnet Ads
»Message Boards
Message Boards
Dotnet Books
»Member Details
Register
Login
LogOut
Submit Code
Submit Jobs
Submit Projects
»Competition
Community
Winners
Prizes
Write For Us
Members
»Other Resources
Links
Dotnet Resources
|
Writing a file to the browser as an attatchmentThis code shows you how to write a file to the browser as an attatchement which then can be saved by the user
string ContentType;
ContentType = "Content-type: text/xml";
Response.ClearContent();
Response.ClearHeaders();
Response.Clear();
Response.Buffer = true;
Response.AddHeader("Content-Disposition", "attachment; filename=username.xml");
Response.Charset = "UTF-8";
Response.ContentType = ContentType;
FileStream outputStream1;
outputStream1 = new FileStream(@"C:filename.xml", FileMode.Open, FileAccess.Read);
MemoryStream ms;
ms = new MemoryStream((int)outputStream1.Length);
BinaryReader br;
br = new BinaryReader(outputStream1);
byte[] bytesRead = br.ReadBytes((int)outputStream1.Length);
ms.Write(bytesRead,0,(int)outputStream1.Length);
Response.OutputStream.Write(ms.ToArray(), 0, (int)ms.Length);
outputStream1.Close();
ms.Close();
br.Close();
|
|