Click here to Skip to main content
15,886,689 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Using the piece of code below, got denied to a network drive even though the network folders/files are accessible through my Windows Explorer.
using (System.IO.StreamReader sr = new System.IO.StreamReader(System.IO.File.OpenRead(@"\\netDrive\floder\SRID.txt")))  {
     s = sr.ReadToEnd();
     Console.WriteLine(s);
}

How can this problem be solved? Thanks.
Posted
Comments
Bernhard Hiller 29-Aug-14 2:47am    
Same user in your application and in Windows Explorer?
Or was the access denied because an application already opened the file exclusively?
s yu 2-Sep-14 8:09am    
Found to be network issue. If the .txt sits in the save server as the program, there is no such a problem. Or else, need userID + password. Thanks.

1 solution

You can ask the user for a username and password, or directly pass those to a function like WNetAddConnection3 (see link[^] for more details).
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900