G
Guest
Hi ,
I am working in c# with crystal report XI.
I read an example about dynamic image location ..
1) In that we have a xml xchema file with two fields n amed
country--datatype is string, img--datatype is base64Binary. using this as the
datasource,i have designed the crytal report. And a parameter is set asking
for the name.
2) I have designed teh form by adding a crystal report viewer and
now the coding part is as follows
// Prcocedure: AddImageRow
// reads an image file and adds this image to a dataset table
//
// [in] tbl DataTable
// country name of a country
// filename name of an image file
//
void AddImageRow(DataTable tbl, string name, string filename)
{
FileStream fs = new FileStream(filename, FileMode.Open);
// create a file stream
BinaryReader br = new BinaryReader(fs);
// create binary reader
DataRow row;
// create a new datarow
row = tbl.NewRow();
// set country field and image field
row[0] = name;
row = br.ReadBytes((int)br.BaseStream.Length);
// add this row to the table
tbl.Rows.Add(row);
// clean up
br = null;
fs = null;
}
// Function: CreateData
// Creates a dataset that has 1 table with two fields: Country (string), and
img (blob/byte[])
// Adds four records to this table
//
DataSet CreateData()
{
DataSet data = new DataSet();
// add a table 'Images' to the dataset
data.Tables.Add("Images");
// add two fields
data.Tables[0].Columns.Add("Country",
System.Type.GetType("System.String"));
data.Tables[0].Columns.Add("img", System.Type.GetType("System.Byte[]"));
// add rows
AddImageRow(data.Tables[0], "argentina", Directory.GetCurrentDirectory()
+ "\\argentina.jpg");
AddImageRow(data.Tables[0], "canada", Directory.GetCurrentDirectory() +
"\\canada.jpg");
return (data);
}
// Procedure: CreateReport
// Creates a report and passes the dataset
//
void CreateReport()
{
// create a report
CrystalReport1 cr = new CrystalReport1();
cr.SetDataSource(CreateData());
// pass a reportdocument to the viewer
crystalReportViewer1.ReportSource = cr;
}
public Form1()
{
//
// Required for Windows Form Designer support
//
InitializeComponent();
//
// TODO: Add any constructor code after InitializeComponent call
//
CreateReport();
}
This is the coding part..ie,when the program is run the image which is
existing in the directory (say argentina.jpg and canada.jpg). it will ask for
country name...so if we type canada..then canada.jpg wil be displyed in the
report.
This is wht the program does..
No I have to modify such that .. I have to add a buttn on the form say
load..so when the load button is clicked, we should be able to load any image
from the disk(any location) and that image should be displayed in the crystal
report..How to do this..
please if any one change the coding part above and sent it .
BATISTA
I am working in c# with crystal report XI.
I read an example about dynamic image location ..
1) In that we have a xml xchema file with two fields n amed
country--datatype is string, img--datatype is base64Binary. using this as the
datasource,i have designed the crytal report. And a parameter is set asking
for the name.
2) I have designed teh form by adding a crystal report viewer and
now the coding part is as follows
// Prcocedure: AddImageRow
// reads an image file and adds this image to a dataset table
//
// [in] tbl DataTable
// country name of a country
// filename name of an image file
//
void AddImageRow(DataTable tbl, string name, string filename)
{
FileStream fs = new FileStream(filename, FileMode.Open);
// create a file stream
BinaryReader br = new BinaryReader(fs);
// create binary reader
DataRow row;
// create a new datarow
row = tbl.NewRow();
// set country field and image field
row[0] = name;
row = br.ReadBytes((int)br.BaseStream.Length);
// add this row to the table
tbl.Rows.Add(row);
// clean up
br = null;
fs = null;
}
// Function: CreateData
// Creates a dataset that has 1 table with two fields: Country (string), and
img (blob/byte[])
// Adds four records to this table
//
DataSet CreateData()
{
DataSet data = new DataSet();
// add a table 'Images' to the dataset
data.Tables.Add("Images");
// add two fields
data.Tables[0].Columns.Add("Country",
System.Type.GetType("System.String"));
data.Tables[0].Columns.Add("img", System.Type.GetType("System.Byte[]"));
// add rows
AddImageRow(data.Tables[0], "argentina", Directory.GetCurrentDirectory()
+ "\\argentina.jpg");
AddImageRow(data.Tables[0], "canada", Directory.GetCurrentDirectory() +
"\\canada.jpg");
return (data);
}
// Procedure: CreateReport
// Creates a report and passes the dataset
//
void CreateReport()
{
// create a report
CrystalReport1 cr = new CrystalReport1();
cr.SetDataSource(CreateData());
// pass a reportdocument to the viewer
crystalReportViewer1.ReportSource = cr;
}
public Form1()
{
//
// Required for Windows Form Designer support
//
InitializeComponent();
//
// TODO: Add any constructor code after InitializeComponent call
//
CreateReport();
}
This is the coding part..ie,when the program is run the image which is
existing in the directory (say argentina.jpg and canada.jpg). it will ask for
country name...so if we type canada..then canada.jpg wil be displyed in the
report.
This is wht the program does..
No I have to modify such that .. I have to add a buttn on the form say
load..so when the load button is clicked, we should be able to load any image
from the disk(any location) and that image should be displayed in the crystal
report..How to do this..
please if any one change the coding part above and sent it .
BATISTA