Question

I am trying to do something like this

Bitmap img = new Bitmap("\\\\server\\folder\\picture.jpg");

which fails every time.

I know I have permission to read the file because I can manually access it.

In general, I would like to know how to work with UNC paths in C#.

Was it helpful?

Solution

That path is valid. Also, with string literals in C# you can declare them like this @".\MyPath\Doesn'tNeed\DoubleSlashes\Because\IUsed@\file.txt"

This tutorial will show you how to access a UNC path with credentials (which you probably need) http://www.codeproject.com/Articles/43091/Connect-to-a-UNC-Path-with-Credentials

Keep in mind that just because the user on Machine A has permissions to access files on Machine B doesn't mean they can do so without entering their credentials.

OTHER TIPS

Account that code runs under on your ASP.Net server does not seem to have permissions to read this file. Some possible reasons:

  • one-hop authentication (if you run code with impersonation)
  • anonymous account does not have permissions on "\server"

You need to figure out what account code runs under before taking next steps to grant access to it.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top