I have a strange behaviour when I try to use a C# program to copy local files to a Sharepoint Server using UNC paths provided by Sharepoint to access the file system. First of all, my user has all the privileges required to access that specific Sharepoint-folder.
This is what my operation basically looks like:
string targetSharepointPath = @"\\team.mycompany.com@SSL\DavWWWRoot\team\wmscompanydep\Software Releases\MyToolConfig"
System.IO.File.Copy(sourcePath, targetSharepointPath, false);
This fails with an error "The network path was not found."
As soon as I copy the path above and paste it into WIndows File Explorer (not internet explorer, this is simply an UNC path), everything works.
So my assumption is, that in the background, Windows explorer does a little bit more. But what? I do not have to enter any credentials, the targetSharepointPath simply works in explorer, and as soon as this was entered once, it also works in my C# program. Until I restart my system, I have to repeat that step. Why, and how can I achieve that programatically? I work with UNC paths on "normal" Windows servers a lot, and once the user has rights I do not need any additional authentication.
To connect to a Sharepoint
you need a windows service called WebClient
.
When you open that link from the Explorer, it will make sure that the service is started. That might be the reason why you're able to access the Sharepoint
from your app after you opened the link in Explorer.
You can make sure that your clients have that service
started automatically to achieve it.
Or you can try starting the service from you code in this way. (You might need admin privileges for this)
using (ServiceController service= new ServiceController("WebClient"))
{
if (service.Status == ServiceControllerStatus.Stopped)
{
service.Start();
service.WaitForStatus(ServiceControllerStatus.Running, new TimeSpan(0, 0, 15));
//Check status here by calling service.Status and proceed with your code.
}
else
{
//proceed with your code as the service is up and running
}
}