Null Pointer
Null Pointer

Reputation: 9299

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 installed 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 ?

Upvotes: 1

Views: 1926

Answers (3)

acoolaum
acoolaum

Reputation: 2130

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.

Upvotes: 0

BlueCode
BlueCode

Reputation: 741

Try System.IO.Directory.Exists(string path) instead.

Upvotes: 1

Darin Dimitrov
Darin Dimitrov

Reputation: 1039200

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.

Upvotes: 2

Related Questions