on 09-09-2008 9:57 AM
Hi to all,
I'm using Crystalreport 11.5,VisualStudio2005-C#,Asp.Net2.0 and SQL server 2005.
Dynamically i add some tables and fields to crystal report then bind the record then show it in the crystal report viewer.
This is my code
protected void Page_Load(object sender, EventArgs e)
{
try
{
//Create a new ReportDocument
boReportDocument = new ReportDocument();
// load the RPT file
boReportDocument.Load(Server.MapPath("//Success//CR_VerticalDesign.rpt"));
//Access the ReportClientDocument in the ReportDocument (EROM bridge)
boReportClientDocument = boReportDocument.ReportClientDocument;
SelectAnyData();
AddTable();
// show in reportviewer
AddAllFieldByVertical();
CrystalReportViewer1.ReportSource = boReportDocument;
CrystalReportViewer1.DataBind();
}
catch (Exception ex)
{
Response.Write(ex.Message);
}
}
public void AddTable()
{
try
{
boReportClientDocument = boReportDocument.ReportClientDocument;
// Convert the DataSet to an ISCRDataset object (something the ISCDReportClientDocument can understand)
CrystalDecisions.ReportAppServer.DataDefModel.ISCRDataSet rasDS;
SelectAnyData();
rasDS = CrystalDecisions.ReportAppServer.DataSetConversion.DataSetConverter.Convert(m_dataset);
// Add the dataset as a data source to the report
boReportClientDocument.DatabaseController.AddDataSource((object)rasDS);
// Add a field to the report canvas
// Note: This is quick and dirty. No positioning, resizing, formatting, etc.
CrystalDecisions.ReportAppServer.Controllers.ISCRResultFieldController rfc;
CrystalDecisions.ReportAppServer.DataDefModel.ISCRTable crTable;
CrystalDecisions.ReportAppServer.DataDefModel.ISCRField crField;
CrystalDecisions.ReportAppServer.ReportDefModel.ISCRFieldHeadingObject fh;
rfc = boReportClientDocument.DataDefController.ResultFieldController;
crTable = boReportClientDocument.Database.Tables[0];
crField = crTable.DataFields[0]; // Hardcoded field "Customer Name" in the Customer table from Xtreme Sample Database
crField.HeadingText = "id";
//rfc.Add(-1, crField);
//boReportClientDocument.VerifyDatabase();
}
catch (Exception ex)
{
throw ex;
}
}
private void AddAllFieldByVertical()
{
try
{
//Create the text object
boTextObject = new CrystalDecisions.ReportAppServer.ReportDefModel.TextObject();
//Create the paragraph elements for the text Object
boParagraphs = new CrystalDecisions.ReportAppServer.ReportDefModel.Paragraphs();
boParagraph = new CrystalDecisions.ReportAppServer.ReportDefModel.Paragraph();
boParagraphElements = new CrystalDecisions.ReportAppServer.ReportDefModel.ParagraphElements();
boParagraphTextElement = new CrystalDecisions.ReportAppServer.ReportDefModel.ParagraphTextElement();
//Set the text value for the text field
boParagraphTextElement.Text = "Id";
boParagraphTextElement.Kind = CrystalDecisions.ReportAppServer.ReportDefModel.CrParagraphElementKindEnum.crParagraphElementKindText;
boParagraphElements.Add(boParagraphTextElement);
boParagraph.ParagraphElements = boParagraphElements;
boParagraphs.Add(boParagraph);
boTextObject.Paragraphs = boParagraphs;
//Now add it to the section
boTextObject.Left = 3 * 1440;
boTextObject.Top = 1;
boTextObject.Width = 1 * 1440;
boTextObject.Height = 226;
//Get the first section in the details section
boSection = boReportClientDocument.ReportDefController.ReportDefinition.DetailArea.Sections[0];
dtlSection = boReportClientDocument.ReportDefController.ReportDefinition.PageHeaderArea.Sections[0];
//Create the field object that we will add to the report and set all of its properties
boFieldObject = new CrystalDecisions.ReportAppServer.ReportDefModel.FieldObject();
boFieldObject.Name = "imgId";
boFieldObject2 = new CrystalDecisions.ReportAppServer.ReportDefModel.FieldObject();
blobObject = new CrystalDecisions.ReportAppServer.ReportDefModel.BlobFieldObject();
//Set which field to use for the data to be displayed
boFieldObject.DataSourceName = "{User_Images.imgId}";
boFieldObject.DataSource = "{User_Images.imgId}";
boFieldObject.Name = "imgId";
boFieldObject.FieldValueType = CrystalDecisions.ReportAppServer.DataDefModel.CrFieldValueTypeEnum.crFieldValueTypeInt32sField;
boFieldObject.Left = 4 * 1440; //1440 twips per inch
boFieldObject.Width = 3 * 1440;
boFieldObject.FontColor = new CrystalDecisions.ReportAppServer.ReportDefModel.FontColor();
boFieldObject.FontColor.Font.Name = "Arial";
boFieldObject.FontColor.Font.Size = 10;
boFieldObject.Format.HorizontalAlignment = CrystalDecisions.ReportAppServer.ReportDefModel.CrAlignmentEnum.crAlignmentLeft;
//Add the object to the report
boReportClientDocument.ReportDefController.ReportObjectController.Add(boFieldObject, boSection, -1);
boReportClientDocument.ReportDefController.ReportObjectController.Add(boTextObject, boSection, 1);
//boReportClientDocument.ReportDefController.ReportObjectController.Add(imgId, boSection, -1);
//boReportClientDocument.ReportDefController.ReportObjectController.Add((CrystalDecisions.ReportAppServer.ReportDefModel.ISCRReportObject)SampleReportText, boSection, -1);
// show in reportviewer
//CrystalReportViewer1.ReportSource = boReportDocument;
}
catch (Exception ex)
{
throw ex;
}
}
This code is working fine if i'm not create this project as Virtual Directory, if i create this project as Virtual Directory then this line raised error
boReportDocument.Load(Server.MapPath("//Success//CR_VerticalDesign.rpt"));
like as
{System.Exception: Load report failed. ---> System.Runtime.InteropServices.COMException (0x80004005): The system cannot find the path specified.
at CrystalDecisions.ReportAppServer.ClientDoc.ReportClientDocumentClass.Open(Object& DocumentPath, Int32 Options)
at CrystalDecisions.ReportAppServer.ReportClientDocumentWrapper.Open(Object& DocumentPath, Int32 Options)
at CrystalDecisions.ReportAppServer.ReportClientDocumentWrapper.EnsureDocumentIsOpened()
--- End of inner exception stack trace ---
at CrystalDecisions.ReportAppServer.ReportClientDocumentWrapper.EnsureDocumentIsOpened()
at CrystalDecisions.CrystalReports.Engine.ReportDocument.Load(String filename, OpenReportMethod openMethod, Int16 parentJob)
at CrystalDecisions.CrystalReports.Engine.ReportDocument.Load(String filename)
at DynamicCrystalReports.Success.VerticalDesignWithMultipleFields.Page_Load(Object sender, EventArgs e) in D:\Jeyaseelan\DotNetPracticals2005\CR 11.5 A2\DynamicCrystalReports\DynamicCrystalReports\Success\VerticalDesignWithMultipleFields.aspx.cs:line 51}
Hello Winseelan,
please try to get the real path name first in a variable and use this.
string path_name = Server.MapPath();
I am not sure if the CR engine can use Server.MapPath as file location.
But I'd rather call this a limitation of the product than a bug.
Best regards
Falk
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
User | Count |
---|---|
87 | |
10 | |
10 | |
10 | |
7 | |
6 | |
6 | |
5 | |
5 | |
4 |
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.