A generic error occurred in GDI+http://forums.asp.net/t/1009359.aspx/1?A+generic+error+occurred+in+GDI+Thu, 17 Aug 2006 13:47:07 -040010093591344645http://forums.asp.net/p/1009359/1344645.aspx/1?A+generic+error+occurred+in+GDI+A generic error occurred in GDI+ I have a sub routine that I wrote in vb.net for asp.net to resize an image from a source location and write it to 3 seperate locations after creating some different sizes. It works well when I call the routine once after performing an image upload to the server. But the kicker is that I also would like to use this as a batch image processor on a directory. So I wrote another routine that runs on a button click to call the resizeImage routine in a loop for all the images that need to be resized. When the button click routine runs I get &quot;A generic error occurred in GDI&#43;&quot;. I put the code in a try catch to see if maybe it was one image or a particular type but it happens for all images. I have verified that the permissions are correct on the source and target image directories. <br> <br> <b>Here is a sample of what I get in my try catch:</b><br> <br> Source: System.Drawing<br> Message: A generic error occurred in GDI&#43;.<br> d:\winhostssl01\hosting\shroomstr\upload\tro651.jpg<br> <br> Source: System.Drawing<br> Message: A generic error occurred in GDI&#43;.<br> d:\winhostssl01\hosting\shroomstr\upload\tro760b.jpg<br> <br> Source: System.Drawing<br> Message: A generic error occurred in GDI&#43;.<br> d:\winhostssl01\hosting\shroomstr\upload\tro962.jpg<br> <br> Source: System.Drawing<br> Message: A generic error occurred in GDI&#43;.<br> d:\winhostssl01\hosting\shroomstr\upload\wmb500.jpg<br> <br> Could not find:<br> d:\winhostssl01\hosting\shroomstr\upload\wr25.jpg<br> <br> Could not find:<br> d:\winhostssl01\hosting\shroomstr\upload\WR30.jpg<br> <br> 0 Images already existed on the server<br> 0 Images where imported to the server<br> 202 Images could not be found<br> 36 Errors occured<br> <br> <br> <b>The could not find is ok due to that fact that not all the images are in the directory at the moment but I just can't seem to figure out what is causing the GDI&#43; error. </b><br> <br> <b>Here is the resizeImage routine that I have written:</b><br> <br> Private Sub resizeImage(ByVal source As String, ByVal largeTarget As String, ByVal thumbTarget As String, ByVal origTarget As String)<br> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Dim multiplier As Double = 5<br> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Dim foundGoodSize As Boolean = False<br> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Dim szLargeSize As Size = New Size(167, 198)<br> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Dim szThumbSize As Size = New Size(83, 99)<br> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Dim bmpNewBitmap As Bitmap<br> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Dim bmpSource As Bitmap<br> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Dim bmpThumb As Bitmap<br> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Dim g As Graphics<br> <br> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; bmpSource = Image.FromFile(source)<br> <br> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; While Not foundGoodSize<br> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; If ((bmpSource.Width * multiplier &lt;= szLargeSize.Width) And (bmpSource.Height * multiplier &lt;= szLargeSize.Height)) Then<br> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; foundGoodSize = True<br> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; szLargeSize.Width = bmpSource.Width * multiplier<br> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; szLargeSize.Height = bmpSource.Height * multiplier<br> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Else<br> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; multiplier -= 0.01<br> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; End If<br> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; End While<br> <br> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; bmpNewBitmap = New Bitmap(szLargeSize.Width, szLargeSize.Height)<br> <br> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; g = Graphics.FromImage(bmpNewBitmap)<br> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; g.SmoothingMode = Drawing2D.SmoothingMode.HighQuality<br> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; g.InterpolationMode = Drawing2D.InterpolationMode.HighQualityBicubic<br> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; g.PixelOffsetMode = Drawing2D.PixelOffsetMode.HighQuality<br> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; g.DrawImage(bmpSource, 0, 0, bmpNewBitmap.Width, bmpNewBitmap.Height)<br> <br> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; szThumbSize.Width = szLargeSize.Width / 2<br> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; szThumbSize.Height = szLargeSize.Height / 2<br> <br> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; bmpThumb = New Bitmap(bmpNewBitmap.GetThumbnailImage(szThumbSize.Width, szThumbSize.Height, Nothing, IntPtr.Zero))<br> <br> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; bmpNewBitmap.SetResolution(72, 72)<br> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; bmpThumb.SetResolution(72, 72)<br> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; bmpSource.SetResolution(72, 72)<br> <br> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; bmpNewBitmap.Save(largeTarget, Imaging.ImageFormat.Jpeg)<br> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; bmpThumb.Save(thumbTarget, Imaging.ImageFormat.Jpeg)<br> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; bmpSource.Save(origTarget, Imaging.ImageFormat.Jpeg)<br> <br> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; bmpNewBitmap.Dispose()<br> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; bmpThumb.Dispose()<br> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; bmpSource.Dispose()<br> <br> <br> <b>Here is the code I use to call it after the single image upload that works great:</b><br> <br> Private Sub btnSubmit_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnSubmit.Click<br> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Dim foundError As Boolean<br> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; lblInfo.Visible = False<br> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; uplProductImage.uploadResult = &quot;&quot;<br> <br> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; If Page.IsValid Then<br> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; If uplProductImage.fileText &lt;&gt; &quot;&quot; Then<br> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; uplProductImage.upload(sender, e)<br> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; End If<br> <br> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Dim errorFound As Boolean<br> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Dim myTarget As String<br> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Dim source As String = HttpContext.Current.Server.MapPath(Request.ApplicationPath) &amp; &quot;upload\&quot; &amp; Path.GetFileName(uplProductImage.fileText)<br> <br> <br> <br> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; If uplProductImage.fileText &lt;&gt; &quot;&quot; Then<br> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; If File.Exists(source) Then<br> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; resizeImage(source, largeTarget, thumbTarget, origTarget)<br> <br> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Else<br> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; lblInfo.Visible = True<br> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; lblInfo.Text = &quot;You Must Upload The Image File Before You Can Submit The Product Information. Click The Upload File Button At The Bottom Of The Page.&quot;<br> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; errorFound = True<br> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; End If<br> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; End If<br> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; If Not errorFound Then<br> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; addProduct()<br> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; btnClear_Click(sender, e)<br> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; End If<br> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; End If<br> &nbsp;&nbsp;&nbsp; End Sub<br> <br> <b>Here is the code I use to call the resizeImage in the loop that is giving me the problem:</b><br> <br> Private Sub btnImportImages_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnImportImages.Click<br> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Dim cmdSelect As New SqlCommand(&quot;Select sku, manufacturer from products&quot;, conDb)<br> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Dim ImportFileName As String<br> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Dim dtResult As New DataTable<br> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Dim myReader As SqlDataReader<br> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Dim myRow As DataRow<br> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Dim productCount As Integer<br> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Dim imageExistOnServer As Integer<br> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Dim imagesImported As Integer<br> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Dim couldNotFind As Integer<br> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Dim errorCount As Integer<br> <br> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; dtResult.Columns.Add(&quot;sku&quot;)<br> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; dtResult.Columns.Add(&quot;manufacturer&quot;)<br> <br> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; conDb.Open()<br> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; myReader = cmdSelect.ExecuteReader<br> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; While myReader.Read<br> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; myRow = dtResult.NewRow<br> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; myRow.Item(&quot;sku&quot;) = myReader.Item(&quot;sku&quot;)<br> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; myRow.Item(&quot;manufacturer&quot;) = myReader.Item(&quot;manufacturer&quot;)<br> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; dtResult.Rows.Add(myRow)<br> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; productCount &#43;= 1<br> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; End While<br> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; conDb.Close()<br> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; lblImageImportResult.Text = productCount &amp; &quot; Products found in the database&lt;br&gt;&quot;<br> <br> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; For Each myRow In dtResult.Rows<br> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; ImportFileName = bulkImageDir &amp; myRow.Item(&quot;sku&quot;) &amp; &quot;.jpg&quot; 'myRow.Item(&quot;manufacturer&quot;) &amp; &quot;\&quot; &amp; myRow.Item(&quot;sku&quot;) &amp; &quot;.jpg&quot;<br> <br> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Try<br> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; If Not File.Exists(largeTarget) Then<br> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; If File.Exists(ImportFileName) Then<br> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; resizeImage(ImportFileName, largeTarget, thumbTarget, origTarget)<br> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; imagesImported &#43;= 1<br> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Else<br> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; lblImageImportResult.Text &#43;= &quot;&lt;br&gt;&lt;br&gt; Could not find:&lt;br&gt;&quot; &amp; ImportFileName<br> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; couldNotFind &#43;= 1<br> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; End If<br> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Else<br> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; imageExistOnServer &#43;= 1<br> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; End If<br> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Catch ex As Exception<br> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; lblImageImportResult.Text &#43;= &quot;&lt;br&gt;&lt;br&gt;Source: &quot; &amp; ex.Source &amp; &quot;&lt;br&gt;Message: &quot; &amp; ex.Message &amp; &quot;&lt;br&gt;&quot; &amp; ImportFileName<br> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; errorCount &#43;= 1<br> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; End Try<br> <br> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Next<br> <br> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; lblImageImportResult.Text &#43;= &quot;&lt;br&gt;&lt;br&gt;&quot; &amp; imageExistOnServer &amp; &quot; Images already existed on the server&lt;br&gt;&quot; &amp; imagesImported &amp; &quot; Images where imported to the server&lt;br&gt;&quot; &amp; couldNotFind &amp; &quot; Images could not be found&lt;br&gt;&quot; &amp; errorCount &amp; &quot; Errors occured&quot;<br> <br> &nbsp;&nbsp;&nbsp; End Sub<br> <br> <b>Here is the Stack Trace from the error caused:</b><br> <br> &nbsp;A generic error occurred in GDI&#43;.<br> 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.<br> <br> Exception Details: System.Runtime.InteropServices.ExternalException: A generic error occurred in GDI&#43;.<br> <br> Source Error:<br> <br> An unhandled exception was generated during the execution of the current web request. Information regarding the origin and location of the exception can be identified using the exception stack trace below.<br> <br> Stack Trace:<br> <br> [ExternalException (0x80004005): A generic error occurred in GDI&#43;.]<br> &nbsp;&nbsp; System.Drawing.Image.Save(String filename, ImageCodecInfo encoder, EncoderParameters encoderParams) &#43;579<br> &nbsp;&nbsp; System.Drawing.Image.Save(String filename, ImageFormat format) &#43;59<br> &nbsp;&nbsp; enternetshop.dbManager1.resizeImage(String source, String largeTarget, String thumbTarget, String origTarget)<br> &nbsp;&nbsp; enternetshop.dbManager1.btnImportImages_Click(Object sender, EventArgs e)<br> &nbsp;&nbsp; System.Web.UI.WebControls.Button.OnClick(EventArgs e) &#43;108<br> &nbsp;&nbsp; System.Web.UI.WebControls.Button.System.Web.UI.IPostBackEventHandler.RaisePostBackEvent(String eventArgument) &#43;57<br> &nbsp;&nbsp; System.Web.UI.Page.RaisePostBackEvent(IPostBackEventHandler sourceControl, String eventArgument) &#43;18<br> &nbsp;&nbsp; System.Web.UI.Page.RaisePostBackEvent(NameValueCollection postData) &#43;33<br> &nbsp;&nbsp; System.Web.UI.Page.ProcessRequestMain() &#43;1292<br> <br> <br> Version Information: Microsoft .NET Framework Version:1.1.4322.2300; ASP.NET Version:1.1.4322.2300<br> <br> If somebody could please look at this and see if I am overlooking something it would be greatly appreciated. 2006-07-18T17:28:30-04:001347551http://forums.asp.net/p/1009359/1347551.aspx/1?Re+A+generic+error+occurred+in+GDI+Re: A generic error occurred in GDI+ Alright, I finally found what was causing the error. It kind a dumb problem too. Oh well, sometimes I find it helps if you've been up coding for a while to just leave the problem and move on to something else for a bit. Anyway the problem was that I was passing in the 3 targets to my imageResize subroutine after they were set for the single image upload routine. I was setting them in the page load like so.<br> <br> largeTarget = HttpContext.Current.Server.MapPath(Request.ApplicationPath) &amp; &quot;images\products\large\&quot; &amp; txtSku.Text.ToLower &amp; Path.GetExtension(uplProductImage.fileText)<br> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; thumbTarget = HttpContext.Current.Server.MapPath(Request.ApplicationPath) &amp; &quot;images\products\thumb\&quot; &amp; txtSku.Text.ToLower &amp; Path.GetExtension(uplProductImage.fileText)<br> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; origTarget = HttpContext.Current.Server.MapPath(Request.ApplicationPath) &amp; &quot;images\products\orig\&quot; &amp; txtSku.Text.ToLower &amp; Path.GetExtension(uplProductImage.fileText)<br> <br> The problem is that txtSku.Text is not set at this point leaving all the targets without a filename. Darn!<br> So here is the modified buttonClick routine that calls my resizeImage routine.<br> <br> &nbsp;&nbsp;&nbsp; Private Sub btnImportImages_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnImportImages.Click<br> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Dim cmdSelect As New SqlCommand(&quot;Select sku, manufacturer from products&quot;, conDb)<br> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Dim ImportFileName As String<br> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Dim dtResult As New DataTable<br> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Dim myReader As SqlDataReader<br> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Dim myRow As DataRow<br> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Dim productCount As Integer<br> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Dim imageExistOnServer As Integer<br> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Dim imagesImported As Integer<br> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Dim couldNotFind As Integer<br> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Dim errorCount As Integer<br> <br> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; dtResult.Columns.Add(&quot;sku&quot;)<br> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; dtResult.Columns.Add(&quot;manufacturer&quot;)<br> <br> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; conDb.Open()<br> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; myReader = cmdSelect.ExecuteReader<br> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; While myReader.Read<br> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; myRow = dtResult.NewRow<br> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; myRow.Item(&quot;sku&quot;) = myReader.Item(&quot;sku&quot;)<br> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; myRow.Item(&quot;manufacturer&quot;) = myReader.Item(&quot;manufacturer&quot;)<br> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; dtResult.Rows.Add(myRow)<br> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; productCount &#43;= 1<br> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; End While<br> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; conDb.Close()<br> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; lblImageImportResult.Text = productCount &amp; &quot; Products found in the database&lt;br&gt;&quot;<br> <br> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; For Each myRow In dtResult.Rows<br> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; ImportFileName = bulkImageDir &amp; myRow.Item(&quot;sku&quot;) &amp; &quot;.jpg&quot; 'myRow.Item(&quot;manufacturer&quot;) &amp; &quot;\&quot; &amp; myRow.Item(&quot;sku&quot;) &amp; &quot;.jpg&quot;<br> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <b>largeTarget = HttpContext.Current.Server.MapPath(Request.ApplicationPath) &amp; &quot;images\products\large\&quot; &amp; myRow.Item(&quot;sku&quot;) &amp; &quot;.jpg&quot;<br> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; thumbTarget = HttpContext.Current.Server.MapPath(Request.ApplicationPath) &amp; &quot;images\products\thumb\&quot; &amp; myRow.Item(&quot;sku&quot;) &amp; &quot;.jpg&quot;<br> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; origTarget = HttpContext.Current.Server.MapPath(Request.ApplicationPath) &amp; &quot;images\products\orig\&quot; &amp; myRow.Item(&quot;sku&quot;) &amp; &quot;.jpg&quot;</b><br> <br> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Try<br> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; If Not File.Exists(largeTarget) Then<br> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; If File.Exists(ImportFileName) Then<br> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; resizeImage(ImportFileName, largeTarget, thumbTarget, origTarget)<br> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; imagesImported &#43;= 1<br> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; System.Threading.Thread.Sleep(10000)<br> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Else<br> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; lblImageImportResult.Text &#43;= &quot;&lt;br&gt;&lt;br&gt; Could not find:&lt;br&gt;&quot; &amp; ImportFileName<br> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; couldNotFind &#43;= 1<br> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; End If<br> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Else<br> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; imageExistOnServer &#43;= 1<br> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; End If<br> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Catch ex As Exception<br> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; lblImageImportResult.Text &#43;= &quot;&lt;br&gt;&lt;br&gt;Source: &quot; &amp; ex.Source &amp; &quot;&lt;br&gt;Message: &quot; &amp; ex.Message &amp; &quot;&lt;br&gt;&quot; &amp; ImportFileName<br> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; errorCount &#43;= 1<br> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; End Try<br> <br> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Next<br> <br> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; lblImageImportResult.Text &#43;= &quot;&lt;br&gt;&lt;br&gt;&quot; &amp; imageExistOnServer &amp; &quot; Images already existed on the server&lt;br&gt;&quot; &amp; imagesImported &amp; &quot; Images where imported to the server&lt;br&gt;&quot; &amp; couldNotFind &amp; &quot; Images could not be found&lt;br&gt;&quot; &amp; errorCount &amp; &quot; Errors occured&quot;<br> <br> &nbsp;&nbsp;&nbsp; End Sub<br> <br> Notice the bold text above as it is what I had to add to solve the problem. I also moved the target assignments from the page load to their respective button click routine routine for the single image upload. So the moral behind the story is that when you read oh about 15 forums saying that a &quot;A generic error occurred in GDI&#43;&quot; is usually caused by invalid permssions or incorrect file paths look into that for just a little longer. Also, I would like to say thank you to anybody who has seen this post and tried to solve my error even though that could have been difficult cause I never even posted the part of the code that was &quot;essentially&quot; causing the error.<br> 2006-07-21T04:06:55-04:001373388http://forums.asp.net/p/1009359/1373388.aspx/1?Re+A+generic+error+occurred+in+GDI+Re: A generic error occurred in GDI+ I have read most of the posts on this topic and on my machine:<br> <br> 1. The VS 2005 and IIS server can't write to certain folders, no matter what account is given permission.<br> <br> 2. Turning off the &quot;readonly&quot; attibute on the folder doesn't help.<br> <br> I get a resized picture, but some are out of focus and pixellated.<br> <br> And there is a bug? <a href="http://forums.microsoft.com/MSDN/ShowPost.aspx?PostID=631868&amp;SiteID=1"> http://forums.microsoft.com/MSDN/ShowPost.aspx?PostID=631868&amp;SiteID=1</a><br> 2006-08-17T13:47:07-04:00