I created a report with some data in it. I do not want the user to click the export form button and export the data to a text document. The file saves well, the problem is when I open the document as a word, itβs just a bunch of garbage instead of the report that I had to save.
my save button looks like this:
SaveFileDialog saveFileDialog = new SaveFileDialog();
saveFileDialog.InitialDirectory = @"C:\";
saveFileDialog.RestoreDirectory = true;
savefileDialog.Title = "Browse Text Files";
saveFileDialog.DefaultExt = "docx";
saveFileDialog.Filter = "Word Doc (*.docx)|*.docx|PDF (*.pdf)| *.pdf";
saveFileDialog.checkFileExists = false;
saveFileDialog.CheckPathExists = true;
Warning[] warnings;
string[] streams;
string mimeType;
string encoding;
string extension;
byte[] bytes = reportViewer1.LocalReport.Render("Word", null, out mimeType, out encoding, out extension, out streams, out warnings);
if (saveFileDialog.ShowDialog() == DialogResult.OK)
{
var filename = saveFileDialog.FileName;
System.IO.FileStream file = new FileStream(filename, FileMode.Create);
file.Write(bytes, 0, bytes.length);
file.close();
}
Any suggestions?
source
share