PDA

View Full Version : Hyperlink to PDF files in a folder that is protect


georgeASP
10-05-2004, 08:02 AM
What I would like to duplicate is what happens when I have a hyperlink to a data file -- the browser either automatically displays the file if it can, or offers to save it to disk.

The catch is that these are confidential files located in a folder protected by Windows 2003 Basic Authentication. I don't want the users to have the access username and password -- I want to do this programmatically. I've gotten as far as sending the file OK using a page called ViewFile.aspx, but the browser is offering to save the transmitted file to ViewFile.aspx instead of the real filename, since that is the URL that launched the process. Ooops!

Any suggestions would be greatly appreciated.

George

georgeASP
10-06-2004, 07:34 AM
Thanks, Vanessa!

Your suggestion works great! I guess I don't have to worry about authorization this way, because .net itself has authorization to access these files!

George

vmoss
10-06-2004, 09:07 AM
Hi George

I am able to programmatically cause files to download using the following code:

If File.Exists(filePath) Then
Response.Clear()

Response.AddHeader("Content-Disposition", _
"attachment; filename = " & _
cQT & UserFileName & cQT)
Response.AddHeader("Content-Length", _
filePath.Length.ToString())
Response.ContentType = "application/octet-stream"
Response.Flush()
Response.WriteFile(filePath)
Response.End()
End If

The variable 'UserFileName' is the file name that the user is prompted to Open or Save. On my test server where this is working, it doesn't matter what the file is actually called on the server, that is defined in variable 'filePath'. I'm not trying to get round passwords though.

Hope this helps

Vanessa

Vanessa