Parameter invalid exception from System.Drawing.Image.FromStream () method

I find it difficult using the Image.FromStream method on my site. The code below works fine on my computer. But when I uploaded it to the test server, it always gives me the exception "The parameter is invalid."

if (!afuImageFile.IsUploading && afuImageFile.HasFile) { System.Drawing.Image imgFile = System.Drawing.Image.FromStream(afuImageFile.FileContent); } 

afuImageFile is an afuImageFile control in Ajax toolkits. afuImageFile.FileContent is an HttpInputStream . I guess I need to add some permissions to some folder. Can anybody help me?

+6
c # system.drawing
source share
1 answer

Please make sure your stream is FileContent since its position is set to 0.

Otherwise, you can turn off image verification by changing the call:

 System.Drawing.Image imgFile = System.Drawing.Image.FromStream(afuImageFile.FileContent); 

in

 System.Drawing.Image imgFile = System.Drawing.Image.FromStream(afuImageFile.FileContent, true, false); 

See Image.FromStream to check for other overloads.

+2
source share

All Articles