Last post Jan 31, 2015 01:41 PM by Boris Pavlovic
Dec 24, 2014 12:49 PM|saeed3164|LINK
iam try with asp.net write to template file word but dont write in file. public void createdoc1()
var oWordApplication = new Application();
object missing = System.Reflection.Missing.Value;
//object fileName = ConfigurationManager.AppSettings["DocxPath"];@"C:\DocXExample.docx";
string fileName = @"D:\120\template1.dot";
object newTemplate = false;
object docType = 0;
object isVisible = true;
var oWordDoc = oWordApplication.Documents.Open(fileName, newTemplate, docType, isVisible,ref missing);
oWordApplication.ActiveWindow.View.ReadingLayout = false;
oWordDoc.Bookmarks["Title"].Range.Text = "Test Field Entry from webform";
oWordDoc.Bookmarks["Address"].Range.Text = "Address Field Entry from webform";
Dec 29, 2014 06:36 AM|Ken Tucker|LINK
I would not automate word from a web site because the instance of word running will be on the server the website is running under not the computer the person who is viewing the website. I would use something like npoi to create a word document
Or the open xml sdk
Jan 31, 2015 01:41 PM|Boris Pavlovic|LINK
Word automation on any kind of server will cause troubles sooner or later, and Microsoft in its KB 257757 (http://support.microsoft.com/kb/257757) advises not to use it.
What you need is OpenXML based solution. Now to start OpenXML from scratch is something you would want to do only if you have plenty of time and don't mind struggling with tons of specifications and trial and error approaches as you will have hard times
finding suitable answers to your questions.
In my opinion, going with some 3rd party tool that has OpenXML support is the only viable solution: Aspose and Windward are two of the most known. I have experience with Docentric Toolkit, which is really simple to use, though you will need a developer license.
But it does not require any run-time server license.
To integrate Word document generation into ASP.NET you would follow these steps:
Below is a sample code which reads customers from France from Northwind database and merges them twith the Word template document to generate new Word document:
static void Main(string args)
List<Customer> custList = new List<Customer>();
using (var ctx = new NorthwindEntities1())
custList = ctx.Customers.Where(q => q.Country == "France").ToList();
string templateName = @"c:\temp\Customers.docx";
string generatedDocument = @"c:\temp\Customers_result.docx";
DocumentGenerator dg = new DocumentGenerator(custList);
DocumentGenerationResult result = dg.GenerateDocument(templateName, generatedDocument);
catch (Exception ex)
// wait for the input to terminate the application
Console.WriteLine("Press Enter to exit...");
As you can see the code is super simple. The result is a plain Word document (docx). You don't need Office installed on a server and document generation is very fast.