Wrox Programmer Forums
ASP.NET 2.0 Professional If you are an experienced ASP.NET programmer, this is the forum for your 2.0 questions. Please also see the Visual Web Developer 2005 forum.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the ASP.NET 2.0 Professional section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
Old June 23rd, 2006, 03:29 PM
Registered User
Join Date: Apr 2006
Posts: 9
Thanks: 0
Thanked 0 Times in 0 Posts
Default Hide downloaded filename

Our company posts PDF files on our server for clients. We would like to restrict access to the files to clients, but if an individual knows the URL for the file they can download it. We use long, randomly generated filenames already. We would like to hide the real filename or generate a temporary name at time of request to prevent users from saving the path to the file in favorites or using history to retrieve the file.

Old June 24th, 2006, 04:05 AM
Authorized User
Join Date: Jun 2006
Posts: 13
Thanks: 0
Thanked 0 Times in 0 Posts

Hi There,

The a strategy you could take would be to load the file from the file system into a stream, and then BinaryWrite the file to the browser giving it a different filename. This would involve making a separate web form to which you would pass a the filename and probably a date/time to ensure the link can only be used once in say, 1 minute or so. This web form would then perform the BinaryWrite for you, presenting the file to the user.

The code to present the file to the user would be along the lines of the below. (No need to reinvent the wheel, this code is from http://www.eggheadcafe.com/articles/20011006.asp)
FileStream MyFileStream = new FileStream(@"d:\inetpub\wwwroot\small.pdf", FileMode.Open);
long FileSize;
FileSize = MyFileStream.Length;
byte[] Buffer = new byte[(int)FileSize];
MyFileStream.Read(Buffer, 0, (int)MyFileStream.Length);
Response.AddHeader( "content-disposition","attachment; filename=MyPDF.PDF");
Notice the "filename=" in the header added to the Response.
This would be where you present your altered filename.

Hope this helps,

Similar Threads
Thread Thread Starter Forum Replies Last Post
downloaded code Joseph BOOK: Beginning SQL 5 December 23rd, 2007 09:35 PM
can't understand this code I downloaded am6019a VB How-To 1 July 7th, 2006 09:11 AM
problem in getting images downloaded Mystic C# 0 July 6th, 2006 04:23 PM
how to find dll is downloaded or not sangeet_83 ASP.NET 2.0 Professional 0 May 3rd, 2006 03:56 AM
ThePhile C# Downloaded code aruny2kprasad General .NET 3 April 16th, 2004 03:02 AM

Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.