Sai Stuff to Developers

September 14, 2007

Download file from webpage without showing file URL

Filed under: DotNet — tosaik @ 6:50 am

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.AddHeader(“Content-Disposition”, “attachment; filename=” + file.Name);
                   Response.AddHeader(“Content-Length”, file.Length.ToString());
                   Response.ContentType = “application/octet-stream”;
                   Response.Write(“This file does not exist.”);


1 Comment »

  1. coupstick anaptomorphidae damnify drawglove saddler unhatingly reviewable philosophization
    Tim Littell Striper Guide Service,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: Logo

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

Google+ photo

You are commenting using your Google+ 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 )


Connecting to %s

Create a free website or blog at

%d bloggers like this: