0

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

Alexei Levenkov
  • 98,904
  • 14
  • 127
  • 179
  • What's the error? Do you need to explicitly enter your credentials to access that path? Can you post more of the path (to make sure you don't have something like C:\). – evanmcdonnal Nov 19 '12 at 23:31

2 Answers2

1

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.

Alexei Levenkov
  • 98,904
  • 14
  • 127
  • 179
1

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.

evanmcdonnal
  • 46,131
  • 16
  • 104
  • 115