We help IT Professionals succeed at work.

Dowloading a File?

directxBOB
directxBOB asked
on
Medium Priority
221 Views
Last Modified: 2010-04-15
I have an application that creates a file and I want to have it downloaded by the user. How do I go about giving that file to the user via code?

I have created an ASP.NET site and I am using C# in the background.

Cheers
Comment
Watch Question

Commented:
Try this
System.IO.FileInfo file = New System.IO.FileInfo(path) //path is a path name for the file u created
If (file.Exists)
{
   Response.Clear();
   Response.AddHeader("Content-Disposition", "attachment; filename=" & file.Name);
   Response.AddHeader("Content-Length", file.Length.ToString());
   Response.ContentType = "application/octet-stream";
   Response.WriteFile(file.FullName);
}
else
{
   Response.Write("This file does not exist.");
}

Open in new window

Explore More ContentExplore courses, solutions, and other research materials related to this topic.