I want to read files from a folder that exists on the network.
When I try to access this folder manually (from run command giving a path like \\ABCServer\Documents ) it ask me for credentials (username and password). After giving the correct credentials I am able to access/read files.
When I try to read the same files from C# code in ASP.NET it gives me an error:
Login Failure: unkown username or bad password
How can I pass credentials via C# code during reading file?
Below is a part of the code that I am using:
Stream s = File.OpenRead(filePath);
byte[] buffer = new byte[s.Length];
try
{
s.Read(buffer, 0, (Int32)s.Length);
}
finally
{
s.Close();
}
Note:
- The code works fine
- I'm using ASP.NET 4.0 with C#
- IIS version is 7.5