locked
Can I place a file on c drive of server where my websit is hosted? RRS feed

  • Question

  • User912480169 posted

    Hi,

    By security resion, can I place file on c drive of server where my website is hosted? If yes then how I set and get path of the location to use on pages? we can get file on root of websit as;

    licFileName = HttpContext.Current.Server.MapPath("~/LicenseFile/") + licFileName;

    can set path to local drive C of server and also get? and how?

    Atiq

    Thursday, May 24, 2012 4:22 AM

Answers

  • User-760709272 posted

    It's not a permission issue, just one of how websites work.  If you have a website at

    c:\inetpub\wwwroot\myweb

    The "http://yourserver.com/" is the root of your site and is the "myweb" folder.  While you can go deeper;

    "/test/file.txt" is "c:\inetpub\wwwroot\myweb\test\file.txt", you can't go further up.  The "myweb" folder is the highest folder in the heirarchy that your website can access.

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Thursday, May 24, 2012 7:46 AM

All replies

  • User-760709272 posted

    If the location is not within a folder than is exposed as a website via IIS then you can't give a url to clients to use the file.  Your server code can create the file and read the file, but clients can't access it via a url as only files within the website can be accessed via url.

    You'd have to create a page on your site that reads the file and sends it to the client via BinaryWrite, and the user would access the page and give the filename on the url.  So if the file was at "c:\myfile.txt" the url would be

    yourserver.com/download.aspx?file=myfile.txt

    The code on "download.aspx" would then read "c:\myfile.txt" and write it to the client.  If you do a search there are loads of examples on how to serve a file to the client via binarywrite.

    http://www.google.co.uk/search?q=asp.net%20binarywrite

    Thursday, May 24, 2012 6:08 AM
  • User-661350001 posted

    yes we save a file in any drive but that folder should have granted permissions for aspnet /network service user 

    Thursday, May 24, 2012 6:39 AM
  • User-760709272 posted

    It's not a permission issue, just one of how websites work.  If you have a website at

    c:\inetpub\wwwroot\myweb

    The "http://yourserver.com/" is the root of your site and is the "myweb" folder.  While you can go deeper;

    "/test/file.txt" is "c:\inetpub\wwwroot\myweb\test\file.txt", you can't go further up.  The "myweb" folder is the highest folder in the heirarchy that your website can access.

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Thursday, May 24, 2012 7:46 AM
  • User912480169 posted

    Thanks, great reply by both of you. I am creating locally a folder "LicenseFile" and in it file "license.Lic". Is it will work online by the same process or not? AidyF may ask not possible Smile and Mudasir may ask folder should have granted permissions for aspnet /network service user Smile

    Atiq

    Thursday, May 24, 2012 8:20 AM
  • User912480169 posted

    and the code that I am using;

    string licFileName = ddlCompanyName.SelectedItem.Text + "_Licence.Lic";
                   
    System.IO.Directory.CreateDirectory("C:\\LicenseFile");
    string FilePath = "C:\\LicenseFile\\" + licFileName;

    and then create file using file handling technique.

    Thursday, May 24, 2012 8:26 AM