MS Word is a popular and widely used word processing software to create rich text documents. While working with Word documents, you may need to copy the content from one document to another. Moreover, the clones of Word documents are also required in certain cases. To perform these operations programmatically, this article covers how to copy the content from one Word document to another in C#. Also, you will learn how to create a copy of a Word document programmatically.
- C# Library to Copy Content of Word Documents
- Copy Content from One Word Document to Another
- Create Copy of a Word Document
C# Library to Copy Content of Word Documents
To copy the content from one Word document to another, we will use Aspose.Words for .NET. It is a feature-rich library to implement word processing features from within .NET applications. You can download the API’s DLL or install it directly from NuGet using the package manager console.
PM> Install-Package Aspose.Words
Copy Content from a Word Document to Another using C#
The following are the steps to copy the content of a Word document to another using C#.
- Load the source Word document using Document class.
- Similarly, load the destination document using Document class.
- Copy the content of source Word document into destination document using Document.AppendDocument(Document, ImportFormatMode) method.
- Save the destination document using Document.Save(string) method.
The following code sample shows how to copy the content of a Word document to another.
Create Copy of a Word Document in C#
You can also copy the content of a Word document into a new document. In other words, you can create clone of a document. The following steps show how to create a copy of the Word document using C#.
- Load the Word document using Document class.
- Create a clone using Document.Clone() method.
- Save the cloned document using Document.Save(string) method.
The following code sample shows how to create a copy of a Word DOCX file in C#.
Get a Free API License
You can get a temporary license in order to use Aspose.Words for .NET without evaluation limitations.
Conclusion
In this article, you have learned how to copy the content from a Word document to another in C#. Moreover, you have seen how to clone a Word document programmatically. Aspose.Words for .NET provides a wide range of other features that you can explore using the documentation. Also, you can ask your queries via our forum.