Sai Stuff to Developers

September 14, 2007

Download file from webpage without showing file URL

Filed under: DotNet — tosaik @ 6:50 am
Tags:

THis code sample shows how you can allow visitors to download a file from the webpage without exposing the path or hyperlink of the file.

if (filename != “”)
{
          string path = Server.MapPath(filename);
          System.IO.FileInfo file = new System.IO.FileInfo(path);
          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);
                   Response.End();
          }
          else
          {
                   Response.Write(“This file does not exist.”);
          }
}

Advertisements

1 Comment »

  1. coupstick anaptomorphidae damnify drawglove saddler unhatingly reviewable philosophization
    Tim Littell Striper Guide Service
    http://www.wired.com/news/business/0,1367,53868,00.html

    Comment by Geraldine Stewart — June 13, 2008 @ 5:33 pm | Reply


RSS feed for comments on this post. TrackBack URI

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

Create a free website or blog at WordPress.com.

%d bloggers like this: