` System.IO.File.Copy(wordFullPath, wordFullPathCopy, true);
using (WordprocessingDocument wordDoc = WordprocessingDocument.Open(wordFullPathCopy, true))
{
string docText = null;
using (StreamReader sr = new StreamReader(wordDoc.MainDocumentPart.GetStream()))
{
docText = sr.ReadToEnd();
docText = docText.Replace("[$1-1-1$]", "TEST1");
docText = docText.Replace("[$1-1-2$]", "TEST2");
using (StreamWriter sw = new StreamWriter(wordDoc.MainDocumentPart.GetStream(FileMode.Create)))
{
sw.Write(docText);
}
}
}
byte[] byteArray = File.ReadAllBytes(wordFullPathCopy);
System.IO.File.Delete(wordFullPathCopy);
Page.Response.Clear();
Page.Response.AppendHeader("Content-Disposition", "attachment; filename=DocxDllTest.docx");
Page.Response.ContentType = "application/octet-stream";
Page.Response.BinaryWrite(byteArray);
Page.Response.OutputStream.Flush();
Page.Response.OutputStream.Close();
Page.Response.Flush();
Page.Response.End();`
Hi~I have a docX template(Of course,It must read only!!). Now I make a copy and use WordprocessingDocument to replace text.
It worked fine.
But now,I want to not make a copy.
Just replace text and save to memorystream then Response to user.
Is it possible? and How??
Thx!!