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
How to Copy Content of a Word Document to Another
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. The good thing is, you can copy content from a Word document into another absolutely free. 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 in 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.
Clone 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#.
Free Java DOCX Library
You can get a free temporary license to use Aspose’ Java DOCX library 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.