Remove sentence from word doc using c#

Hi All,
Advance thanks
Am using c#, mvc
Have created a file using spire.doc. The problem is it creates with the text "Evaluation Warning: The document was created with Spire.Doc for .NET." always. I need to remove the text and save the file with it's original name and extension. Please help..

Kind regards,
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Shaun VermaakTechnical Specialist/DeveloperCommented:
You need to buy a license for that. Do you have one?

Alternatively, you can use the limited free one
Chinmay PatelChief Technical NinjaCommented:
Hi Pooja,

With reference to your earlier question(and accepted answer) editing a word document is not replacing a string inside a file as modern office document i.e. DOCX/XSLX/PPTX and so on are nothing but Zip files having multiple child files. So if you replace a text inside a zip files by simple string swap you will end up corrupting the entire document.

Now, coming to your query, ideally you should use OpenXML SDK: It is the ultimate solution if you are willing to take some pain in learning its APIs. OpenXML SDK is completely free and you can use it in Server side document generation as well.

1.Create a copy of the template and open it for editing
2.Change the document type to WordProcessingDocumentType.Document
3.Create an AttachedTemplate object
4.Append the AttachedTemplateobject to the DocumentSettingsPart.Settings.
5.Add an External Relationship of type AttachedTemplate to the DocumentSettingsPart.Settings.
6.Save the document.

You can get the SDK from here:

Sample code:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using DocumentFormat.OpenXml.Wordprocessing;
using DocumentFormat.OpenXml.Packaging;
using System.IO;

    class Program
        static void Main(string[] args)
            string destinationFile = Path.Combine(Environment.CurrentDirectory, "SampleDocument.docx");
            string sourceFile = Path.Combine(Environment.CurrentDirectory, "Sample.dotx");
                // Create a copy of the template file and open the copy
                File.Copy(sourceFile, destinationFile, true);
                using (WordprocessingDocument document = WordprocessingDocument.Open(destinationFile, true))
                    // Change the document type to Document

                    // Get the MainPart of the document
                    MainDocumentPart mainPart = document.MainDocumentPart;

                    // Get the Document Settings Part
                    DocumentSettingsPart documentSettingPart1 = mainPart.DocumentSettingsPart;

                    // Create a new attachedTemplate and specify a relationship ID
                    AttachedTemplate attachedTemplate1 = new AttachedTemplate() { Id = "relationId1" };

                    // Append the attached template to the DocumentSettingsPart

                    // Add an ExternalRelationShip of type AttachedTemplate.
                    // Specify the path of template and the relationship ID
                    documentSettingPart1.AddExternalRelationship("", new Uri(sourceFile, UriKind.Absolute), "relationId1");

                    // Save the document
                   Console.WriteLine("Document generated at " + destinationFile);
            catch (Exception ex)
                Console.WriteLine("\nPress Enter to continue…");

Open in new window

Reference Article:

Let me know if you have any questions/concerns.


Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
poojasureshkumarAuthor Commented:
Chinmay PatelChief Technical NinjaCommented:
One more request, you should first try the code/example and if it works then and only you should accept the solution. I hope you already tried/tested the code I have posted. Please do let me know if you face any challenge.
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
.NET Programming

From novice to tech pro — start learning today.