943,652 Members | Top Members by Rank

Ad:
  • ASP.NET Discussion Thread
  • Unsolved
  • Views: 2388
  • ASP.NET RSS
Nov 11th, 2008
0

Load image in report in runtime in ASP.Net

Expand Post »
Hi,

I have to display a logo in crystal report in runtime. I have tried two solutions given in http://www.devx.com/codemag/Article/33658/1954 (Tip 6: Better Handling of Dynamic Images)

Dim data As New DataSet()
Dim row As DataRow

Step1 (Passing Image URL into dataset): my code is as follows
asp.net Syntax (Toggle Plain Text)
  1. Private Sub LoadImgUrl()
  2. Try
  3. data.Tables.Add("Image")
  4. data.Tables("Image").Columns.Add("Name")
  5.  
  6. row = data.Tables(0).NewRow()
  7. row(0) = Server.MapPath("DI.bmp")
  8. data.Tables(0).Rows.Add(row)
  9.  
  10. rptDoc.Load(Server.MapPath("rptImgUrl.rpt"))
  11. rptDoc.SetDataSource(data)
  12.  
  13. Response.Clear()
  14. Response.Buffer = True
  15. Response.ClearContent()
  16. Response.ClearHeaders()
  17.  
  18. Response.ContentType = "application/pdf"
  19. rptDoc.ExportToHttpResponse(CrystalDecisions.Shared.ExportFormatType.PortableDocFormat, Response, False, "")
  20.  
  21. Response.Flush()
  22.  
  23. Response.End()
  24. Catch ex As Exception
  25.  
  26. End Try
  27.  
  28. End Sub
--------------

Step2 (Storing Image into dataset): my code is as follows

asp.net Syntax (Toggle Plain Text)
  1. Private Sub LoadImgDS()
  2. Try
  3. data.Tables.Add("Image")
  4. data.Tables("Image").Columns.Add("Logo", System.Type.GetType("System.Byte[]"))
  5.  
  6. Dim fs As New System.IO.FileStream(Server.MapPath("DI.bmp"), System.IO.FileMode.Open, IO.FileAccess.Read)
  7. Dim br As New System.IO.BinaryReader(fs)
  8.  
  9. row = data.Tables("Image").NewRow()
  10. row("Logo") = br.ReadBytes(br.BaseStream.Length)
  11. data.Tables("Image").Rows.Add(row)
  12.  
  13. rptDoc.Load(Server.MapPath("rptImgDS.rpt"))
  14. rptDoc.SetDataSource(data)
  15.  
  16. Response.Clear()
  17. Response.Buffer = True
  18. Response.ClearContent()
  19. Response.ClearHeaders()
  20.  
  21. Response.ContentType = "application/pdf"
  22. rptDoc.ExportToHttpResponse(CrystalDecisions.Shared.ExportFormatType.PortableDocFormat, Response, False, "")
  23. br.Close()
  24. fs.Close()
  25.  
  26. br = Nothing
  27. fs = Nothing
  28. Catch ex As Exception
  29.  
  30. End Try
  31. End Sub
--------

In both case i am getting error "cannot obtain value" in following line:

rptDoc.ExportToHttpResponse(CrystalDecisions.Shared.ExportFormatType.PortableDocFormat, Response, False, "")

Need help to solve this. Its very urgent.

Thanks
Last edited by peter_budo; Nov 12th, 2008 at 5:49 am. Reason: Keep It Organized - For easy readability, always wrap programming code within posts in [code] (code blocks) and [icode] (inline code) tags.
Reputation Points: 10
Solved Threads: 0
Newbie Poster
plugsharma is offline Offline
5 posts
since Apr 2008

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in ASP.NET Forum Timeline: abt ddl
Next Thread in ASP.NET Forum Timeline: create sqldatasource through coding





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC