Coruscate5
Coruscate5

Reputation: 2533

Calling a WebDAV "Network" Share results in "Network Path was not Found"

I have a C# application that calls a WebDAV file as though it were a network fileshare.

Ex:

var file = File.ReadAllText(@"\\server\WebDAVRoot\file.txt");

However, sometimes (seemingly sporadically) this returns "network path was not found". When I remote to the server & check the share, magically the code starts working.

What's wrong here?

Upvotes: 0

Views: 1377

Answers (1)

Coruscate5
Coruscate5

Reputation: 2533

The problem here is that .NET cannot access WebDAV shares unless the WebDAV service has already been trigger-started by the user.

By default, this service is the "WebClient" service - some servers don't even have this installed by default either (you can fix this by adding the "Desktop Experience" feature from Server Manager).

Once WebDAV is installed on the server, WebClient by default is set to "Manual (Trigger Start)". The trigger to activate the service is an Explorer call to a WebDAV share - thus, the .NET code will not trigger the service to start.

You can solve this a few ways - I solved it by setting the WebClient service to "Automatic" but you can also check service status/start the service from inside the C# code by using the ServiceController class.

Upvotes: 2

Related Questions