I am doing a programmatically access of a SMB Network Shared Drive using C#
I saw this thread How to provide user name and password when connecting to a network share which let's you define UNC path and some credentials.
I've used similar logic on giving the credentials on accessing the share like Network Share Gist but they both give an error 67 which is "The network name cannot be found". Even though the network share is mapped as network drive, the error still persists.
I am now hitting the wall to make work as almost all of the thread I've seen is not working for me.
This is my code accessing the network share using the class that is advised on the thread above.
NetworkCredential credentials = new NetworkCredential("user", "pass");
using (new smbconn(@"\\192.168.1.89\Main-Storage\", credentials))
{
Files = Directory.GetFiles(@"\\192.168.1.89\Main-Storage\");
MessageBox.Show(string.Join(Environment.NewLine, Files));
}
If more additional information is needed, please don't hesitate to comment. Thanks
I stumbled upon a really newer thread and has the same type of error with this.
It comes down on how the passed variables like the network path and credentials is being passed to the parameters of WNetAddConnection2.
It completely fixes the problem.