Here's what you'll need to do:
- Have Visual Studio and Office installed.
- Create a C# console project using the .NET framework of your choice (recommend 4.0 or above).
- Add a reference to the Word COM library (Project menu => Add Reference, COM tab, Microsoft Word XX.0 Object library -- Word 2010 is 14.0).
- Set the Embed Interop Types setting to false for the references added above
- Expand References in Solution Explorer
- Select Microsoft.Office.Core, Microsoft.Office.Interop.Word and VBIDE
- Right-click and select Properties to bring up the Properties panel for the references.
- In the Properties panel, set Embed Interop Types to False
- Code away.
Here's some sample code.
using System;
using Microsoft.Office.Interop.Word;
namespace CSharpConsole
{
static class Program
{
[STAThread]
static void Main()
{
var application = new ApplicationClass();
var document = application.Documents.Add();
document.SaveAs("D:\test.docx");
application.Quit();
}
}
}
For more information, see http://msdn.microsoft.com/en-us/library/office/ff601860(v=office.14).aspx