affi affi -4 years ago 81
C# Question

I'm creating docx file in c# using Docx library. when i click create button its not overwrite the document. it repeated display. how i can do that

enter image description

DocX document = DocX.Load(@"F:\BIIT\Project\LetterTemplate\sample.docx");

//Insert a Text into the document.

Paragraph p3 = document.InsertParagraph();
p3.Append("to introduce ").Italic().Font(new FontFamily("Times New Roman"));
p3.Append(txtname.Text);
p3.Append(" S/o ").Italic();
p3.Append(txtfathername.Text);
p3.Append("of our institute was enrolled in");
p3.Append(txtprog.Text);
p3.Append("program under University registration No. ");
p3.Append(txtaridNo.Text);
p3.Append("during academics session ");
p3.Append(txtsession.Text);
p3.AppendLine();
p3.AppendLine();
p3.AppendLine("In this connection I would request you to provide him the opportunity to acquire practical knowledge and would appreciate your willingness to accept him as");
p3.Append("internee").Bold();
p3.AppendLine("in your esteemed organization");

p3.AppendLine();

document.Save();


OUTPUT

to introduce - our institute was enrolled in(BSCS)program under University registration academics session 2013-2017

In this connection I would request you to provide him the opportunity to acquire practical knowledge and would appreciate your willingness to accept him asinternee
in your esteemed organization

to introduce S/o our institute was enrolled in(BSCS)program under University registration No. academics session

In this connection I would request you to provide him the opportunity to acquire practical knowledge and would appreciate your willingness to accept him asinternee
in your esteemed organization

Answer Source

As I looked in the code, you can't make that if you use Load and Save, because you are opening the document and append text.

So you have the option to create a new document, and append the text, or also you can use SaveAs as saving method, and make a differente filename for each document you create.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download