Reputation: 73
I am trying to create a xtrareport with xml in asp.net using c#. I created xml and reference to xtrareport. I have also selected data source schmema and data member on xtrareport design and put fields to labels. I have also debugged dataset and it is not empty. But I can't see data on my report page.
SqlConnection conn = new SqlConnection(@"blabla");
SqlCommand select = new SqlCommand(@"select * from table",conn);
conn.Open();
SqlDataAdapter da = new SqlDataAdapter(select);
DataSet ds = new DataSet();
da.Fill(ds);
//ds.WriteXmlSchema(@"C:\dataset.xml");
XtraReport1 rpr = new XtraReport1();
rpr.DataSource = ds;
rpr.PrintingSystem.SetCommandVisibility(PrintingSystemCommand.ClosePreview, DevExpress.XtraPrinting.CommandVisibility.None);
rpr.CreateDocument(true);`
Upvotes: 0
Views: 1797
Reputation: 11
personally I create extensions to load and save xml Layout of reports. I create them with an win application or whatever then save the xml layout:
public static void RestoreFromXmlXtraReportLayout(this DevExpress.XtraReports.UI.XtraReport report, string xmlXtraReportLayout)
{
if (!string.IsNullOrEmpty(xmlXtraReportLayout))
{
string fileName = System.IO.Path.GetTempPath() + Guid.NewGuid().ToString() + ".repx";
System.IO.File.WriteAllText(fileName, xmlXtraReportLayout);
report.LoadLayout(fileName);
System.IO.File.Delete(fileName);
}
}
public static string GetXmlXtraReportLayout(this DevExpress.XtraReports.UI.XtraReport report)
{
string tmpFileName = System.IO.Path.GetTempPath() + Guid.NewGuid().ToString() + ".repx";
report.SaveLayout(tmpFileName);
string xmlXtraReportLayout = System.IO.File.ReadAllText(tmpFileName);
System.IO.File.Delete(tmpFileName);
return xmlXtraReportLayout;
}
using Memory Stream ( but it dosn't works fine, some data are lost, but you can try it )
public static void RestoreLayoutFromNavigationItem(this DevExpress.XtraReports.UI.XtraReport report, string xmlXtraReportLayout)
{
if (!string.IsNullOrEmpty(xmlXtraReportLayout))
{
using (Stream xmlStream = new System.IO.MemoryStream())
{
XmlDocument xDoc = new XmlDocument();
xDoc.LoadXml(xmlXtraReportLayout);
xDoc.Save(xmlStream);
xmlStream.Flush();
xmlStream.Position = 0;
report.LoadLayoutFromXml(xmlStream);
}
}
}
and to load the report I use a web page that contains a ASPxDocumentViewer :
<body>
<form id="formDocumentViewer" runat="server">
<div>
<dx:ASPxDocumentViewer ID="mainDocumentViewer" runat="server">
</dx:ASPxDocumentViewer>
</div>
</form>
in the page Load:
protected void Page_Load(object sender, EventArgs e)
{
report.DataSource = "your data source";
string xmlXtraReportLayout = "load it from the saved file";
report.RestoreFromXmlXtraReportLayout(xmlXtraReportLayout);
this.mainDocumentViewer.SettingsSplitter.SidePaneVisible = false;
this.mainDocumentViewer.Report = report;
}
but first you have to create your report with the report designer , load it in win application , use GetXmlXtraReportLayout to save the layout into a file.
Upvotes: 1