Hi,
I need to load xml report to XmlDocument, modify and load this xml as a report. I'm loading xml file to XmlDocument and then saving it to memory stream. Then I'm loading report from memory stream. The problem is that report look different. There are some problems with page header and footer. Loading report directly from file works fine. In my opinion the problem is with XmlDocument. Maybe some encoding problems ? Any ideas ?
regards
I'm doing something similar, with pretty good results, but I've been using XElement.Parse to convert from text, and using
new
MemoryStream( Encoding.UTF8.GetBytes( report ) )
to get the memory stream to pass to
ServerExporterFactory
.CreateExporter
Hope this helps,
Mike
many thanks for the repply. I'm curious how are you loading xml report to xmldocument ? When I load xml using xDocument.load() and then save it to another file, using the second file with report.load() gives poor results. Some elements are missing....
As I said, I'm not using XmlDocument, I'm using the newer XElement class hierarchy. I load the report defintion from a file system into a string (template, below). Then I use code like the following to load and examine it:
.PreserveWhitespace );
igr = document.GetDefaultNamespace();
).FirstOrDefault();
Once I have finished with the document, I use the following code to finally generate the report.
string report = document.ToString();
using
( IServerExporter exporter = ServerExporterFactory.CreateExporter(
MemoryStream( Encoding.UTF8.GetBytes( report )
) )
{
exporter.DataSources = dataSourceValues;
using ( FileStream outStream = File.OpenWrite( filePath ) )
memoryStream.WriteTo( outStream );
}
exporter.Export( memoryStream, GetExportFormat( exportParameters.ExportFormat ) );
using ( MemoryStream memoryStream = new MemoryStream() )
Sorry about the formatting, but it's the forum software that wrecks it. The above code is somewhat simplified from what I'm actually doing (for clarity) but I hope it helps you.
There's a bunch of duplication in that post, and I can't seem to edit it. Sorry about the mess.
Hello Mike,
I have been following through this thread and was wondering if this is the code you intended of pasting:
“ XElement document = XElement.Parse( template, LoadOptions.PreserveWhitespace );
XNamespace igr = document.GetDefaultNamespace();
XElement pageSettings = document.Descendants(igr + "PageSettings").FirstOrDefault();
using (IServerExporter exporter = ServerExporterFactory.CreateExporter(new MemoryStream(Encoding.UTF8.GetBytes(report))))
using (MemoryStream memoryStream = new MemoryStream())
exporter.Export(memoryStream, GetExportFormat(exportParameters.ExportFormat));
using (FileStream outStream = File.OpenWrite(filePath))
memoryStream.WriteTo(outStream);
} ”
Please let me know if I can be of any further assistance.
Thanks Petar. That's what I intended to paste, but your forum software seems to have some issues. Almost every thread I look at has someone trying to paste some code, and it always looks terrible. Is someone ever going to fix that?
Thanks, Mike
I've solved problem in different way. I had to use LoadOptions.PreserveWhiteSpaces
regards,
Sebastian