.NET Tutorials, Forums, Interview Questions And Answers
Welcome :Guest
Sign In
Win Surprise Gifts!!!

Top 5 Contributors of the Month
david stephan
Gaurav Pal
Post New Web Links

Generating Word Document using C#

Posted By:      Posted Date: September 15, 2010    Points: 0   Category :ASP.Net
Hi all I am trying to generate word document from my web application  using C#. actually I did it and its working ... but not fine :( initially I have the original word document and I save it as xml then I create xslt file from the xml file, and in my code I will provide the xslt file with xml values (data set) and do transformation to generate the document file ... this is working but the problem is its taking around 7 minutes on my PC to generate the file (transformation) so is there any other way to generate the file? and if I use template and replace the bookmarks inside the templates with the proper values will give me better performance? P.S. my word document is large (2MB) and locked (only few fields are editable from the user)   any help on that will be highly appreciated   Thank Yaser

View Complete Post

More Related Resource Links

Charset Problem with dynamically generated Word Document


in my asp.net web application i am dynamically generating a word documnet out of a sql data. I have set the char set UTF-8 during the doument creation in code but still when i open the generated document and check it char set .. it is always windows-1252 not the one that i have set. My sql data in the document have special characters whihc can only be understandable using the UTF-8 charset otherwise its always ?T written in place of an apostrophy . Pasting my code here..

         HttpContext.Current.Response.ContentType = "application/msword";
         HttpContext.Current.Response.ContentEncoding = System.Text.UnicodeEncoding.UTF8;
         HttpContext.Current.Response.Charset = "utf-8";
         string strFileName = "Details" + ".doc";
        HttpContext.Current.Response.AddHeader("Content-Disposition", "inline;filename=" + strFileName);
        StringBuilder strHTMLContent = new StringBuilder();
        string strMessage = " ";
        DataView abstractview = (DataView)dsAbstract.Select(DataSourceSelectArguments.Empty);
        foreach (DataRowView row1 in abstractview)
            strMessage += "<table border='1' cellspacing='0' cellpadding='5' width

Embed word document inside excel



I am using ASP.NET and C# 2.0 and working on web application.

I want to embed a word document inside a excel sheet.

How to embed word document inside excel.

Thank you



Advanced Basics: Setting Word Document Properties the Office 2007 Way


The last time I wrote this column (March 2006), I shared an application that allows you to update all the Microsoft® Word documents in a folder and its subfolders. Each time the application finds a document in the specified path, it updates the document properties to match those you specified in the application.

Ken Getz

MSDN Magazine June 2006

Advanced Basics: Set Word Document Properties Programmatically


At the beginning of another lovely day of writing courseware in mad pursuit of unrealistic deadlines, I received a frantic call from a business partner. He was at the end of a long consulting project and had several hundred Microsoft® Word documents, all of which required their document properties to be set identically, except the Title property of the document, which was to be based on the document file name, minus the .

Ken Getz

MSDN Magazine March 2006

Full text search in a Word document



  I´m currently programming a web search application in ASP.Net and having problem with full text searching. My requirements are:

1. Save a byte array from SQL server to word document as a temp file in a server side?

2. How to highlight the string I am currently searching in the Word document and return to the user the sentence with the highlighted string (like on Bing or any other search engines)? Is it possible to fullfill this requirement with full-text search integrated in SQL Server 2008?

Thanks in advance,




Re-authentication issue when openeing a MS Word Document


We have a SharePoint installation for one of our clients with external access enabled using https via ISA server. When accessing the portal internally within the intranet/domain its fine. In case of external access using https when users login to portal adn when they try to open a MS Word (or any Office) document they are prompted to to enter their username and password again. It happens for every MS Office document. We are using MOSS 2007, Office 2007. I know that the promp for re-authentication is is due to the fact that office try to open a new session but is there any work around to overcome this.

Any help will be highly appreciated.



Search does not find text in Word document stored in document library on a Report Center site within



We have a document library on a site created off of the Report Center site template. We uploaded a Word 2007 document with the word zebra in the text. Using the search bar at the top of the page we selected This list: Our document library and searched for zebra. We received no results.

We tested the same thing on another site (site template Team site) within the same site collection and search worked fine.

Does the Report Center search function differently then the search functionality on the Team site?

Tamara Bredemus SharePoint Minion...working up to Maven

Replace text in a word document stored in a Document Library


Hi to all,

im tying to replace some text introduced in a word document stored in a document library.

Exactly i need a web part with a button that change a key in a word template <list> (for example) and replace <list> with a text in another list.


I think that it would works with the Microsoft.Office.Word.Interop; namespace but when i call the function :

