Note
Access to this page requires authorization. You can try signing in or changing directories.
Access to this page requires authorization. You can try changing directories.
Question
Wednesday, November 4, 2009 1:28 PM
Hi. Am trying to access a folder on a network in C# using MySql connection to save a picture in the folder on the network. Am using the IP address of the computer. Below is the code for that part but the error is: path format not supported. Please help me with the right path syntax
[code]
MemberPics.Image.Save(string.Format("\192.168.1.6\c:\Pictures\{0}.jpg", fileName), System.Drawing.Imaging.ImageFormat.Jpeg);
[/code]
All replies (1)
Wednesday, November 4, 2009 1:44 PM âś…Answered | 1 vote
You are looking for UNC (Universal Naming Convention) syntax.
To form a UNC path, you need \server\share\folder\file.ext
So what you're missing is the SHARE name for your C volume.
To access the C drive via the built-in administrative share, you could use the "c$" share name like this:
\192.168.1.6\c$\Pictures\foo.jpg
Otherwise you'll have to share the C drive and use whatever name you give it. If you do this, the name will likely default to "C"
\192.168.1.6\C\Pictures\foo.jpg
From Windows explorer, right click your C drive and click "Sharing and Security... " (on XP) and see what it's shared as. On Vista it's called "Share... ". On Windows 7 its "Share With > Advanced Sharing " I think.
Anyway, you need to know the name of the share. You can't use "C:" That's not how the UNC naming works.
Now to put this into a string, you need to be careful to either escape your backslashes or use the @ string literal syntax .
MemberPics.Image.Save(string.Format(@"\\192.168.1.6\C$\Pictures\{0}.jpg", fileName), System.Drawing.Imaging.ImageFormat.Jpeg);
// OR if you really like using escape characters
MemberPics.Image.Save(string.Format("\\\\192.168.1.6\\C$\\Pictures\\{0}.jpg", fileName), System.Drawing.Imaging.ImageFormat.Jpeg);
// OR if you enable a share called "C" for your C volume:
MemberPics.Image.Save(string.Format(@"\\192.168.1.6\C\Pictures\{0}.jpg", fileName), System.Drawing.Imaging.ImageFormat.Jpeg);