Click here to Skip to main content
15,881,812 members
Please Sign up or sign in to vote.
1.67/5 (3 votes)
See more:
VB
Protected Sub btnSave_Click(ByVal sender As Object, ByVal e As EventArgs) Handles btnSave.Click

    Dim productId As Integer = 0
    Dim userId As Integer = 0
    userId = Convert.ToInt32(Session(Common.SESSION_USERID).ToString())

    Dim strImage1 As String = String.Empty
    Dim FileImage1 As String = String.Empty
    Dim strParth1 As String = String.Empty
    Dim strRemoveString1 As String = String.Empty
    If (flImage1.HasFile) Then
        Dim strPath As String = Server.MapPath("Common/ProductImages/")
        'Dim strPath As String = Server.MapPath("httpdocs/Common/ProductImages/")
        flImage1.SaveAs(strPath + flImage1.FileName)
        strParth1 = strPath + flImage1.FileName
        FileImage1 = flImage1.FileName
        strImage1 = "Common/ProductImages/" + flImage1.FileName

        Dim big As String = "~Big"
        Dim strm As Stream = flImage1.PostedFile.InputStream
        Dim targetFile = strParth1
        GenerateThumbnails(3.0, strm, targetFile, big)

    Else
       
    End If

    If Request.QueryString("Id") IsNot Nothing Then
        productId = InsertUpdateProduct(Convert.ToInt32(Request.QueryString("Id")), userId, txtName.Text, editorDesc.Content, txtPrice.Text, strImage1, txtShippingPrice.Text)
        If productId > 0 Then
            lblMsg.Text = "updated successfuly...."
            lblMsg.ForeColor = System.Drawing.Color.Green
        End If
    Else

        Dim strProductCount As Integer
        Dim strPlan As String = String.Empty

        strProductCount = Session(Common.SESSION_ProductCount)
        strPlan = Session(Common.SESSION_PlanTitle)

        If (Convert.ToInt32(strProductCount) < 30 And strPlan = "Gold Member") Then

            productId = InsertUpdateProduct(0, userId, txtName.Text, editorDesc.Content, txtPrice.Text, strImage1, strImage2, strImage3, txtShippingPrice.Text)
            If productId > 0 Then
                lblMsg.Text = "inserted successfuly...."
                lblMsg.ForeColor = System.Drawing.Color.Green
            End If
        Else
        End If

    End If

End Sub


VB
Private Sub GenerateThumbnails(ByVal scaleFactor As Double, ByVal sourcePath As Stream, ByVal targetPath As String, ByVal name As String)
    Using image = System.Drawing.Image.FromStream(sourcePath)
        Dim newWidth = CInt(Math.Truncate(image.Width * scaleFactor))
        Dim newHeight = CInt(Math.Truncate(image.Height * scaleFactor))
        Dim thumbnailImg = New Bitmap(newWidth, newHeight)
        Dim thumbGraph = Graphics.FromImage(thumbnailImg)
        thumbGraph.CompositingQuality = CompositingQuality.HighQuality
        thumbGraph.SmoothingMode = SmoothingMode.HighQuality
        thumbGraph.InterpolationMode = InterpolationMode.HighQualityBicubic
        Dim imageRectangle = New Rectangle(0, 0, newWidth, newHeight)
        thumbGraph.DrawImage(image, imageRectangle)

        Dim withoutExtension As String = targetPath
        Dim strImage As String = String.Empty
        Dim strArr() As String
        strArr = withoutExtension.Split(".")
        strImage = strArr(0)
        targetPath = strImage + ".jpg"

        Dim targetPath1 As String = targetPath.Replace(Path.GetFileNameWithoutExtension(targetPath), Path.GetFileNameWithoutExtension(targetPath) & name)

        thumbnailImg.Save(targetPath1, image.RawFormat)
        thumbnailImg.Dispose()
    End Using
End Sub





Above this code are properly working on local or IIS but in Server this code is not working
It's a generic error occurred in gdi+
Please resolve this problem....
It's urgent.
Posted
Updated 1-Sep-14 6:08am
v2
Comments
Dave Kreskowiak 1-Sep-14 11:38am    
Yeah, you're going to have to specify what line that crashes on.
[no name] 1-Sep-14 12:05pm    
You probably have a permission issue. And, no it's not urgent at all.
abhishek burnwal Kolkata 2-Sep-14 2:13am    
these error comes in when image has been uploaded.......
I have already given the folder permission.

Server Error in '/' Application.

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.ExternalException: A generic error occurred in GDI+.

Source Error:

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.

Stack Trace:


[ExternalException (0x80004005): A generic error occurred in GDI+.]
System.Drawing.Image.Save(String filename, ImageCodecInfo encoder, EncoderParameters encoderParams) +381522
System.Drawing.Image.Save(String filename, ImageFormat format) +69
FindurBiz.Product.GenerateThumbnails(Double scaleFactor, Stream sourcePath, String targetPath, String name) +768
FindurBiz.Product.btnSave_Click(Object sender, EventArgs e) +2277
System.Web.UI.WebControls.Button.OnClick(EventArgs e) +111
System.Web.UI.WebControls.Button.RaisePostBackEvent(String eventArgument) +110
System.Web.UI.WebControls.Button.System.Web.UI.IPostBackEventHandler.RaisePostBackEvent(String eventArgument) +10
System.Web.UI.Page.RaisePostBackEvent(IPostBackEventHandler sourceControl, String eventArgument) +13
System.Web.UI.Page.RaisePostBackEvent(NameValueCollection postData) +36
System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +1565

Version Information: Microsoft .NET Framework Version:2.0.50727.5472; ASP.NET Version:2.0.50727.5474
Rajiv Gogoi 2-Sep-14 12:12pm    
might be a path issue. does the path folder exist on server?

1 solution

Use some logging in server to find out which line of code has the issue. As its working on local etc, perhaps there is some permission issue etc. Code review won't help in such cases.
 
Share this answer
 
Comments
abhishek burnwal Kolkata 2-Sep-14 2:11am    

these error comes in when image has been uploaded.......

I have already given the folder permission.

Server Error in '/' Application.

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.ExternalException: A generic error occurred in GDI+.

Source Error:

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.

Stack Trace:


[ExternalException (0x80004005): A generic error occurred in GDI+.]
System.Drawing.Image.Save(String filename, ImageCodecInfo encoder, EncoderParameters encoderParams) +381522
System.Drawing.Image.Save(String filename, ImageFormat format) +69
FindurBiz.Product.GenerateThumbnails(Double scaleFactor, Stream sourcePath, String targetPath, String name) +768
FindurBiz.Product.btnSave_Click(Object sender, EventArgs e) +2277
System.Web.UI.WebControls.Button.OnClick(EventArgs e) +111
System.Web.UI.WebControls.Button.RaisePostBackEvent(String eventArgument) +110
System.Web.UI.WebControls.Button.System.Web.UI.IPostBackEventHandler.RaisePostBackEvent(String eventArgument) +10
System.Web.UI.Page.RaisePostBackEvent(IPostBackEventHandler sourceControl, String eventArgument) +13
System.Web.UI.Page.RaisePostBackEvent(NameValueCollection postData) +36
System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +1565

Version Information: Microsoft .NET Framework Version:2.0.50727.5472; ASP.NET Version:2.0.50727.5474

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900