0

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);

            }
        }

    }
  • Try searching for "c# net use with credentials" The following may be helpful: https://stackoverflow.com/questions/295538/how-to-provide-user-name-and-password-when-connecting-to-a-network-share and https://www.c-sharpcorner.com/blogs/how-to-access-network-drive-using-c-sharp – user9938 Jul 03 '21 at 12:00

0 Answers0