Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
private void Form1_Load(object sender, EventArgs e)
{
var rpt = new PageReport(new FileInfo("report.rdlx"));
var doc = new PageDocument(rpt);
var xml = new XmlRenderingExtension();
var settings = new Settings {Encoding = "UTF-8"};
var streamProvider = new CustomStreamProvider(new DirectoryInfo("."), "report.xml");
doc.Render(xml, streamProvider, settings);
}
class CustomStreamProvider : StreamProvider
{
private readonly DirectoryInfo _baseDir;
private readonly string _fileName;
private StreamInfo _primaryStream;
public CustomStreamProvider(DirectoryInfo baseDir, string fileName)
{
_baseDir = baseDir;
_fileName = fileName;
}
public override StreamInfo CreatePrimaryStream(string mimeType, string suggestedFileExtension)
{
_primaryStream = new CustomSreamInfo(new FileInfo(Path.Combine(_baseDir.FullName, _fileName)), mimeType);
return _primaryStream;
}
public override StreamInfo CreateSecondaryStream(string relativeName, string mimeType, string suggestedFileExtension)
{
throw new NotImplementedException();
}
public override StreamInfo GetPrimaryStream()
{
return _primaryStream;
}
public override StreamInfo[] GetSecondaryStreams()
{
throw new NotImplementedException();
}
}
class CustomSreamInfo : StreamInfo
{
private readonly FileInfo _file;
public CustomSreamInfo(FileInfo fileInfo, string mimeType) : base(new Uri(fileInfo.FullName), mimeType)
{
_file = fileInfo;
}
public override Stream OpenStream()
{
if(_file.Exists)
_file.Delete();
var stream = _file.Open(FileMode.OpenOrCreate, FileAccess.ReadWrite);
return stream;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.