Search code examples
c#asp.netbitmapunc

How do I create a bitmap object using a UNC path?


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#.


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.