N
Nathan Sokalski
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(Server.MapPath("images/frog2.gif"), IO.FileMode.Open)
frogbitmap = New Bitmap(frogstream)
frogbitmap.Save(Server.MapPath("images/frog2.gif"), Imaging.ImageFormat.Gif)
frogstream.Close()
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.ArgumentException: Invalid parameter used.
Source Error:
Line 33: Dim frogbitmap As Bitmap
Line 34: Dim frogstream As New IO.FileStream(Server.MapPath("images/frog2.gif"), IO.FileMode.Open)
Line 35: frogbitmap = New Bitmap(frogstream)
Line 36: frogbitmap.Save(Server.MapPath("images/frog2.gif"), Imaging.ImageFormat.Gif)
Line 37: frogstream.Close()
Source File: C:\Inetpub\wwwroot\WebApplication1\ImageNoCache.aspx.vb Line: 35
Stack Trace:
[ArgumentException: Invalid parameter used.]
System.Drawing.Bitmap..ctor(Stream stream) +271
WebApplication1.ImageNoCache.btnRotate_Click(Object sender, EventArgs e) in C:\Inetpub\wwwroot\WebApplication1\ImageNoCache.aspx.vb:35
System.Web.UI.WebControls.Button.OnClick(EventArgs e) +108
System.Web.UI.WebControls.Button.System.Web.UI.IPostBackEventHandler.RaisePostBackEvent(String eventArgument) +57
System.Web.UI.Page.RaisePostBackEvent(IPostBackEventHandler sourceControl, String eventArgument) +18
System.Web.UI.Page.RaisePostBackEvent(NameValueCollection postData) +33
System.Web.UI.Page.ProcessRequestMain() +1273
Here is the one where I close the FileStream first:
Dim frogbitmap As Bitmap
Dim frogstream As New IO.FileStream(Server.MapPath("images/frog2.gif"), IO.FileMode.Open)
frogbitmap = New Bitmap(frogstream)
frogstream.Close()
frogbitmap.Save(Server.MapPath("images/frog2.gif"), Imaging.ImageFormat.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.ArgumentException: Invalid parameter used.
Source Error:
Line 33: Dim frogbitmap As Bitmap
Line 34: Dim frogstream As New IO.FileStream(Server.MapPath("images/frog2.gif"), IO.FileMode.Open)
Line 35: frogbitmap = New Bitmap(frogstream)
Line 36: frogstream.Close()
Line 37: frogbitmap.Save(Server.MapPath("images/frog2.gif"), Imaging.ImageFormat.Gif)
Source File: C:\Inetpub\wwwroot\WebApplication1\ImageNoCache.aspx.vb Line: 35
Stack Trace:
[ArgumentException: Invalid parameter used.]
System.Drawing.Bitmap..ctor(Stream stream) +271
WebApplication1.ImageNoCache.btnRotate_Click(Object sender, EventArgs e) in C:\Inetpub\wwwroot\WebApplication1\ImageNoCache.aspx.vb:35
System.Web.UI.WebControls.Button.OnClick(EventArgs e) +108
System.Web.UI.WebControls.Button.System.Web.UI.IPostBackEventHandler.RaisePostBackEvent(String eventArgument) +57
System.Web.UI.Page.RaisePostBackEvent(IPostBackEventHandler sourceControl, String eventArgument) +18
System.Web.UI.Page.RaisePostBackEvent(NameValueCollection postData) +33
System.Web.UI.Page.ProcessRequestMain() +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.
Here is the one where I save it first:
Dim frogbitmap As Bitmap
Dim frogstream As New IO.FileStream(Server.MapPath("images/frog2.gif"), IO.FileMode.Open)
frogbitmap = New Bitmap(frogstream)
frogbitmap.Save(Server.MapPath("images/frog2.gif"), Imaging.ImageFormat.Gif)
frogstream.Close()
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.ArgumentException: Invalid parameter used.
Source Error:
Line 33: Dim frogbitmap As Bitmap
Line 34: Dim frogstream As New IO.FileStream(Server.MapPath("images/frog2.gif"), IO.FileMode.Open)
Line 35: frogbitmap = New Bitmap(frogstream)
Line 36: frogbitmap.Save(Server.MapPath("images/frog2.gif"), Imaging.ImageFormat.Gif)
Line 37: frogstream.Close()
Source File: C:\Inetpub\wwwroot\WebApplication1\ImageNoCache.aspx.vb Line: 35
Stack Trace:
[ArgumentException: Invalid parameter used.]
System.Drawing.Bitmap..ctor(Stream stream) +271
WebApplication1.ImageNoCache.btnRotate_Click(Object sender, EventArgs e) in C:\Inetpub\wwwroot\WebApplication1\ImageNoCache.aspx.vb:35
System.Web.UI.WebControls.Button.OnClick(EventArgs e) +108
System.Web.UI.WebControls.Button.System.Web.UI.IPostBackEventHandler.RaisePostBackEvent(String eventArgument) +57
System.Web.UI.Page.RaisePostBackEvent(IPostBackEventHandler sourceControl, String eventArgument) +18
System.Web.UI.Page.RaisePostBackEvent(NameValueCollection postData) +33
System.Web.UI.Page.ProcessRequestMain() +1273
Here is the one where I close the FileStream first:
Dim frogbitmap As Bitmap
Dim frogstream As New IO.FileStream(Server.MapPath("images/frog2.gif"), IO.FileMode.Open)
frogbitmap = New Bitmap(frogstream)
frogstream.Close()
frogbitmap.Save(Server.MapPath("images/frog2.gif"), Imaging.ImageFormat.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.ArgumentException: Invalid parameter used.
Source Error:
Line 33: Dim frogbitmap As Bitmap
Line 34: Dim frogstream As New IO.FileStream(Server.MapPath("images/frog2.gif"), IO.FileMode.Open)
Line 35: frogbitmap = New Bitmap(frogstream)
Line 36: frogstream.Close()
Line 37: frogbitmap.Save(Server.MapPath("images/frog2.gif"), Imaging.ImageFormat.Gif)
Source File: C:\Inetpub\wwwroot\WebApplication1\ImageNoCache.aspx.vb Line: 35
Stack Trace:
[ArgumentException: Invalid parameter used.]
System.Drawing.Bitmap..ctor(Stream stream) +271
WebApplication1.ImageNoCache.btnRotate_Click(Object sender, EventArgs e) in C:\Inetpub\wwwroot\WebApplication1\ImageNoCache.aspx.vb:35
System.Web.UI.WebControls.Button.OnClick(EventArgs e) +108
System.Web.UI.WebControls.Button.System.Web.UI.IPostBackEventHandler.RaisePostBackEvent(String eventArgument) +57
System.Web.UI.Page.RaisePostBackEvent(IPostBackEventHandler sourceControl, String eventArgument) +18
System.Web.UI.Page.RaisePostBackEvent(NameValueCollection postData) +33
System.Web.UI.Page.ProcessRequestMain() +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.