none
Network path in C#

    Question

  • 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]
    Wednesday, November 04, 2009 1:28 PM

Answers

  • 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);
    • Proposed as answer by Geert van Horrik Wednesday, November 04, 2009 1:56 PM
    • Marked as answer by SAINTJAB Monday, November 09, 2009 9:25 AM
    Wednesday, November 04, 2009 1:44 PM