This code shows you how to write a file to the browser as an attatchement which then can be saved by the user 
CODE:
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();


0 comments:
Post a Comment