Click here to Skip to main content
13,045,387 members (79,456 online)
Rate this:
Please Sign up or sign in to vote.
See more:

On an ASP.NET page I try to access a network shared directory using the
following code:

String txtDir = TextBox1.Text.ToString();
if (Directory.Exists(txtDir))
   Response.Write("The Directory exists");
   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?

Posted 7-Jan-13 22:20pm
Updated 7-Jan-13 22:24pm
Rate this: bad
Please Sign up or sign in to vote.

Solution 1

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.
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.
Rate this: bad
Please Sign up or sign in to vote.

Solution 2

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[^]]

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)

  Print Answers RSS
Top Experts
Last 24hrsThis month

Advertise | Privacy | Mobile
Web01 | 2.8.170713.1 | Last Updated 8 Jan 2013
Copyright © CodeProject, 1999-2017
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100