How can I directly export a Word document to the report viewer

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?

+5
source share
3 answers

LocalReport.Render for Word Word ( 6, ). , XML ( docx) . , docx, Word , , . , docx Word .zip, . , .

+3

, (), , "WORDOPENXML" "Word" Render. , docx.

ListRenderingExtensions, , .

+10

, , :

saveFileDialog.Filter = "Word Doc (*.docx)|*.docx|PDF (*.pdf)| *.pdf"; 

to

saveFileDialog.Filter = "Word Doc (*.doc)|*.doc|PDF (*.pdf)| *.pdf"; 

. - .docx .

+1
source

All Articles