Click here to Skip to main content
15,888,610 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi
On an ASP.NET page I try to access a network shared directory using the
following code:

C#
String txtDir = TextBox1.Text.ToString();
if (Directory.Exists(txtDir))
{
   Response.Write("The Directory exists");
}
else
{
   Response.Write("The Directory doesn't exists");
}



This works fine when I ran through the code.

But after hosting it in the IIS, Directory.Exists always returns false though the directory has the required permissions.

I tried to place a File upload control and it allows me to browse the path for which the 'Directory.Exists' returns false.

Does anyone know why this method returns true for a network path?


Thanks
Posted
Updated 7-Jan-13 22:24pm
v2

Because C# code runs on the server, not the client. The upload control looks on the client, and finds the folder perfectly happily. Your code looks at the file system of the Server, where the folder does not exist.
 
Share this answer
 
Comments
sony_cute6 8-Jan-13 4:45am    
In that case, can you please suggest me how to resolve it and move further?
OriginalGriff 8-Jan-13 4:55am    
You can't access the folder on the client from the server (except in special circumstances which do not apply in 99% of situations).
Security will not even allow you to find out if the client has a a folder or even any concept of folders. It could be a phone, tablet, PC or internet enabled fridge!

What are you trying to do that you think you need this?
sony_cute6 8-Jan-13 5:36am    
I will place my files in a shared path and will specify the path through the application. Automatically my application will distribute the files to other users where the files are picked automatically from the share folder. Its a kind of work distributor.
When you run the code in Visual Studio it runs under the the rights of your user.

When you run the code in IIS it runs in the identity of the Application Pool which by default is the built in user "Network Service" this is a local user account which does not have access outside the local machine. The rights on the network share are the first layer, after that the NTFS rights on the directory are checked. You need to change the identity of the application pool to a domain user with the same rights as your user.
[Actual answer Reference[^]]


--Amit
 
Share this answer
 
Comments
sony_cute6 8-Jan-13 4:39am    
i have not created any application pool for this. Should i create an application pool for this
_Amy 8-Jan-13 4:46am    
Yes, you should try using that. Because the application will be running on client machine and depends on the authorization of the user.
sony_cute6 8-Jan-13 5:45am    
CAn you please suggest me how to change the identity of the application pool to a domain user with the same rights as your user in WIN Xp.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900