0

I am getting byte from database and convert them into an image and post it in asp:image; it doesn't work in when the page is hosted in server although page is working locally properly. Why is this happening? This is not a JS error either, most likely to be an exception.

Error: a generic error occurred in gdi+

ASP VB.NET code

 ds = objPicturess.GetALLPicturesByCategoryIdnCusId(dplCustomer.SelectedValue, dplCategory.SelectedValue, dtpFromDate.Date, dtpToDate.Date)
                If ds.Tables(0).Rows.Count <> 0 Then
                    For i = 0 To ds.Tables(0).Rows.Count - 1
                        Dim imageContent As Byte() = DirectCast((ds.Tables(0).Rows(i)("Picture")), Byte())
                        byteArrayToImage(imageContent, ds.Tables(0).Rows(i)("PictureTitle"), ds.Tables(0).Rows(i)("Remarks"))
                        'Response.BinaryWrite(imageContent)
                    Next
                    DataList1.DataSource = dt
                    DataList1.DataBind()
                Else
                    DataList1.DataSource = Nothing
                    DataList1.DataBind()
                End If

Public Sub byteArrayToImage(ByVal byteArrayIn As Byte(), ByVal strFile_Name As String, ByVal strRemarks As String)
        Try

            Dim newImage As System.Drawing.Image
            Dim strFileName2 As String
            strPictureTitle = ""
            strPictureTitle = strFile_Name
            strFileName = ""
            strFileName = "~/PictureGallery/" & strFile_Name & ".jpg"
            strFileName2 = Server.MapPath("~/PictureGallery/" & strFile_Name & ".jpg")
            Dim f As New IO.FileInfo(strFileName)
            If Not f.Exists Then
                Using stream As New MemoryStream(byteArrayIn)
                    newImage = System.Drawing.Image.FromStream(stream)
                    newImage.Save(strFileName2)
                End Using
            End If
            dr = dt.NewRow()
            dr("PictureTitle") = strPictureTitle
            dr("Picture") = strFileName
            dr("Remarks") = strRemarks
            dt.Rows.Add(dr)

        Catch ex As Exception
            ScriptManager.RegisterClientScriptBlock(Page, Page.GetType(), "message", "alert('" + ex.Message + "');", True)
        End Try
    End Sub

ASPx code

 <ItemTemplate>
      <asp:Label ID="Label1" runat="server" Font-Bold="True" Text ='<%# Eval("PictureTitle")%>'

         Font-Size="10pt" ForeColor="#336699" Width="100%" />
      <br /> 
     <asp:ImageMap  BorderWidth="1px" BorderColor="Black" runat="server" Height = "175px" ID="imageZoom" Width = "172px" ImageUrl= '<%# Eval("Picture")%>'   StyleFolder="styles/simple"  BigImageUrl='<%# Eval("Picture")%>'/>
     <br />
     <asp:Label ID="lblRemarks" runat="server" Font-Bold="True" Text ='<%# Eval("Remarks")%>' Font-Size="10pt" ForeColor="#336699" Width="100%" /> 

   </ItemTemplate>
halfer
  • 19,824
  • 17
  • 99
  • 186
gayan1991
  • 753
  • 2
  • 11
  • 35

2 Answers2

1

You can access folder security / permissions directly through IIS:

  1. Open inetmgr (start > run > inetmgr)
  2. Expand your site and right-click the folder where your images are being written
  3. Click "Edit Permissions"
  4. Go to the Security tab
  5. Add the appropriate account to the list of authorized users and/or make sure that account has write permission.
  6. Apply the changes
Code Uniquely
  • 6,356
  • 4
  • 30
  • 40
0

Give permission to your folder from IIS

gayan1991
  • 753
  • 2
  • 11
  • 35