mishmash
mishmash

Reputation: 4458

Cannot find file Exception with FileStream, opens in Explorer

I have the following code:

FileStream file = new FileStream(@"\\srv\dscan$\001\unknown\2012-04\0011200001001700_001.pdf", System.IO.FileMode.Open);

It always throws a FileNotFoundException. The strange thing is that if I paste the exact same path above into Windows Explorer, the file can be found and opened perfectly OK.

What can be causing this? Is there a special way of handling file streams on shared network drives?

Upvotes: 0

Views: 1680

Answers (3)

Gerald Versluis
Gerald Versluis

Reputation: 34013

What Darin Dimitrov says.

The user account that you are logged in under in Windows seems to have the sufficient permissions or maybe you have entered a username and password before which you marked as 'remember'.

When running your code it probably does under minimal rights (UAC) or maybe you are creating a Windows Service, which runs under a different account all together.

Problem could also be related to the dollar sign, which indicates that you are trying to reach a hidden share. I don't know if that is a problem in itself, but could have impact on your (in)sufficient rights.

Upvotes: 1

Joey.Lu
Joey.Lu

Reputation: 124

C# treats a path differently from a windows explorer. And one more thing, if you check those posts: Reading File From Network Location

you will find that you need some more work on the configurations.

Upvotes: -1

Darin Dimitrov
Darin Dimitrov

Reputation: 1038770

What can be causing this?

The account under which is executing the process containing this code doesn't have sufficient permissions to read from this location.

Upvotes: 2

Related Questions