Search code examples
c#windowsubuntushared-file

How to read shared file from Ubuntu/Samba using C#?


I have shared folder on ubuntu/samba server of my network.

I am running my c# code on Vista , so How can i read file shared on ubuntu/samba server ?

My code :

String errorLogFile = @"\\\\198.168.0.2\\sharedfolder\myfile.wmv";

//throws excetion login fail
StreamReader sr = new StreamReader(errorLogFile);

sr.Read();

streamWriter.Close();

Solution

  • Use the code provided in this answer to authenticate your code for the remote directory.

    Update:
    Additionally, the combination of escaped backslashes and verbatim strings is a bad idea. Use one of these but not both.
    Also, you are missing the backslash after the name of the shared folder.
    It should be like this:

    String errorLogFile = @"\\198.168.0.2\sharedfolder\" + finaldate + ".wmv";