Last post May 24, 2012 08:26 AM by Atiqiub
May 24, 2012 04:22 AM|Atiqiub|LINK
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?
May 24, 2012 06:08 AM|AidyF|LINK
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
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.
May 24, 2012 06:39 AM|Mudasir.Khan|LINK
yes we save a file in any drive but that folder should have granted permissions for aspnet /network service user
May 24, 2012 07:46 AM|AidyF|LINK
It's not a permission issue, just one of how websites work. If you have a website at
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.
May 24, 2012 08:20 AM|Atiqiub|LINK
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
and Mudasir may ask folder should have granted permissions for aspnet /network service user
May 24, 2012 08:26 AM|Atiqiub|LINK
and the code that I am using;
string licFileName = ddlCompanyName.SelectedItem.Text + "_Licence.Lic";
string FilePath = "C:\\LicenseFile\\" + licFileName;
and then create file using file handling technique.