Strange behaviour from System.IO.DirectoryInfo. Exists function
I am developing an application using c# and asp. It need to access some places in the local network . There is a text box in the form which accept the path to be accessed from the user and will store it to a string variable named location.
The if loop always return false if the application run in windows 7. and it occurs only when I run from the inst开发者_高级运维alled application, otherwise it will return true if the path is true. Here is the code:
The input to textbox BackupLocation is like this
\\192.168.0.33\Others (F)
. It work fine if the application is hosted on a system which have windows XP
System.IO.DirectoryInfo locationInfo = new System.IO.DirectoryInfo(BackupLocationTxt.Text);
if (locationInfo.Exists) // always return false if the application run in windows 7
{
}
Why this happens ?
This happens because the user you are running your application under doesn't have authorization to read those folders. You might need to grant read access to those folders to the account you are running your site under.
Try System.IO.Directory.Exists(string path)
instead.
Your ASP.NET application doesn't have permissions to the folder on other computer in local network.
Try use windows service started under LocalService account.
精彩评论