473,785 Members | 2,482 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Problem creating a Bitmap from an IO.FileStream

I am having a problem saving an image with the same name it originally had. I have two similar versions of my code, one in which I close the FileStream used to open the original image before saving, the other in which I close the FileStream afterwards, although both return the same error. Here are the two versions of the code and the errors they each return (NOTE: I rebooted immediately before running each of these versions so that I knew they were run under exactly the same conditions, I think the FileStream gets left open because the error occurs before I can close it):
Here is the one where I save it first:

Dim frogbitmap As Bitmap
Dim frogstream As New IO.FileStream(S erver.MapPath(" images/frog2.gif"), IO.FileMode.Ope n)
frogbitmap = New Bitmap(frogstre am)
frogbitmap.Save (Server.MapPath ("images/frog2.gif"), Imaging.ImageFo rmat.Gif)
frogstream.Clos e()
Invalid parameter used.
Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.

Exception Details: System.Argument Exception: Invalid parameter used.

Source Error:

Line 33: Dim frogbitmap As Bitmap
Line 34: Dim frogstream As New IO.FileStream(S erver.MapPath(" images/frog2.gif"), IO.FileMode.Ope n)
Line 35: frogbitmap = New Bitmap(frogstre am)
Line 36: frogbitmap.Save (Server.MapPath ("images/frog2.gif"), Imaging.ImageFo rmat.Gif)
Line 37: frogstream.Clos e()

Source File: C:\Inetpub\wwwr oot\WebApplicat ion1\ImageNoCac he.aspx.vb Line: 35

Stack Trace:

[ArgumentExcepti on: Invalid parameter used.]
System.Drawing. Bitmap..ctor(St ream stream) +271
WebApplication1 .ImageNoCache.b tnRotate_Click( Object sender, EventArgs e) in C:\Inetpub\wwwr oot\WebApplicat ion1\ImageNoCac he.aspx.vb:35
System.Web.UI.W ebControls.Butt on.OnClick(Even tArgs e) +108
System.Web.UI.W ebControls.Butt on.System.Web.U I.IPostBackEven tHandler.RaiseP ostBackEvent(St ring eventArgument) +57
System.Web.UI.P age.RaisePostBa ckEvent(IPostBa ckEventHandler sourceControl, String eventArgument) +18
System.Web.UI.P age.RaisePostBa ckEvent(NameVal ueCollection postData) +33
System.Web.UI.P age.ProcessRequ estMain() +1273


Here is the one where I close the FileStream first:

Dim frogbitmap As Bitmap
Dim frogstream As New IO.FileStream(S erver.MapPath(" images/frog2.gif"), IO.FileMode.Ope n)
frogbitmap = New Bitmap(frogstre am)
frogstream.Clos e()
frogbitmap.Save (Server.MapPath ("images/frog2.gif"), Imaging.ImageFo rmat.Gif)
Invalid parameter used.
Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.

Exception Details: System.Argument Exception: Invalid parameter used.

Source Error:

Line 33: Dim frogbitmap As Bitmap
Line 34: Dim frogstream As New IO.FileStream(S erver.MapPath(" images/frog2.gif"), IO.FileMode.Ope n)
Line 35: frogbitmap = New Bitmap(frogstre am)
Line 36: frogstream.Clos e()
Line 37: frogbitmap.Save (Server.MapPath ("images/frog2.gif"), Imaging.ImageFo rmat.Gif)

Source File: C:\Inetpub\wwwr oot\WebApplicat ion1\ImageNoCac he.aspx.vb Line: 35

Stack Trace:

[ArgumentExcepti on: Invalid parameter used.]
System.Drawing. Bitmap..ctor(St ream stream) +271
WebApplication1 .ImageNoCache.b tnRotate_Click( Object sender, EventArgs e) in C:\Inetpub\wwwr oot\WebApplicat ion1\ImageNoCac he.aspx.vb:35
System.Web.UI.W ebControls.Butt on.OnClick(Even tArgs e) +108
System.Web.UI.W ebControls.Butt on.System.Web.U I.IPostBackEven tHandler.RaiseP ostBackEvent(St ring eventArgument) +57
System.Web.UI.P age.RaisePostBa ckEvent(IPostBa ckEventHandler sourceControl, String eventArgument) +18
System.Web.UI.P age.RaisePostBa ckEvent(NameVal ueCollection postData) +33
System.Web.UI.P age.ProcessRequ estMain() +1273

I know that Server.MapPath( "images/frog2.gif") returns the correct path. I appreciate any help you can offer, thank you all in advance.
--
Nathan Sokalski
nj********@hotm ail.com
http://www.nathansokalski.com/
Dec 10 '05 #1
7 3009
Are you sure the stream is valid (contains data,valid picture)?

--
Miha Markic [MVP C#]
RightHand .NET consulting & development www.rthand.com
Blog: http://cs.rthand.com/blogs/blog_with_righthand/

"Nathan Sokalski" <nj********@hot mail.com> wrote in message news:en******** *****@TK2MSFTNG P15.phx.gbl...
I am having a problem saving an image with the same name it originally had. I have two similar versions of my code, one in which I close the FileStream used to open the original image before saving, the other in which I close the FileStream afterwards, although both return the same error. Here are the two versions of the code and the errors they each return (NOTE: I rebooted immediately before running each of these versions so that I knew they were run under exactly the same conditions, I think the FileStream gets left open because the error occurs before I can close it):
Here is the one where I save it first:

Dim frogbitmap As Bitmap
Dim frogstream As New IO.FileStream(S erver.MapPath(" images/frog2.gif"), IO.FileMode.Ope n)
frogbitmap = New Bitmap(frogstre am)
frogbitmap.Save (Server.MapPath ("images/frog2.gif"), Imaging.ImageFo rmat.Gif)
frogstream.Clos e()
Invalid parameter used.
Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.

Exception Details: System.Argument Exception: Invalid parameter used.

Source Error:

Line 33: Dim frogbitmap As Bitmap
Line 34: Dim frogstream As New IO.FileStream(S erver.MapPath(" images/frog2.gif"), IO.FileMode.Ope n)
Line 35: frogbitmap = New Bitmap(frogstre am)
Line 36: frogbitmap.Save (Server.MapPath ("images/frog2.gif"), Imaging.ImageFo rmat.Gif)
Line 37: frogstream.Clos e()

Source File: C:\Inetpub\wwwr oot\WebApplicat ion1\ImageNoCac he.aspx.vb Line: 35

Stack Trace:

[ArgumentExcepti on: Invalid parameter used.]
System.Drawing. Bitmap..ctor(St ream stream) +271
WebApplication1 .ImageNoCache.b tnRotate_Click( Object sender, EventArgs e) in C:\Inetpub\wwwr oot\WebApplicat ion1\ImageNoCac he.aspx.vb:35
System.Web.UI.W ebControls.Butt on.OnClick(Even tArgs e) +108
System.Web.UI.W ebControls.Butt on.System.Web.U I.IPostBackEven tHandler.RaiseP ostBackEvent(St ring eventArgument) +57
System.Web.UI.P age.RaisePostBa ckEvent(IPostBa ckEventHandler sourceControl, String eventArgument) +18
System.Web.UI.P age.RaisePostBa ckEvent(NameVal ueCollection postData) +33
System.Web.UI.P age.ProcessRequ estMain() +1273


Here is the one where I close the FileStream first:

Dim frogbitmap As Bitmap
Dim frogstream As New IO.FileStream(S erver.MapPath(" images/frog2.gif"), IO.FileMode.Ope n)
frogbitmap = New Bitmap(frogstre am)
frogstream.Clos e()
frogbitmap.Save (Server.MapPath ("images/frog2.gif"), Imaging.ImageFo rmat.Gif)
Invalid parameter used.
Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.

Exception Details: System.Argument Exception: Invalid parameter used.

Source Error:

Line 33: Dim frogbitmap As Bitmap
Line 34: Dim frogstream As New IO.FileStream(S erver.MapPath(" images/frog2.gif"), IO.FileMode.Ope n)
Line 35: frogbitmap = New Bitmap(frogstre am)
Line 36: frogstream.Clos e()
Line 37: frogbitmap.Save (Server.MapPath ("images/frog2.gif"), Imaging.ImageFo rmat.Gif)

Source File: C:\Inetpub\wwwr oot\WebApplicat ion1\ImageNoCac he.aspx.vb Line: 35

Stack Trace:

[ArgumentExcepti on: Invalid parameter used.]
System.Drawing. Bitmap..ctor(St ream stream) +271
WebApplication1 .ImageNoCache.b tnRotate_Click( Object sender, EventArgs e) in C:\Inetpub\wwwr oot\WebApplicat ion1\ImageNoCac he.aspx.vb:35
System.Web.UI.W ebControls.Butt on.OnClick(Even tArgs e) +108
System.Web.UI.W ebControls.Butt on.System.Web.U I.IPostBackEven tHandler.RaiseP ostBackEvent(St ring eventArgument) +57
System.Web.UI.P age.RaisePostBa ckEvent(IPostBa ckEventHandler sourceControl, String eventArgument) +18
System.Web.UI.P age.RaisePostBa ckEvent(NameVal ueCollection postData) +33
System.Web.UI.P age.ProcessRequ estMain() +1273

I know that Server.MapPath( "images/frog2.gif") returns the correct path. I appreciate any help you can offer, thank you all in advance.
--
Nathan Sokalski
nj********@hotm ail.com
http://www.nathansokalski.com/
Dec 11 '05 #2
You're right, the image was invalid (I probably didn't realize that it became invalid because of one of my other errors). I fixed that, and now I get an error during the Save method. Here is the error:

