I want to read a file content with UNC path and credentials unsing streamreader in C#. I am surprised that there is no clear answer for this topic in the internet.
I have tried before the streamreader code, the following code but didn't work
{
ConnectionOptions options = new ConnectionOptions();
options.Username = "user";
options.Password = "Password";
try
{
using (StreamReader sr = new StreamReader(@"\\10.92.127.7\E$\AlarmReader\alarmlist.txt"))
{
alarmtext = sr.ReadToEnd();
}
}
catch (Exception ex)
{
using (StreamWriter sw = File.AppendText((error_path)))
{
sw.WriteLine(ex);
}
}
}