Getting to the root directory, programmatically

Discussion in 'ASP.NET / ASP.NET Core' started by Karen, Nov 3, 2005.

Thread Status:
Threads that have been inactive for 5 years or longer are closed to further replies. Please start a new thread.
  1. Hi guys. :eek:)

    One more problem that is causing me fits. I've found how to force downloads of files that would otherwise appear in the browser window. (If anyone wants to know, email me!) BUT...

    The files I'm forcing downloads on are in a different folder on my server. So, thefolder with the downloadaspx fileis in www.domain.com/folder1, but the files for download are in www.domain.com/folder2. I had the code successfully working when the files were parked within folder1, because of the nature of the path, but I don't know how to make it find another (another path?)...

    Right now, my code is:


     
  2. Bruce

    Bruce DiscountASP.NET Staff

    hmmm.. not sure i understand the question.

    can you provide more details??

    Bruce

    DiscountASP.NET
    www.DiscountASP.NET
     
  3. Thanks for responding, Bruce. I'll try to be more specific.


    I have files that exist in a subfolder on my website. Let's call the address where they reside: www.mysite.com/filefolder. I've created a user control panel in a separate subfolder, which is private. Let's call this subfolder: www.mysite.com/manager.


    I have a page within my manager subfolder that my user can access to download the files that are in the filefolder directory. So, my user will be on www.mysite.com/manager/download.aspx. Let's say they want to download the first file that has a link on that page. The address of that file is going to be www.mysite.com/filefolder/link1.fnm.


    To try and simplify: The code I have that forces a download dialog box requires that you put a path to where the file is located. But, it will only accept paths that exist within the directory I'm in. So, when my user is on www.mysite.com/manager/download.aspx, I can only successfully access the files within manager or the subfolders I might have inside the manager subdirectory. In other words:


    Server.MapPath("manager/somefile.aspx") OR
    Server.MapPath("manager/somefolder/somefile.aspx")


    What I NEED is:


    Server.MapPath("http://www.mysite.com/FILEFOLDER/....") I need the server to understand that the path where the file is located is not in the same subdirectory that the site page lies. And, when I try to add the http part, oreven starting at www, I get the error that the virtual path isn't valid...?


    So, I need to know how to tell the server to look for the file elsewhere, outside of the subdirectory the person iscurrently in.


    I hope this is clearer. Please let me know if you still need additional info...


    Thanks again, forall your help!!
     
  4. Bruce

    Bruce DiscountASP.NET Staff

    try this

    Server.MapPath('/filefoler/somefile.aspx')

    i think this will take you all the way to the site root.

    if it still doesn't work, you may want to use the full path.

    Bruce

    DiscountASP.NET
    www.DiscountASP.NET
     
  5. Hi Bruce!


    Sorry it's taken me so long to reply. As always, I deeply appreciate your help.


    I tried your suggestion, and with the change (that essentially involved adding a "/" character before my subfolder), I'm no longer getting any error, but it's not bringing up the forced download dialog box anymore either.... Any ideas?


    Thanks again...


    Steph
     
  6. Bruce

    Bruce DiscountASP.NET Staff

  7. Thanks for looking into this and trying to help, Bruce!


    So, I've still not had much luck doing this the way I originally wanted to, so I'm trying another (possibly better) way.


    Instead of trying to direct the download code to a folder in a different path, I'll put the folder within the same path (www.mysite.com/manager/filefolder/etc...)


    My new problem is that the manager folder is a private (password-protected) folder. So, when another page in my application writes the files that get stored in the "filefolder" subfolder, it will ask for the password before it actually creates the files. The average user of the page will not know my password, so I need my code to pass the password programatically. The end-user should not even know that a password was ever needed.


    The password is one I created...not a Windows password. So, can anyone help me with code (or other help) that passes the password behind-the-scenes? This would be happening immediately before a file is created (using the streamwriter object) and stored in the folder.


    Thanks in advance!


    Steph
     
  8. Bruce

    Bruce DiscountASP.NET Staff

    i think the only thing you can do is to impersonate. Since you are not really making a HTTP call to the file but rather using filestream to pump that file out to the browser, the web app is still running in the realm of the Anonymous user (or what ever users you logged in w/).

    Bruce

    DiscountASP.NET
    www.DiscountASP.NET
     
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