A generic error occurred in GDI+.
Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.

Exception Details: System.Runtime. InteropServices .ExternalExcept ion: A generic error occurred in GDI+.

Source Error:

Line 34: Dim frogstream As New IO.FileStream(S erver.MapPath(" images/frog2.gif"), IO.FileMode.Ope n)
Line 35: frogbitmap = New Bitmap(frogstre am)
Line 36: frogbitmap.Save (Server.MapPath ("images/frog2.gif"), Imaging.ImageFo rmat.Gif)
Line 37: frogstream.Clos e()
Line 38:

Source File: C:\Inetpub\wwwr oot\WebApplicat ion1\ImageNoCac he.aspx.vb Line: 36

Stack Trace:

[ExternalExcepti on (0x80004005): A generic error occurred in GDI+.]
System.Drawing. Image.Save(Stri ng filename, ImageCodecInfo encoder, EncoderParamete rs encoderParams) +581
System.Drawing. Image.Save(Stri ng filename, ImageFormat format) +61
WebApplication1 .ImageNoCache.b tnRotate_Click( Object sender, EventArgs e) in C:\Inetpub\wwwr oot\WebApplicat ion1\ImageNoCac he.aspx.vb:36
System.Web.UI.W ebControls.Butt on.OnClick(Even tArgs e) +108
System.Web.UI.W ebControls.Butt on.System.Web.U I.IPostBackEven tHandler.RaiseP ostBackEvent(St ring eventArgument) +57
System.Web.UI.P age.RaisePostBa ckEvent(IPostBa ckEventHandler sourceControl, String eventArgument) +18
System.Web.UI.P age.RaisePostBa ckEvent(NameVal ueCollection postData) +33
System.Web.UI.P age.ProcessRequ estMain() +1273

The error is exactly the same regardless of whether the Save or Close methods are called first. Would using a FileStream when saving my image solve the problem? I think the error is somehow related to the fact that I am reading from and writing to the same file, because if I use the same code with two different files, it works perfect. Thanks.
--
Nathan Sokalski
nj********@hotm ail.com
http://www.nathansokalski.com/
"Miha Markic [MVP C#]" <miha at rthand com> wrote in message news:Oa******** ******@TK2MSFTN GP11.phx.gbl...
Are you sure the stream is valid (contains data,valid picture)?

