Symptom
How can you load an image from disk into a dataset using CSharp (C#) in Visual Studio .NET?
Resolution
To load an image into a DataSet, use the following code:
using System;
using System.Data;
using System.Configuration;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using CrystalDecisions.CrystalReports.Engine;
public partial class _Default : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
//Load image from disk into dataset
MyDataSet myDataSet = new MyDataSet();
System.IO.BinaryReader binaryReader = new System.IO.BinaryReader(new System.IO.FileStream(Server.MapPath("image.jpeg"),System.IO.FileMode.Open));
myDataSet.Images.AddImagesRow(binaryReader.ReadBytes(Convert.ToInt32(new System.IO.FileInfo(Server.MapPath("image.jpeg")).Length)));
binaryReader.Close();
//Prepare report
ReportDocument reportDocument = new ReportDocument();
reportDocument.Load(Server.MapPath("MyReport.rpt"));
reportDocument.SetDataSource(myDataSet);
///
}
}
TIP |
If the code sample is truncated in your browser window, copy and paste the entire block of code into a text editor. Code samples are intentionally formatted this way so they do not wrap. Wrapped code can produce unexpected errors in your application. |
NOTE |
This code snippet is meant as an example only and is not a
supported BusinessObjects product. All custom code should be
thoroughly tested in your own development environment prior to
using in production.
|
Keywords
dataset image VS2005 load , 3784723 , KBA , BI-DEV-NET-SDK , .NET SDK / COM SDK , How To
Product
SAP Crystal Reports, developer version for Microsoft Visual Studio ; SAP Crystal Reports, version for Visual Studio .NET 2008