WebClient Saving Exception


M

Magnus

Hi

I'm converting a C# console program to a Windows form.

I use this code to grab a .gif and save it to a folder on
my C: drive

webC = new WebClient();

OutputBitmap = new Bitmap(webC.OpenRead
(myImgPath.AbsoluteUri.ToString()));
OutputBitmap.Save(@"C:\Images\test.gif");
OutputBitmap.Dispose();

There is no problem at all in the console version, but the
Windows Form throws this:

System.Runtime.InteropServices.ExternalException: A
generic error occurred in GDI+. at
System.Drawing.Image.Save(String filename, ImageCodecInfo
encoder, EncoderParameters encoderParams)
at System.Drawing.Image.Save(String filename, ImageFormat
format)
at System.Drawing.Image.Save(String filename)

I've set every permission available in my Images folder,
but no success. Has anyone come across this and have an
idea of the problem?

Thanks
 
Ad

Advertisements

J

Jared

I don't think the system.drawing namespace is referenced by default in a
console app. Try to add the reference yourself and see if it works.
 
M

Morten Wennevik

Hi Magnus,

I couldn't find any problems using your code in either Console or Windows
Form. However I tested it under Win98 which does not bother with
permissions.

A workaround might be to drop using Bitmap altogether when saving the file
using

webC.DownloadFile(myImgPath.AbsoluteUri.ToString(), @"C:\Images\test.gif");
 
Ad

Advertisements

G

Guest

Thanks both of you,

Jared, there were no reference problems, thanks.

Morten, your workround works! It means I'll have to then
go onto re-name the saved image, because I always need it
to be the same name.

It's definetly a permissions problem. Does anyone else
know why the Forms code is creating this Exception?

Thanks
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top