--
Miha Markic [MVP C#]
RightHand .NET consulting & development www.rthand.com
Blog: http://cs.rthand.com/blogs/blog_with_righthand/

"Nathan Sokalski" <nj********@hot mail.com> wrote in message news:en******** *****@TK2MSFTNG P15.phx.gbl...
I am having a problem saving an image with the same name it originally had. I have two similar versions of my code, one in which I close the FileStream used to open the original image before saving, the other in which I close the FileStream afterwards, although both return the same error. Here are the two versions of the code and the errors they each return (NOTE: I rebooted immediately before running each of these versions so that I knew they were run under exactly the same conditions, I think the FileStream gets left open because the error occurs before I can close it):
Here is the one where I save it first:

Dim frogbitmap As Bitmap
Dim frogstream As New IO.FileStream(S erver.MapPath(" images/frog2.gif"), IO.FileMode.Ope n)
frogbitmap = New Bitmap(frogstre am)
frogbitmap.Save (Server.MapPath ("images/frog2.gif"), Imaging.ImageFo rmat.Gif)
frogstream.Clos e()
Invalid parameter used.
Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.

Exception Details: System.Argument Exception: Invalid parameter used.

Source Error:

Line 33: Dim frogbitmap As Bitmap
Line 34: Dim frogstream As New IO.FileStream(S erver.MapPath(" images/frog2.gif"), IO.FileMode.Ope n)
Line 35: frogbitmap = New Bitmap(frogstre am)
Line 36: frogbitmap.Save (Server.MapPath ("images/frog2.gif"), Imaging.ImageFo rmat.Gif)
Line 37: frogstream.Clos e()

Source File: C:\Inetpub\wwwr oot\WebApplicat ion1\ImageNoCac he.aspx.vb Line: 35

Stack Trace:

[ArgumentExcepti on: Invalid parameter used.]
System.Drawing. Bitmap..ctor(St ream stream) +271
WebApplication1 .ImageNoCache.b tnRotate_Click( Object sender, EventArgs e) in C:\Inetpub\wwwr oot\WebApplicat ion1\ImageNoCac he.aspx.vb:35
System.Web.UI.W ebControls.Butt on.OnClick(Even tArgs e) +108
System.Web.UI.W ebControls.Butt on.System.Web.U I.IPostBackEven tHandler.RaiseP ostBackEvent(St ring eventArgument) +57
System.Web.UI.P age.RaisePostBa ckEvent(IPostBa ckEventHandler sourceControl, String eventArgument) +18
System.Web.UI.P age.RaisePostBa ckEvent(NameVal ueCollection postData) +33
System.Web.UI.P age.ProcessRequ estMain() +1273


Here is the one where I close the FileStream first:

Dim frogbitmap As Bitmap
Dim frogstream As New IO.FileStream(S erver.MapPath(" images/frog2.gif"), IO.FileMode.Ope n)
frogbitmap = New Bitmap(frogstre am)
frogstream.Clos e()
frogbitmap.Save (Server.MapPath ("images/frog2.gif"), Imaging.ImageFo rmat.Gif)
Invalid parameter used.
Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.

Exception Details: System.Argument Exception: Invalid parameter used.

Source Error:

Line 33: Dim frogbitmap As Bitmap
Line 34: Dim frogstream As New IO.FileStream(S erver.MapPath(" images/frog2.gif"), IO.FileMode.Ope n)
Line 35: frogbitmap = New Bitmap(frogstre am)
Line 36: frogstream.Clos e()
Line 37: frogbitmap.Save (Server.MapPath ("images/frog2.gif"), Imaging.ImageFo rmat.Gif)

Source File: C:\Inetpub\wwwr oot\WebApplicat ion1\ImageNoCac he.aspx.vb Line: 35

Stack Trace:

[ArgumentExcepti on: Invalid parameter used.]
System.Drawing. Bitmap..ctor(St ream stream) +271
WebApplication1 .ImageNoCache.b tnRotate_Click( Object sender, EventArgs e) in C:\Inetpub\wwwr oot\WebApplicat ion1\ImageNoCac he.aspx.vb:35
System.Web.UI.W ebControls.Butt on.OnClick(Even tArgs e) +108
System.Web.UI.W ebControls.Butt on.System.Web.U I.IPostBackEven tHandler.RaiseP ostBackEvent(St ring eventArgument) +57
System.Web.UI.P age.RaisePostBa ckEvent(IPostBa ckEventHandler sourceControl, String eventArgument) +18
System.Web.UI.P age.RaisePostBa ckEvent(NameVal ueCollection postData) +33
System.Web.UI.P age.ProcessRequ estMain() +1273

I know that Server.MapPath( "images/frog2.gif") returns the correct path. I appreciate any help you can offer, thank you all in advance.
--
Nathan Sokalski
nj********@hotm ail.com
http://www.nathansokalski.com/
Dec 12 '05 #3
You should Close stream first, that's for sure. And make sure you have write privileges to that file.

--
Miha Markic [MVP C#]
RightHand .NET consulting & development www.rthand.com
Blog: http://cs.rthand.com/blogs/blog_with_righthand/

"Nathan Sokalski" <nj********@hot mail.com> wrote in message news:uX******** *****@tk2msftng p13.phx.gbl...
You're right, the image was invalid (I probably didn't realize that it became invalid because of one of my other errors). I fixed that, and now I get an error during the Save method. Here is the error:

A generic error occurred in GDI+.
Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.

Exception Details: System.Runtime. InteropServices .ExternalExcept ion: A generic error occurred in GDI+.

Source Error:

Line 34: Dim frogstream As New IO.FileStream(S erver.MapPath(" images/frog2.gif"), IO.FileMode.Ope n)
Line 35: frogbitmap = New Bitmap(frogstre am)
Line 36: frogbitmap.Save (Server.MapPath ("images/frog2.gif"), Imaging.ImageFo rmat.Gif)
Line 37: frogstream.Clos e()
Line 38:

Source File: C:\Inetpub\wwwr oot\WebApplicat ion1\ImageNoCac he.aspx.vb Line: 36

Stack Trace:

[ExternalExcepti on (0x80004005): A generic error occurred in GDI+.]
System.Drawing. Image.Save(Stri ng filename, ImageCodecInfo encoder, EncoderParamete rs encoderParams) +581
System.Drawing. Image.Save(Stri ng filename, ImageFormat format) +61
WebApplication1 .ImageNoCache.b tnRotate_Click( Object sender, EventArgs e) in C:\Inetpub\wwwr oot\WebApplicat ion1\ImageNoCac he.aspx.vb:36
System.Web.UI.W ebControls.Butt on.OnClick(Even tArgs e) +108
System.Web.UI.W ebControls.Butt on.System.Web.U I.IPostBackEven tHandler.RaiseP ostBackEvent(St ring eventArgument) +57
System.Web.UI.P age.RaisePostBa ckEvent(IPostBa ckEventHandler sourceControl, String eventArgument) +18
System.Web.UI.P age.RaisePostBa ckEvent(NameVal ueCollection postData) +33
System.Web.UI.P age.ProcessRequ estMain() +1273

The error is exactly the same regardless of whether the Save or Close methods are called first. Would using a FileStream when saving my image solve the problem? I think the error is somehow related to the fact that I am reading from and writing to the same file, because if I use the same code with two different files, it works perfect. Thanks.
--
Nathan Sokalski
nj********@hotm ail.com
http://www.nathansokalski.com/
"Miha Markic [MVP C#]" <miha at rthand com> wrote in message news:Oa******** ******@TK2MSFTN GP11.phx.gbl...
Are you sure the stream is valid (contains data,valid picture)?

--
Miha Markic [MVP C#]
RightHand .NET consulting & development www.rthand.com
Blog: http://cs.rthand.com/blogs/blog_with_righthand/

"Nathan Sokalski" <nj********@hot mail.com> wrote in message news:en******** *****@TK2MSFTNG P15.phx.gbl...
I am having a problem saving an image with the same name it originally had. I have two similar versions of my code, one in which I close the FileStream used to open the original image before saving, the other in which I close the FileStream afterwards, although both return the same error. Here are the two versions of the code and the errors they each return (NOTE: I rebooted immediately before running each of these versions so that I knew they were run under exactly the same conditions, I think the FileStream gets left open because the error occurs before I can close it):
Here is the one where I save it first:

Dim frogbitmap As Bitmap
Dim frogstream As New IO.FileStream(S erver.MapPath(" images/frog2.gif"), IO.FileMode.Ope n)
frogbitmap = New Bitmap(frogstre am)
frogbitmap.Save (Server.MapPath ("images/frog2.gif"), Imaging.ImageFo rmat.Gif)
frogstream.Clos e()
Invalid parameter used.
Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.

Exception Details: System.Argument Exception: Invalid parameter used.

Source Error:

Line 33: Dim frogbitmap As Bitmap
Line 34: Dim frogstream As New IO.FileStream(S erver.MapPath(" images/frog2.gif"), IO.FileMode.Ope n)
Line 35: frogbitmap = New Bitmap(frogstre am)
Line 36: frogbitmap.Save (Server.MapPath ("images/frog2.gif"), Imaging.ImageFo rmat.Gif)
Line 37: frogstream.Clos e()

Source File: C:\Inetpub\wwwr oot\WebApplicat ion1\ImageNoCac he.aspx.vb Line: 35

Stack Trace:

[ArgumentExcepti on: Invalid parameter used.]
System.Drawing. Bitmap..ctor(St ream stream) +271
WebApplication1 .ImageNoCache.b tnRotate_Click( Object sender, EventArgs e) in C:\Inetpub\wwwr oot\WebApplicat ion1\ImageNoCac he.aspx.vb:35
System.Web.UI.W ebControls.Butt on.OnClick(Even tArgs e) +108
System.Web.UI.W ebControls.Butt on.System.Web.U I.IPostBackEven tHandler.RaiseP ostBackEvent(St ring eventArgument) +57
System.Web.UI.P age.RaisePostBa ckEvent(IPostBa ckEventHandler sourceControl, String eventArgument) +18
System.Web.UI.P age.RaisePostBa ckEvent(NameVal ueCollection postData) +33
System.Web.UI.P age.ProcessRequ estMain() +1273


Here is the one where I close the FileStream first:

Dim frogbitmap As Bitmap
Dim frogstream As New IO.FileStream(S erver.MapPath(" images/frog2.gif"), IO.FileMode.Ope n)
frogbitmap = New Bitmap(frogstre am)
frogstream.Clos e()
frogbitmap.Save (Server.MapPath ("images/frog2.gif"), Imaging.ImageFo rmat.Gif)
Invalid parameter used.
Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.

Exception Details: System.Argument Exception: Invalid parameter used.

Source Error:

Line 33: Dim frogbitmap As Bitmap
Line 34: Dim frogstream As New IO.FileStream(S erver.MapPath(" images/frog2.gif"), IO.FileMode.Ope n)
Line 35: frogbitmap = New Bitmap(frogstre am)
Line 36: frogstream.Clos e()
Line 37: frogbitmap.Save (Server.MapPath ("images/frog2.gif"), Imaging.ImageFo rmat.Gif)

Source File: C:\Inetpub\wwwr oot\WebApplicat ion1\ImageNoCac he.aspx.vb Line: 35

Stack Trace:

[ArgumentExcepti on: Invalid parameter used.]
System.Drawing. Bitmap..ctor(St ream stream) +271
WebApplication1 .ImageNoCache.b tnRotate_Click( Object sender, EventArgs e) in C:\Inetpub\wwwr oot\WebApplicat ion1\ImageNoCac he.aspx.vb:35
System.Web.UI.W ebControls.Butt on.OnClick(Even tArgs e) +108
System.Web.UI.W ebControls.Butt on.System.Web.U I.IPostBackEven tHandler.RaiseP ostBackEvent(St ring eventArgument) +57
System.Web.UI.P age.RaisePostBa ckEvent(IPostBa ckEventHandler sourceControl, String eventArgument) +18
System.Web.UI.P age.RaisePostBa ckEvent(NameVal ueCollection postData) +33
System.Web.UI.P age.ProcessRequ estMain() +1273

I know that Server.MapPath( "images/frog2.gif") returns the correct path. I appreciate any help you can offer, thank you all in advance.
--
Nathan Sokalski
nj********@hotm ail.com
http://www.nathansokalski.com/
Dec 12 '05 #4
I'm sure that you have more experience with Streams than me, but here are some tests I did along with their results:
I checked for ASPNET Write privileges, and it does have them, both for the file and the images directory

To test that it was not a problem with Write privileges, I ran the code using images/frog.gif as the source for the FileStream. When I did this, it would only work when I did the Save BEFORE the Close.
Although I have a way to make the code work to "copy" an image, it does not seem to work when trying to "modify" an image (well, my code doesn't really modify it right now, but you get the point). I think that all the Streams involved in the opening and saving end up interfering with each other somehow when saving with the same name, but I'm not sure how, and I'm having trouble figuring it out because I don't have a lot of experience with Streams in VB.NET. At the moment, that is the only idea I have, so although I plan to keep trying, I would appreciate any help that can be given. Thanks.
--
Nathan Sokalski
nj********@hotm ail.com
http://www.nathansokalski.com/
"Miha Markic [MVP C#]" <miha at rthand com> wrote in message news:%2******** *******@TK2MSFT NGP12.phx.gbl.. .
You should Close stream first, that's for sure. And make sure you have write privileges to that file.

--
Miha Markic [MVP C#]
RightHand .NET consulting & development www.rthand.com
Blog: http://cs.rthand.com/blogs/blog_with_righthand/

"Nathan Sokalski" <nj********@hot mail.com> wrote in message news:uX******** *****@tk2msftng p13.phx.gbl...
You're right, the image was invalid (I probably didn't realize that it became invalid because of one of my other errors). I fixed that, and now I get an error during the Save method. Here is the error:

A generic error occurred in GDI+.
Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.

Exception Details: System.Runtime. InteropServices .ExternalExcept ion: A generic error occurred in GDI+.

Source Error:

Line 34: Dim frogstream As New IO.FileStream(S erver.MapPath(" images/frog2.gif"), IO.FileMode.Ope n)
Line 35: frogbitmap = New Bitmap(frogstre am)
Line 36: frogbitmap.Save (Server.MapPath ("images/frog2.gif"), Imaging.ImageFo rmat.Gif)
Line 37: frogstream.Clos e()
Line 38:

Source File: C:\Inetpub\wwwr oot\WebApplicat ion1\ImageNoCac he.aspx.vb Line: 36

Stack Trace:

[ExternalExcepti on (0x80004005): A generic error occurred in GDI+.]
System.Drawing. Image.Save(Stri ng filename, ImageCodecInfo encoder, EncoderParamete rs encoderParams) +581
System.Drawing. Image.Save(Stri ng filename, ImageFormat format) +61
WebApplication1 .ImageNoCache.b tnRotate_Click( Object sender, EventArgs e) in C:\Inetpub\wwwr oot\WebApplicat ion1\ImageNoCac he.aspx.vb:36
System.Web.UI.W ebControls.Butt on.OnClick(Even tArgs e) +108
System.Web.UI.W ebControls.Butt on.System.Web.U I.IPostBackEven tHandler.RaiseP ostBackEvent(St ring eventArgument) +57
System.Web.UI.P age.RaisePostBa ckEvent(IPostBa ckEventHandler sourceControl, String eventArgument) +18
System.Web.UI.P age.RaisePostBa ckEvent(NameVal ueCollection postData) +33
System.Web.UI.P age.ProcessRequ estMain() +1273

The error is exactly the same regardless of whether the Save or Close methods are called first. Would using a FileStream when saving my image solve the problem? I think the error is somehow related to the fact that I am reading from and writing to the same file, because if I use the same code with two different files, it works perfect. Thanks.
--
Nathan Sokalski
nj********@hotm ail.com
http://www.nathansokalski.com/
"Miha Markic [MVP C#]" <miha at rthand com> wrote in message news:Oa******** ******@TK2MSFTN GP11.phx.gbl...
Are you sure the stream is valid (contains data,valid picture)?

--
Miha Markic [MVP C#]
RightHand .NET consulting & development www.rthand.com
Blog: http://cs.rthand.com/blogs/blog_with_righthand/

"Nathan Sokalski" <nj********@hot mail.com> wrote in message news:en******** *****@TK2MSFTNG P15.phx.gbl...
I am having a problem saving an image with the same name it originally had. I have two similar versions of my code, one in which I close the FileStream used to open the original image before saving, the other in which I close the FileStream afterwards, although both return the same error. Here are the two versions of the code and the errors they each return (NOTE: I rebooted immediately before running each of these versions so that I knew they were run under exactly the same conditions, I think the FileStream gets left open because the error occurs before I can close it):
Here is the one where I save it first:

Dim frogbitmap As Bitmap
Dim frogstream As New IO.FileStream(S erver.MapPath(" images/frog2.gif"), IO.FileMode.Ope n)
frogbitmap = New Bitmap(frogstre am)
frogbitmap.Save (Server.MapPath ("images/frog2.gif"), Imaging.ImageFo rmat.Gif)
frogstream.Clos e()
Invalid parameter used.
Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.

Exception Details: System.Argument Exception: Invalid parameter used.

Source Error:

Line 33: Dim frogbitmap As Bitmap
Line 34: Dim frogstream As New IO.FileStream(S erver.MapPath(" images/frog2.gif"), IO.FileMode.Ope n)
Line 35: frogbitmap = New Bitmap(frogstre am)
Line 36: frogbitmap.Save (Server.MapPath ("images/frog2.gif"), Imaging.ImageFo rmat.Gif)
Line 37: frogstream.Clos e()

Source File: C:\Inetpub\wwwr oot\WebApplicat ion1\ImageNoCac he.aspx.vb Line: 35

Stack Trace:

[ArgumentExcepti on: Invalid parameter used.]
System.Drawing. Bitmap..ctor(St ream stream) +271
WebApplication1 .ImageNoCache.b tnRotate_Click( Object sender, EventArgs e) in C:\Inetpub\wwwr oot\WebApplicat ion1\ImageNoCac he.aspx.vb:35
System.Web.UI.W ebControls.Butt on.OnClick(Even tArgs e) +108
System.Web.UI.W ebControls.Butt on.System.Web.U I.IPostBackEven tHandler.RaiseP ostBackEvent(St ring eventArgument) +57
System.Web.UI.P age.RaisePostBa ckEvent(IPostBa ckEventHandler sourceControl, String eventArgument) +18
System.Web.UI.P age.RaisePostBa ckEvent(NameVal ueCollection postData) +33
System.Web.UI.P age.ProcessRequ estMain() +1273


Here is the one where I close the FileStream first:

Dim frogbitmap As Bitmap
Dim frogstream As New IO.FileStream(S erver.MapPath(" images/frog2.gif"), IO.FileMode.Ope n)
frogbitmap = New Bitmap(frogstre am)
frogstream.Clos e()
frogbitmap.Save (Server.MapPath ("images/frog2.gif"), Imaging.ImageFo rmat.Gif)
Invalid parameter used.
Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.

Exception Details: System.Argument Exception: Invalid parameter used.

Source Error:

Line 33: Dim frogbitmap As Bitmap
Line 34: Dim frogstream As New IO.FileStream(S erver.MapPath(" images/frog2.gif"), IO.FileMode.Ope n)
Line 35: frogbitmap = New Bitmap(frogstre am)
Line 36: frogstream.Clos e()
Line 37: frogbitmap.Save (Server.MapPath ("images/frog2.gif"), Imaging.ImageFo rmat.Gif)

Source File: C:\Inetpub\wwwr oot\WebApplicat ion1\ImageNoCac he.aspx.vb Line: 35

Stack Trace:

[ArgumentExcepti on: Invalid parameter used.]
System.Drawing. Bitmap..ctor(St ream stream) +271
WebApplication1 .ImageNoCache.b tnRotate_Click( Object sender, EventArgs e) in C:\Inetpub\wwwr oot\WebApplicat ion1\ImageNoCac he.aspx.vb:35
System.Web.UI.W ebControls.Butt on.OnClick(Even tArgs e) +108
System.Web.UI.W ebControls.Butt on.System.Web.U I.IPostBackEven tHandler.RaiseP ostBackEvent(St ring eventArgument) +57
System.Web.UI.P age.RaisePostBa ckEvent(IPostBa ckEventHandler sourceControl, String eventArgument) +18
System.Web.UI.P age.RaisePostBa ckEvent(NameVal ueCollection postData) +33
System.Web.UI.P age.ProcessRequ estMain() +1273

I know that Server.MapPath( "images/frog2.gif") returns the correct path. I appreciate any help you can offer, thank you all in advance.
--
Nathan Sokalski
nj********@hotm ail.com
http://www.nathansokalski.com/
Dec 12 '05 #5
Hi Nathan,

To rule out any asp.net issue I suggest you to try it in a winforms or console application.

--
Miha Markic [MVP C#]
RightHand .NET consulting & development www.rthand.com
Blog: http://cs.rthand.com/blogs/blog_with_righthand/

"Nathan Sokalski" <nj********@hot mail.com> wrote in message news:%2******** ********@TK2MSF TNGP10.phx.gbl. ..
I'm sure that you have more experience with Streams than me, but here are some tests I did along with their results:
I checked for ASPNET Write privileges, and it does have them, both for the file and the images directory

To test that it was not a problem with Write privileges, I ran the code using images/frog.gif as the source for the FileStream. When I did this, it would only work when I did the Save BEFORE the Close.
Although I have a way to make the code work to "copy" an image, it does not seem to work when trying to "modify" an image (well, my code doesn't really modify it right now, but you get the point). I think that all the Streams involved in the opening and saving end up interfering with each other somehow when saving with the same name, but I'm not sure how, and I'm having trouble figuring it out because I don't have a lot of experience with Streams in VB.NET. At the moment, that is the only idea I have, so although I plan to keep trying, I would appreciate any help that can be given. Thanks.
--
Nathan Sokalski
nj********@hotm ail.com
http://www.nathansokalski.com/
"Miha Markic [MVP C#]" <miha at rthand com> wrote in message news:%2******** *******@TK2MSFT NGP12.phx.gbl.. .
You should Close stream first, that's for sure. And make sure you have write privileges to that file.

--
Miha Markic [MVP C#]
RightHand .NET consulting & development www.rthand.com
Blog: http://cs.rthand.com/blogs/blog_with_righthand/

"Nathan Sokalski" <nj********@hot mail.com> wrote in message news:uX******** *****@tk2msftng p13.phx.gbl...
You're right, the image was invalid (I probably didn't realize that it became invalid because of one of my other errors). I fixed that, and now I get an error during the Save method. Here is the error:

A generic error occurred in GDI+.
Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.

Exception Details: System.Runtime. InteropServices .ExternalExcept ion: A generic error occurred in GDI+.

Source Error:

Line 34: Dim frogstream As New IO.FileStream(S erver.MapPath(" images/frog2.gif"), IO.FileMode.Ope n)
Line 35: frogbitmap = New Bitmap(frogstre am)
Line 36: frogbitmap.Save (Server.MapPath ("images/frog2.gif"), Imaging.ImageFo rmat.Gif)
Line 37: frogstream.Clos e()
Line 38:

Source File: C:\Inetpub\wwwr oot\WebApplicat ion1\ImageNoCac he.aspx.vb Line: 36

Stack Trace:

[ExternalExcepti on (0x80004005): A generic error occurred in GDI+.]
System.Drawing. Image.Save(Stri ng filename, ImageCodecInfo encoder, EncoderParamete rs encoderParams) +581
System.Drawing. Image.Save(Stri ng filename, ImageFormat format) +61
WebApplication1 .ImageNoCache.b tnRotate_Click( Object sender, EventArgs e) in C:\Inetpub\wwwr oot\WebApplicat ion1\ImageNoCac he.aspx.vb:36
System.Web.UI.W ebControls.Butt on.OnClick(Even tArgs e) +108
System.Web.UI.W ebControls.Butt on.System.Web.U I.IPostBackEven tHandler.RaiseP ostBackEvent(St ring eventArgument) +57
System.Web.UI.P age.RaisePostBa ckEvent(IPostBa ckEventHandler sourceControl, String eventArgument) +18
System.Web.UI.P age.RaisePostBa ckEvent(NameVal ueCollection postData) +33
System.Web.UI.P age.ProcessRequ estMain() +1273

The error is exactly the same regardless of whether the Save or Close methods are called first. Would using a FileStream when saving my image solve the problem? I think the error is somehow related to the fact that I am reading from and writing to the same file, because if I use the same code with two different files, it works perfect. Thanks.
--
Nathan Sokalski
nj********@hotm ail.com
http://www.nathansokalski.com/
"Miha Markic [MVP C#]" <miha at rthand com> wrote in message news:Oa******** ******@TK2MSFTN GP11.phx.gbl...
Are you sure the stream is valid (contains data,valid picture)?

--
Miha Markic [MVP C#]
RightHand .NET consulting & development www.rthand.com
Blog: http://cs.rthand.com/blogs/blog_with_righthand/

"Nathan Sokalski" <nj********@hot mail.com> wrote in message news:en******** *****@TK2MSFTNG P15.phx.gbl...
I am having a problem saving an image with the same name it originally had. I have two similar versions of my code, one in which I close the FileStream used to open the original image before saving, the other in which I close the FileStream afterwards, although both return the same error. Here are the two versions of the code and the errors they each return (NOTE: I rebooted immediately before running each of these versions so that I knew they were run under exactly the same conditions, I think the FileStream gets left open because the error occurs before I can close it):
Here is the one where I save it first:

Dim frogbitmap As Bitmap
Dim frogstream As New IO.FileStream(S erver.MapPath(" images/frog2.gif"), IO.FileMode.Ope n)
frogbitmap = New Bitmap(frogstre am)
frogbitmap.Save (Server.MapPath ("images/frog2.gif"), Imaging.ImageFo rmat.Gif)
frogstream.Clos e()
Invalid parameter used.
Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.

Exception Details: System.Argument Exception: Invalid parameter used.

Source Error:

Line 33: Dim frogbitmap As Bitmap
Line 34: Dim frogstream As New IO.FileStream(S erver.MapPath(" images/frog2.gif"), IO.FileMode.Ope n)
Line 35: frogbitmap = New Bitmap(frogstre am)
Line 36: frogbitmap.Save (Server.MapPath ("images/frog2.gif"), Imaging.ImageFo rmat.Gif)
Line 37: frogstream.Clos e()

Source File: C:\Inetpub\wwwr oot\WebApplicat ion1\ImageNoCac he.aspx.vb Line: 35

Stack Trace:

[ArgumentExcepti on: Invalid parameter used.]
System.Drawing. Bitmap..ctor(St ream stream) +271
WebApplication1 .ImageNoCache.b tnRotate_Click( Object sender, EventArgs e) in C:\Inetpub\wwwr oot\WebApplicat ion1\ImageNoCac he.aspx.vb:35
System.Web.UI.W ebControls.Butt on.OnClick(Even tArgs e) +108
System.Web.UI.W ebControls.Butt on.System.Web.U I.IPostBackEven tHandler.RaiseP ostBackEvent(St ring eventArgument) +57
System.Web.UI.P age.RaisePostBa ckEvent(IPostBa ckEventHandler sourceControl, String eventArgument) +18
System.Web.UI.P age.RaisePostBa ckEvent(NameVal ueCollection postData) +33
System.Web.UI.P age.ProcessRequ estMain() +1273


Here is the one where I close the FileStream first:

Dim frogbitmap As Bitmap
Dim frogstream As New IO.FileStream(S erver.MapPath(" images/frog2.gif"), IO.FileMode.Ope n)
frogbitmap = New Bitmap(frogstre am)
frogstream.Clos e()
frogbitmap.Save (Server.MapPath ("images/frog2.gif"), Imaging.ImageFo rmat.Gif)
Invalid parameter used.
Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.

Exception Details: System.Argument Exception: Invalid parameter used.

Source Error:

Line 33: Dim frogbitmap As Bitmap
Line 34: Dim frogstream As New IO.FileStream(S erver.MapPath(" images/frog2.gif"), IO.FileMode.Ope n)
Line 35: frogbitmap = New Bitmap(frogstre am)
Line 36: frogstream.Clos e()
Line 37: frogbitmap.Save (Server.MapPath ("images/frog2.gif"), Imaging.ImageFo rmat.Gif)

Source File: C:\Inetpub\wwwr oot\WebApplicat ion1\ImageNoCac he.aspx.vb Line: 35

Stack Trace:

[ArgumentExcepti on: Invalid parameter used.]
System.Drawing. Bitmap..ctor(St ream stream) +271
WebApplication1 .ImageNoCache.b tnRotate_Click( Object sender, EventArgs e) in C:\Inetpub\wwwr oot\WebApplicat ion1\ImageNoCac he.aspx.vb:35
System.Web.UI.W ebControls.Butt on.OnClick(Even tArgs e) +108
System.Web.UI.W ebControls.Butt on.System.Web.U I.IPostBackEven tHandler.RaiseP ostBackEvent(St ring eventArgument) +57
System.Web.UI.P age.RaisePostBa ckEvent(IPostBa ckEventHandler sourceControl, String eventArgument) +18
System.Web.UI.P age.RaisePostBa ckEvent(NameVal ueCollection postData) +33
System.Web.UI.P age.ProcessRequ estMain() +1273

I know that Server.MapPath( "images/frog2.gif") returns the correct path. I appreciate any help you can offer, thank you all in advance.
--
Nathan Sokalski
nj********@hotm ail.com
http://www.nathansokalski.com/
Dec 12 '05 #6
I not familiar with creating console applications. As for winforms, just to make sure, is that basically a Windows application written using ..NET? I have written Windows applications using VB (that was before .NET even existed), so I want to make sure that I am understanding what you are suggesting.
--
Nathan Sokalski
nj********@hotm ail.com
http://www.nathansokalski.com/
"Miha Markic [MVP C#]" <miha at rthand com> wrote in message news:uN******** *****@TK2MSFTNG P09.phx.gbl...
Hi Nathan,

To rule out any asp.net issue I suggest you to try it in a winforms or console application.

--
Miha Markic [MVP C#]
RightHand .NET consulting & development www.rthand.com
Blog: http://cs.rthand.com/blogs/blog_with_righthand/

"Nathan Sokalski" <nj********@hot mail.com> wrote in message news:%2******** ********@TK2MSF TNGP10.phx.gbl. ..
I'm sure that you have more experience with Streams than me, but here are some tests I did along with their results:
I checked for ASPNET Write privileges, and it does have them, both for the file and the images directory

To test that it was not a problem with Write privileges, I ran the code using images/frog.gif as the source for the FileStream. When I did this, it would only work when I did the Save BEFORE the Close.
Although I have a way to make the code work to "copy" an image, it does not seem to work when trying to "modify" an image (well, my code doesn't really modify it right now, but you get the point). I think that all the Streams involved in the opening and saving end up interfering with each other somehow when saving with the same name, but I'm not sure how, and I'm having trouble figuring it out because I don't have a lot of experience with Streams in VB.NET. At the moment, that is the only idea I have, so although I plan to keep trying, I would appreciate any help that can be given. Thanks.
--
Nathan Sokalski
nj********@hotm ail.com
http://www.nathansokalski.com/
"Miha Markic [MVP C#]" <miha at rthand com> wrote in message news:%2******** *******@TK2MSFT NGP12.phx.gbl.. .
You should Close stream first, that's for sure. And make sure you have write privileges to that file.

--
Miha Markic [MVP C#]
RightHand .NET consulting & development www.rthand.com
Blog: http://cs.rthand.com/blogs/blog_with_righthand/

"Nathan Sokalski" <nj********@hot mail.com> wrote in message news:uX******** *****@tk2msftng p13.phx.gbl...
You're right, the image was invalid (I probably didn't realize that it became invalid because of one of my other errors). I fixed that, and now I get an error during the Save method. Here is the error:

A generic error occurred in GDI+.
Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.

Exception Details: System.Runtime. InteropServices .ExternalExcept ion: A generic error occurred in GDI+.

Source Error:

Line 34: Dim frogstream As New IO.FileStream(S erver.MapPath(" images/frog2.gif"), IO.FileMode.Ope n)
Line 35: frogbitmap = New Bitmap(frogstre am)
Line 36: frogbitmap.Save (Server.MapPath ("images/frog2.gif"), Imaging.ImageFo rmat.Gif)
Line 37: frogstream.Clos e()
Line 38:

Source File: C:\Inetpub\wwwr oot\WebApplicat ion1\ImageNoCac he.aspx.vb Line: 36

Stack Trace:

[ExternalExcepti on (0x80004005): A generic error occurred in GDI+.]
System.Drawing. Image.Save(Stri ng filename, ImageCodecInfo encoder, EncoderParamete rs encoderParams) +581
System.Drawing. Image.Save(Stri ng filename, ImageFormat format) +61
WebApplication1 .ImageNoCache.b tnRotate_Click( Object sender, EventArgs e) in C:\Inetpub\wwwr oot\WebApplicat ion1\ImageNoCac he.aspx.vb:36
System.Web.UI.W ebControls.Butt on.OnClick(Even tArgs e) +108
System.Web.UI.W ebControls.Butt on.System.Web.U I.IPostBackEven tHandler.RaiseP ostBackEvent(St ring eventArgument) +57
System.Web.UI.P age.RaisePostBa ckEvent(IPostBa ckEventHandler sourceControl, String eventArgument) +18
System.Web.UI.P age.RaisePostBa ckEvent(NameVal ueCollection postData) +33
System.Web.UI.P age.ProcessRequ estMain() +1273

The error is exactly the same regardless of whether the Save or Close methods are called first. Would using a FileStream when saving my image solve the problem? I think the error is somehow related to the fact that I am reading from and writing to the same file, because if I use the same code with two different files, it works perfect. Thanks.
--
Nathan Sokalski
nj********@hotm ail.com
http://www.nathansokalski.com/
"Miha Markic [MVP C#]" <miha at rthand com> wrote in message news:Oa******** ******@TK2MSFTN GP11.phx.gbl...
Are you sure the stream is valid (contains data,valid picture)?

--
Miha Markic [MVP C#]
RightHand .NET consulting & development www.rthand.com
Blog: http://cs.rthand.com/blogs/blog_with_righthand/

"Nathan Sokalski" <nj********@hot mail.com> wrote in message news:en******** *****@TK2MSFTNG P15.phx.gbl...
I am having a problem saving an image with the same name it originally had. I have two similar versions of my code, one in which I close the FileStream used to open the original image before saving, the other in which I close the FileStream afterwards, although both return the same error. Here are the two versions of the code and the errors they each return (NOTE: I rebooted immediately before running each of these versions so that I knew they were run under exactly the same conditions, I think the FileStream gets left open because the error occurs before I can close it):
Here is the one where I save it first:

Dim frogbitmap As Bitmap
Dim frogstream As New IO.FileStream(S erver.MapPath(" images/frog2.gif"), IO.FileMode.Ope n)
frogbitmap = New Bitmap(frogstre am)
frogbitmap.Save (Server.MapPath ("images/frog2.gif"), Imaging.ImageFo rmat.Gif)
frogstream.Clos e()
Invalid parameter used.
Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.

Exception Details: System.Argument Exception: Invalid parameter used.

Source Error:

Line 33: Dim frogbitmap As Bitmap
Line 34: Dim frogstream As New IO.FileStream(S erver.MapPath(" images/frog2.gif"), IO.FileMode.Ope n)
Line 35: frogbitmap = New Bitmap(frogstre am)
Line 36: frogbitmap.Save (Server.MapPath ("images/frog2.gif"), Imaging.ImageFo rmat.Gif)
Line 37: frogstream.Clos e()

Source File: C:\Inetpub\wwwr oot\WebApplicat ion1\ImageNoCac he.aspx.vb Line: 35

Stack Trace:

[ArgumentExcepti on: Invalid parameter used.]
System.Drawing. Bitmap..ctor(St ream stream) +271
WebApplication1 .ImageNoCache.b tnRotate_Click( Object sender, EventArgs e) in C:\Inetpub\wwwr oot\WebApplicat ion1\ImageNoCac he.aspx.vb:35
System.Web.UI.W ebControls.Butt on.OnClick(Even tArgs e) +108
System.Web.UI.W ebControls.Butt on.System.Web.U I.IPostBackEven tHandler.RaiseP ostBackEvent(St ring eventArgument) +57
System.Web.UI.P age.RaisePostBa ckEvent(IPostBa ckEventHandler sourceControl, String eventArgument) +18
System.Web.UI.P age.RaisePostBa ckEvent(NameVal ueCollection postData) +33
System.Web.UI.P age.ProcessRequ estMain() +1273


Here is the one where I close the FileStream first:

Dim frogbitmap As Bitmap
Dim frogstream As New IO.FileStream(S erver.MapPath(" images/frog2.gif"), IO.FileMode.Ope n)
frogbitmap = New Bitmap(frogstre am)
frogstream.Clos e()
frogbitmap.Save (Server.MapPath ("images/frog2.gif"), Imaging.ImageFo rmat.Gif)
Invalid parameter used.
Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.

Exception Details: System.Argument Exception: Invalid parameter used.

Source Error:

Line 33: Dim frogbitmap As Bitmap
Line 34: Dim frogstream As New IO.FileStream(S erver.MapPath(" images/frog2.gif"), IO.FileMode.Ope n)
Line 35: frogbitmap = New Bitmap(frogstre am)
Line 36: frogstream.Clos e()
Line 37: frogbitmap.Save (Server.MapPath ("images/frog2.gif"), Imaging.ImageFo rmat.Gif)

Source File: C:\Inetpub\wwwr oot\WebApplicat ion1\ImageNoCac he.aspx.vb Line: 35

Stack Trace:

[ArgumentExcepti on: Invalid parameter used.]
System.Drawing. Bitmap..ctor(St ream stream) +271
WebApplication1 .ImageNoCache.b tnRotate_Click( Object sender, EventArgs e) in C:\Inetpub\wwwr oot\WebApplicat ion1\ImageNoCac he.aspx.vb:35
System.Web.UI.W ebControls.Butt on.OnClick(Even tArgs e) +108
System.Web.UI.W ebControls.Butt on.System.Web.U I.IPostBackEven tHandler.RaiseP ostBackEvent(St ring eventArgument) +57
System.Web.UI.P age.RaisePostBa ckEvent(IPostBa ckEventHandler sourceControl, String eventArgument) +18
System.Web.UI.P age.RaisePostBa ckEvent(NameVal ueCollection postData) +33
System.Web.UI.P age.ProcessRequ estMain() +1273

I know that Server.MapPath( "images/frog2.gif") returns the correct path. I appreciate any help you can offer, thank you all in advance.
--
Nathan Sokalski
nj********@hotm ail.com
http://www.nathansokalski.com/
Dec 12 '05 #7

"Nathan Sokalski" <nj********@hot mail.com> wrote in message news:ug******** ******@TK2MSFTN GP10.phx.gbl...
I not familiar with creating console applications. As for winforms, just to make sure, is that basically a Windows application written using ..NET?

Yes.

I have written Windows applications using VB (that was before .NET even existed), so I want to make sure that I am understanding what you are suggesting.
--
Nathan Sokalski
nj********@hotm ail.com
http://www.nathansokalski.com/
"Miha Markic [MVP C#]" <miha at rthand com> wrote in message news:uN******** *****@TK2MSFTNG P09.phx.gbl...
Hi Nathan,

To rule out any asp.net issue I suggest you to try it in a winforms or console application.

--
Miha Markic [MVP C#]
RightHand .NET consulting & development www.rthand.com
Blog: http://cs.rthand.com/blogs/blog_with_righthand/

"Nathan Sokalski" <nj********@hot mail.com> wrote in message news:%2******** ********@TK2MSF TNGP10.phx.gbl. ..
I'm sure that you have more experience with Streams than me, but here are some tests I did along with their results:
I checked for ASPNET Write privileges, and it does have them, both for the file and the images directory

To test that it was not a problem with Write privileges, I ran the code using images/frog.gif as the source for the FileStream. When I did this, it would only work when I did the Save BEFORE the Close.
Although I have a way to make the code work to "copy" an image, it does not seem to work when trying to "modify" an image (well, my code doesn't really modify it right now, but you get the point). I think that all the Streams involved in the opening and saving end up interfering with each other somehow when saving with the same name, but I'm not sure how, and I'm having trouble figuring it out because I don't have a lot of experience with Streams in VB.NET. At the moment, that is the only idea I have, so although I plan to keep trying, I would appreciate any help that can be given. Thanks.
--
Nathan Sokalski
nj********@hotm ail.com
http://www.nathansokalski.com/
"Miha Markic [MVP C#]" <miha at rthand com> wrote in message news:%2******** *******@TK2MSFT NGP12.phx.gbl.. .
You should Close stream first, that's for sure. And make sure you have write privileges to that file.

--
Miha Markic [MVP C#]
RightHand .NET consulting & development www.rthand.com
Blog: http://cs.rthand.com/blogs/blog_with_righthand/

"Nathan Sokalski" <nj********@hot mail.com> wrote in message news:uX******** *****@tk2msftng p13.phx.gbl...
You're right, the image was invalid (I probably didn't realize that it became invalid because of one of my other errors). I fixed that, and now I get an error during the Save method. Here is the error:

A generic error occurred in GDI+.
Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.

Exception Details: System.Runtime. InteropServices .ExternalExcept ion: A generic error occurred in GDI+.

Source Error:

Line 34: Dim frogstream As New IO.FileStream(S erver.MapPath(" images/frog2.gif"), IO.FileMode.Ope n)
Line 35: frogbitmap = New Bitmap(frogstre am)
Line 36: frogbitmap.Save (Server.MapPath ("images/frog2.gif"), Imaging.ImageFo rmat.Gif)
Line 37: frogstream.Clos e()
Line 38:

Source File: C:\Inetpub\wwwr oot\WebApplicat ion1\ImageNoCac he.aspx.vb Line: 36

Stack Trace:

[ExternalExcepti on (0x80004005): A generic error occurred in GDI+.]
System.Drawing. Image.Save(Stri ng filename, ImageCodecInfo encoder, EncoderParamete rs encoderParams) +581
System.Drawing. Image.Save(Stri ng filename, ImageFormat format) +61
WebApplication1 .ImageNoCache.b tnRotate_Click( Object sender, EventArgs e) in C:\Inetpub\wwwr oot\WebApplicat ion1\ImageNoCac he.aspx.vb:36
System.Web.UI.W ebControls.Butt on.OnClick(Even tArgs e) +108
System.Web.UI.W ebControls.Butt on.System.Web.U I.IPostBackEven tHandler.RaiseP ostBackEvent(St ring eventArgument) +57
System.Web.UI.P age.RaisePostBa ckEvent(IPostBa ckEventHandler sourceControl, String eventArgument) +18
System.Web.UI.P age.RaisePostBa ckEvent(NameVal ueCollection postData) +33
System.Web.UI.P age.ProcessRequ estMain() +1273

The error is exactly the same regardless of whether the Save or Close methods are called first. Would using a FileStream when saving my image solve the problem? I think the error is somehow related to the fact that I am reading from and writing to the same file, because if I use the same code with two different files, it works perfect. Thanks.
--
Nathan Sokalski
nj********@hotm ail.com
http://www.nathansokalski.com/
"Miha Markic [MVP C#]" <miha at rthand com> wrote in message news:Oa******** ******@TK2MSFTN GP11.phx.gbl...
Are you sure the stream is valid (contains data,valid picture)?

--
Miha Markic [MVP C#]
RightHand .NET consulting & development www.rthand.com
Blog: http://cs.rthand.com/blogs/blog_with_righthand/

"Nathan Sokalski" <nj********@hot mail.com> wrote in message news:en******** *****@TK2MSFTNG P15.phx.gbl...
I am having a problem saving an image with the same name it originally had. I have two similar versions of my code, one in which I close the FileStream used to open the original image before saving, the other in which I close the FileStream afterwards, although both return the same error. Here are the two versions of the code and the errors they each return (NOTE: I rebooted immediately before running each of these versions so that I knew they were run under exactly the same conditions, I think the FileStream gets left open because the error occurs before I can close it):
Here is the one where I save it first:

Dim frogbitmap As Bitmap
Dim frogstream As New IO.FileStream(S erver.MapPath(" images/frog2.gif"), IO.FileMode.Ope n)
frogbitmap = New Bitmap(frogstre am)
frogbitmap.Save (Server.MapPath ("images/frog2.gif"), Imaging.ImageFo rmat.Gif)
frogstream.Clos e()
Invalid parameter used.
Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.

Exception Details: System.Argument Exception: Invalid parameter used.

Source Error:

Line 33: Dim frogbitmap As Bitmap
Line 34: Dim frogstream As New IO.FileStream(S erver.MapPath(" images/frog2.gif"), IO.FileMode.Ope n)
Line 35: frogbitmap = New Bitmap(frogstre am)
Line 36: frogbitmap.Save (Server.MapPath ("images/frog2.gif"), Imaging.ImageFo rmat.Gif)
Line 37: frogstream.Clos e()

Source File: C:\Inetpub\wwwr oot\WebApplicat ion1\ImageNoCac he.aspx.vb Line: 35

Stack Trace:

[ArgumentExcepti on: Invalid parameter used.]
System.Drawing. Bitmap..ctor(St ream stream) +271
WebApplication1 .ImageNoCache.b tnRotate_Click( Object sender, EventArgs e) in C:\Inetpub\wwwr oot\WebApplicat ion1\ImageNoCac he.aspx.vb:35
System.Web.UI.W ebControls.Butt on.OnClick(Even tArgs e) +108
System.Web.UI.W ebControls.Butt on.System.Web.U I.IPostBackEven tHandler.RaiseP ostBackEvent(St ring eventArgument) +57
System.Web.UI.P age.RaisePostBa ckEvent(IPostBa ckEventHandler sourceControl, String eventArgument) +18
System.Web.UI.P age.RaisePostBa ckEvent(NameVal ueCollection postData) +33
System.Web.UI.P age.ProcessRequ estMain() +1273


Here is the one where I close the FileStream first:

Dim frogbitmap As Bitmap
Dim frogstream As New IO.FileStream(S erver.MapPath(" images/frog2.gif"), IO.FileMode.Ope n)
frogbitmap = New Bitmap(frogstre am)
frogstream.Clos e()
frogbitmap.Save (Server.MapPath ("images/frog2.gif"), Imaging.ImageFo rmat.Gif)
Invalid parameter used.
Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.

Exception Details: System.Argument Exception: Invalid parameter used.

Source Error:

Line 33: Dim frogbitmap As Bitmap
Line 34: Dim frogstream As New IO.FileStream(S erver.MapPath(" images/frog2.gif"), IO.FileMode.Ope n)
Line 35: frogbitmap = New Bitmap(frogstre am)
Line 36: frogstream.Clos e()
Line 37: frogbitmap.Save (Server.MapPath ("images/frog2.gif"), Imaging.ImageFo rmat.Gif)

Source File: C:\Inetpub\wwwr oot\WebApplicat ion1\ImageNoCac he.aspx.vb Line: 35

Stack Trace:

[ArgumentExcepti on: Invalid parameter used.]
System.Drawing. Bitmap..ctor(St ream stream) +271
WebApplication1 .ImageNoCache.b tnRotate_Click( Object sender, EventArgs e) in C:\Inetpub\wwwr oot\WebApplicat ion1\ImageNoCac he.aspx.vb:35
System.Web.UI.W ebControls.Butt on.OnClick(Even tArgs e) +108
System.Web.UI.W ebControls.Butt on.System.Web.U I.IPostBackEven tHandler.RaiseP ostBackEvent(St ring eventArgument) +57
System.Web.UI.P age.RaisePostBa ckEvent(IPostBa ckEventHandler sourceControl, String eventArgument) +18
System.Web.UI.P age.RaisePostBa ckEvent(NameVal ueCollection postData) +33
System.Web.UI.P age.ProcessRequ estMain() +1273

I know that Server.MapPath( "images/frog2.gif") returns the correct path. I appreciate any help you can offer, thank you all in advance.
--
Nathan Sokalski
nj********@hotm ail.com
http://www.nathansokalski.com/
Dec 13 '05 #8

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
1689
by: Chung Ta | last post by:
Hi all, I am having problem creating web application using Visual Studio .Net. I encountered the following error: Unable to create Web project 'WebApp1'. Unable to validate that the file path 'C:\Inetpub\wwwroot\WebApp1' matches the URL path 'http://localhost/WebApp1'. A connection with the server could not be established.
1
4942
by: David Hoffer | last post by:
I am creating a custom user control and I am having problems with setting the transparent color of the bitmap. Here is my code... protected override void OnPaint( PaintEventArgs e ) { System.Drawing.Imaging.ImageAttributes imageAttributes = new System.Drawing.Imaging.ImageAttributes();
1
2616
by: James Dean | last post by:
In my program i create a 32ARGB bitmap. To actually create the bitmap seems very slow. In fairness the file size is very big. I support multiple bitmaps as well. I have to convert these bitmaps to thumbnails also which again seems very slow. There is a memory bitmap but i can't seem to find any good information about it. I want to be able to create a 32bpp bitmap as fast as possible and also try to make a thumbnail as fast as possible too....
2
1517
by: umilmi81 | last post by:
I am having a problem creating an ASP.NET application in Visual Studio.NET 2003, installed on Windows XP Professional I get a message stating that I do not have ASP.NET 1.1 installed, so I can not create web applications I downloaded the update that is supposed to install ASP.NET 1.1, but I'm still getting the message My research leads me to understand that VS.NET 2003 wont allow users to create web applications on anything "less" than...
0
1182
by: Raphaël Désalbres | last post by:
Hello, everybody, I'm having a problem creating a control...All I want to do is a simple poll system, so I need to input (trough a ListitemCollection) the values from the user. The problem is I'm getting an error each time I try to modify the elements, I don't know why.... If anyone can help, I would appreciate...
5
1247
by: Brian Cryer | last post by:
I'm developing a website and for one of the pages I need to create a number of coloured rectangles - its part of a legend and the user has control over the actual colours used which is why I want to create it dynamically. I've put together an aspx.vb page which creates a rectangle as a jpeg in the colour passed via the url. My idea being to pull in each coloured rectangle using something like: <img...
7
2321
by: Nathan Sokalski | last post by:
I am having a problem saving an image with the same name it originally had. I have two similar versions of my code, one in which I close the FileStream used to open the original image before saving, the other in which I close the FileStream afterwards, although both return the same error. Here are the two versions of the code and the errors they each return (NOTE: I rebooted immediately before running each of these versions so that I knew they...
0
1253
by: AlVis1515 | last post by:
We had a VB6 program that was used to take a scanned signature image as a set of screen coordinates. The VB6 program then converted this into a bitmap file which we used to embed the signature in certain documents such as invoices. The code was recently ported to VB.NET. We are using the BitMap and DataPoint objects to convert the data to a bitmap file, then saving it using a .NET PictureBox. The problem is that apparently the bitmap...
1
2454
by: de4ever | last post by:
HI, i have created a windows service using wmi and c# for mantaining a log of all print jobs in the printing queue.It creates log of only those print jobs which are there when the service started.But i want it to create log of a newly added print job to the print queue when the service is running..can any one help please..my simple code is below.. ManagementObjectSearcher searcher =new ManagementObjectSearcher("SELECT * FROM...
2
3000
by: FFrozTT | last post by:
I am having a problem creating a DLL with an entry point. I've been trying sub Main, DllMain, and I get nothing. When I run dumpbin - exports mydll.dll I see no entry points, also the dll when executed by rundll32 is not giving expected results. I have the project set to Class Library with Sub Main as the startup object, which I can't change to anything else anyway without modifying the .vbproj file which also seems to have no effect. ...
0
9480
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10324
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10147
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
9949
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
8971
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
6739
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5380
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5511
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
3645
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.