Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / Windows Forms / WinForm General / October 2004

Tip: Looking for answers? Try searching our database.

WebClient Saving Exception

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Magnus - 13 Oct 2004 08:16 GMT
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
Jared - 13 Oct 2004 10:57 GMT
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.

> Hi
>
[quoted text clipped - 26 lines]
>
> Thanks
Morten Wennevik - 13 Oct 2004 12:28 GMT
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");

Signature

Happy Coding!
Morten Wennevik [C# MVP]

- 13 Oct 2004 17:37 GMT
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

>-----Original Message-----
>Hi Magnus,
[quoted text clipped - 7 lines]
>
>webC.DownloadFile(myImgPath.AbsoluteUri.ToString(), @"C:\Images\test.gif");

Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.