Hyperlink to PDF files in a folder that is protect

Discussion in 'ASP.NET / ASP.NET Core' started by georgeASP, Oct 5, 2004.

Thread Status:
Threads that have been inactive for 5 years or longer are closed to further replies. Please start a new thread.
  1. 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
     
  2. 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
     
  3. 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
     
Thread Status:
Threads that have been inactive for 5 years or longer are closed to further replies. Please start a new thread.

Share This Page