This blog is about the dotnet.all types of codes,news about dotnet including asp.net,vb.net,c# and know about new dotnet technology.programing in asp.net,vb.net,c#, ajax, AJAX tech support for .net and discuss the new technology in dotnet.ncluding asp.net,vb.net,c# and know about new dotnet technology.programing in asp.net,vb.net,c#, ajax, AJAX tech support for .net and discuss the new technology in dotnet.asp.net programming,dot net programming,dotnet programs,dotnet source code,source code.

Free Hosting

Free Hosting

Showing posts with label ASP.NET code to attach files. Show all posts
Showing posts with label ASP.NET code to attach files. Show all posts

Sunday, November 2, 2008

Writing a file to the browser as an attatchment(asp.net code)

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();

dotnet(.Net) Project Source code Downloads and Tutorials

Email Subscrption



Enter your email address:

Delivered by FeedBurner

Feedburner Count

Unique Visitor

Design by araba-cı | MoneyGenerator Blogger Template by GosuBlogger