• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 212
  • Last Modified:

Dowloading a File?

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
0
directxBOB
Asked:
directxBOB
1 Solution
 
jax79sgCommented:
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

0

Featured Post

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now