Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
See more: C#2.0 ASP.NET
Hi
 
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");
}
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 7-Jan-13 23:20pm
Edited 7-Jan-13 23:24pm
_Amy51.3K
v2
Rate this: bad
good
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.
  Permalink  
Comments
sony_cute6 at 8-Jan-13 4:45am
   
In that case, can you please suggest me how to resolve it and move further?
OriginalGriff at 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 at 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
good
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[^]]
 

--Amit
  Permalink  
Comments
sony_cute6 at 8-Jan-13 4:39am
   
i have not created any application pool for this. Should i create an application pool for this
_Amy at 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 at 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
0 OriginalGriff 539
1 Maciej Los 300
2 DamithSL 233
3 Sergey Alexandrovich Kryukov 209
4 BillWoodruff 200
0 OriginalGriff 7,168
1 Sergey Alexandrovich Kryukov 6,377
2 DamithSL 5,461
3 Manas Bhardwaj 4,876
4 Maciej Los 4,450


Advertise | Privacy | Mobile
Web01 | 2.8.1411023.1 | Last Updated 8 Jan 2013
Copyright © CodeProject, 1999-2014
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