开发者

A generic error occurred in GDI+, PNG Image to UNC

Ussualy I don't write stuff to forums just read info that i need. This time I've got big problems and I need help from expert.

I would like to save image from PictureBox to file.

It works when I use

Image.Save("X:\\Files\\logo.png");

But I need to save Image to UNC location. So created UNC from X:\Files

When I try to save Image as

Image.Save("\\\\\PC\\Files\\logo.png");

I get stupid GDI+ error without any info..

I tried saving it using MemoryStream and nothing is resolved.. I am trying it for 4hours and no sucess..

If I map netvork drive \\PC\files to drive letter lets say L:\ and then save image as

Image.Save("L:\\logo.png"); // it works !

OK what is with you boy? Again..

Image.Save("X:\\Files\\logo.png");          // WORKS
Image.Save("\\\\PC\\Files\\logo.png");    // GDI+ ERROR
Image.Save("L:\\logo.png");  // DOES THE JOB (it is network drive from \\pc\files)

Ok now you will ask me what perrmisions I created on Shared folder. I added user Everyone and set permissions t开发者_StackOverflow中文版o write,read&execute.

Problem is that actually I would like to save Images to NAS drive so I am not sure what Sabma security permissions it has (everyone,guest, don't know) or in other words it is not as simple as clicking on Shared folder and play with permissions..

How can I resolve this buggy implementation? I tried Image.Clone(), MemoryStrean and all the stuff I found with Uncle Google but nothing does the job I think that problem isn't in unaccessable Image but it has something to do with permissions on UNC location but just don't know why it works if i create Network Drive with no special user login.. I just can't say to customer to create Network Drive it has to work with UNC path!


I'd say you just miscounted your backslashes - there should be 4, not 5. Try:

Image.Save("\\\\PC\\Files\\logo.png");


Thank you Mark for comment.. I didn't have 5 backslashes but I did something more stupid...

TextBox1.Text = "\\\\\\\\PC\\Files"; // through GUI I add "\\\\PC\Files"

and then

string path = TextBox1.Text;    
Image.Save(path + "\\" filename");

As you can se the string in path was "\\\\PC\Files"! Wrong! :=) It has to be \\ so solution is

TextBox1.Text="\\\\PC\\Files"; // or if I add this string by GUI "\\PC\Files"

And something that follows my stupid input into text box.

if (path.StartsWith("\\\\\\\\") || path.Contains(":"))
{
   // Problem was that in TextBox were really 4 backslashes so it jumps here
   image.Save(path,ImageFormat.Png); 
   // and because string started as "\\\\" it throws GDI+ error
}
else
{
   string path2= Directory.GetCurrentDirectory()+"\\"+path;
   image.Save(path2, System.Drawing.Imaging.ImageFormat.Png);
}

Yeah I am an Idiot :=)

i did fix and it is the way it should be :=) I am sorry that I am spamming stackoverflow.


I think it is not a code problem, it is due to installed components, I also experienced the same issue and is solved by self after uploading on a regular server.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