Reputation: 9225
I have a ASP.net website and in the code behind I am creating a folder on page load, if it doesn't exist in the local drive:
string strDirectory = @"C:\PDFGenerate\";
try
{
if (!Directory.Exists(strDirectory))
{
Directory.CreateDirectory(strDirectory);
}
}
catch (Exception ce)
{
tc.Text = "Unable to create directory to save generated PDF files";
}
The website is currently hosted in my local server. I added the website to my IIS so I can access it locally from any PC in our network.
The issue I am experiencing is whenever I access the website from my local PC, the folder is being created in the server and not in my PC.
Is this something to do with access? I tried to create a folder in my own local drive and it worked fine.
Upvotes: 1
Views: 967
Reputation: 1500675
The issue I am experiencing is whenever I access the website from my local PC, the folder is being created in the server and not in my PC.
Yes. That's because all your code is being executed on the server. The server just delivers HTML to your PC, and the web browser displays the HTML. Of course, if that includes some Javascript, that will run on the PC (in the browser) - but the C# runs on the server. (Think about it: how would you expect the C# code to run on a machine which didn't have any facility for running .NET?)
It's really really important to understand where your code is running. As a web app creator, you don't get to create folders on client machines. You've got some very limited access to local (i.e. client-side) storage, but you won't be able to perform arbitrary file system operations. That would be horribly insecure.
Upvotes: 8