wDoc = wordApp.Documents.Open(ref fileName, ref missing,
                                ref readOnly, ref missing, ref missing, ref missing,
                                ref missing, ref missing, ref missing, ref missing,
                                ref missing, ref isVisible, ref missing, ref missing,

merge word document



I recently created a team site on the SharePoint for projects management and our team will use the word document for inserting the information about the project that they work on it,

My case is:

for each project have multiple documents and i created a user control by VS.2005, this user control contain a drop down list contain all projects and merge button, when the user choose any project and click merge i will use the Work dll to merge all document that related to the project and export to the user.

This is my code

private void mergeDocument()


ApplicationClass WordApp =

Generating MS Word doc from mht file gives smart quote problem


I have a word document to be generated using ASP.Net/VB.net.

So I have a word document template saved as .mht file on the web server.

In my ASP.Net code,I read this mht file content and replace certain string line Description$$ with the actual description from the database.Then save this content as .doc file.

This works fine but shows a box symbol when I have smart quotes " (not this one as I cannot type it here.The double quote which you see in MS Word,the slanted double quote).

I dont know how to make my word doc generated, show the exact double quote as in MS word.

If any of you have any idea of this please reply.

Thank you

open Word document in iframe without open/ save dialouge

Hello All! In my application users upload their word document and user has been given an option to preivew the uploaded document. Inorder to  preview  the document  i put the following code in my page_load eventdiv1.InnerHtml = "<iframe name='iframe4' src='DocumentUuploaded/report.doc ' target='iframe4'  frameborder='no' height='500' scrolling='no' width='800'></iframe>";The problem is it is asking Do you want to open or save this file. How can i get rid of this dialouge box . Pls helpThanks in advance.

SQL Server 2008 installation fails There was an error generating the XML document. Error code 0x84B

My system config: window XP - SP3 4 GB RAM, I have VS2008 with SP1, VS2010 Ultimate installed First when I tried to install SQL 2008 R2 Dev edition I got an error saying vs2008 SP1 was not installed, infact I had the SP1 installed in my m/c.  I did reinstalled the SP1 and tried to install SQL again. while in the final installation process I got the error  "Setup has encountered the following error: There was an error generating the XML document. Error code 0x84B10001." I uninstall the SQL server again to remove the files which were created from Unsuccessful installation I removed the register entry as suggested by this forum. reinstalled but no chance, I have tried all the option which I can get know in web. Please help me. here is the log files details  Exception type: Microsoft.SqlServer.Chainer.Infrastructure.ChainerInfrastructureException 2010-08-26 14:54:53 Slp:     Message: 2010-08-26 14:54:53 Slp:         There was an error generating the XML document. 2010-08-26 14:54:53 Slp:     Stack: 2010-08-26 14:54:53 Slp:         at Microsoft.SqlServer.Chainer.Infrastructure.DataStoreService.SerializeObject(String rootPath, Object objectToSerialize, Boolean saveToCache) 2010-08-26 14:54:53 Slp:   &nb

Replace Text in textbox in word document using interop and asp.net

Hi all,  I'm trying to create a function to replace fields in a word document using asp.net. The fields are marked in the document using ###field### and I need to replace them with the data from the DB. The code I have works fine for the body of the word document but doesn't appear to work if the text is contained within a textbox, is there a way to correct this? Here's the code I am currently using Dim Contract as string Dim word As New Word.Application        Dim doc As Word.Document        Try            word.Documents.Open("c:\FYI.doc")            word.Visible = True             doc = word.ActiveDocument            Dim myStoryRange As Microsoft.Office.Interop.Word.Range            For Each myStoryRange In doc.StoryRanges                With myStoryRange.Find                    .Text = "###field###&quo

Display the content of a Word document in a web part?

Hello all,We are planning to display the content of the word document pulling document from document library in a web page in sharepoint as a web part.So, based on above requirement , I have to display word document in a container/control which allows word document to edit, read and save it back to document library.I know that if you have Office 2007 installed we can convert the word document to web page and display it in the page viewer web part but we have office 2003 suite. So we are looking for web part which can display the content of the word document inline with the web page.Thanks in advacne,Chakri

Is there a way to parse information in a word document and store them on a list (MOSS2007)? (Without

My current project requires me to parse through a Word document with tables that simulate a form. However Infopath isn't an available rescource for me. For example I'm to bring all information in the notes cell onto a list in sharepoint. Ultimately i'll be using a view to display that list through a webpart on a dashboard like interface on a sharepoint page. Is this possible? or is Info Path really the only way to go about this?

how to embedd a word document into web page

Hi All, I want to show a new word file opened in a panel/div/frame on web page. Can anybody help me in doing that. I have tried with Iframe but when page loads completely it opens as open save dialog but I want it to be opened on web page. Please help. 

Converting Word Documents library to PDF document library in SharePoint Server 2007

My project requires me to create an event reciever such that when a word file is added to one library the same content pdf file should be added to other library also when a word file is updated,edited or checked in the respective pdf file in other document library should be replaced by a new pdf file with the edited word content . Can we do this in Sharepoint 2007 I have seen this can be done in Sharepoint 2010 http://msdn.microsoft.com/en-us/library/ff181518.aspx
ASP.NetWindows Application  .NET Framework  C#  VB.Net  ADO.Net  
Sql Server  SharePoint  Silverlight  Others  All   

Hall of Fame    Twitter   Terms of Service    Privacy Policy    Contact Us    Archives   Tell A Friend