Welcome to WebmasterWorld Guest from

Forum Moderators: ocean10000

Message Too Old, No Replies

System.Drawing.Image.FromFile and network paths

trying to use a file located at \\SERVER\DRIVE\

8:29 pm on Jul 20, 2009 (gmt 0)

New User

10+ Year Member

joined:Dec 11, 2008
votes: 0

I am trying to send a file name that sits on a network path to this function:

imageURL = "\\SNAKE\Cobra\InetPub\Sites\" & websiteFolder & "\graphics\" & imageURL
dim originalImage As System.Drawing.Image = System.Drawing.Image.FromFile( imageURL )

Where SNAKE is the server name on the same domain and Cobra is the name of the drive (using the drive letter instead doesn't work).

Is this possible? The MSDN pages don't have any good examples, as usual. I tried passing it through Server.MapPath with no luck.

3:08 am on July 21, 2009 (gmt 0)


WebmasterWorld Administrator 10+ Year Member Top Contributors Of The Month

joined:Jan 14, 2004
votes: 3

I am going to assume the file is being accessed in an Asp.Net web application, and that the file resides in the web application child folders. I am going to paste in some sample C# code to help debug common issues. I am adding trace events that can be read using trace.axd in asp.net.

string path = System.Web.HttpContext.Current.Request.MapPath("/graphics/");
if (System.IO.Directory.Exists(path) == false)
//Folder path doesn't exist
System.Web.HttpContext.Current.Trace.Warn("Folder path doesn't exist");

path = System.Web.HttpContext.Current.Request.MapPath("/graphics/ + imageURL);
if (System.IO.File.Exists(path) == false)
//File does not exist
System.Web.HttpContext.Current.Trace.Warn("File does not exist");

System.Drawing.Image originalImage = System.Drawing.Image.FromFile( path );

Just a word of warning some methods of System.Drawing.Image uses unmanaged GDI+ handles, and on a busy site can easily exceed the pool of these handles. Depending how often they are used and disposed of.
6:53 am on July 21, 2009 (gmt 0)

Senior Member

WebmasterWorld Senior Member 10+ Year Member

joined:Feb 1, 2005
votes: 0

Your code should work, I just tested the following in my work network, and it loaded the image fine.

Dim imageURL As String = "\\SERVERNAME\Share\Test\Untitled.jpg"
Dim originalImage As System.Drawing.Image = System.Drawing.Image.FromFile(imageURL)

- What does your imageURL string contain at the point of loading the Image. (the reason being you have called it 'imageURL', is it a url?)

- Does your website (the Network Service user) have the correct permissions for this folder?

And, as Ocean10000 says, I would do the processing within a Try...Finally block (disposing of the Image in 'Finally' to free up resources)