Click here to Skip to main content
15,893,487 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I want to create a word document on a LinkButton click in a webpage.

I have a default word document located inside the web directory,when i click on the Link button, the respective word document must open.

i also want to replace some fields according to database values,ie of no significance here.

The code i used for the above is :

public void CreateWord(object fileName, string Invoice_No, string Purchaser, string Supplier, string Address, string Pincode, string City, string Country, string Invoice_Date, string Remark)
    {
        try
        {
            object missing = System.Reflection.Missing.Value;
            Word.Application wordApp = new Word.ApplicationClass();
            Word.Document aDoc = null;
            if (System.IO.File.Exists((string)fileName))
            {
                DateTime today = DateTime.Now;
                object readOnly = false;
                object isVisible = false;
                wordApp.Visible = true;
                aDoc = wordApp.Documents.Open(ref fileName,
                        ref readOnly, ref missing, ref missing, ref missing,
                        ref missing, ref missing, ref missing, ref missing,
                        ref missing, ref missing, ref missing, ref missing,
                        ref missing, ref missing, ref missing);
                this.FindAndReplace(wordApp, "Purchaser", Purchaser);
                this.FindAndReplace(wordApp, "Number", Invoice_No);
                this.FindAndReplace(wordApp, "{Supplier name}", Supplier);
                this.FindAndReplace(wordApp, "{Street & number}", Address);
                this.FindAndReplace(wordApp, "{Postal code}", Pincode);
                this.FindAndReplace(wordApp, "{location}", City);
                this.FindAndReplace(wordApp, "(invoice date)", Invoice_Date);
                this.FindAndReplace(wordApp, "(Copy field DIA)", Remark);
                this.FindAndReplace(wordApp, "Purchaser Name", Purchaser);
            }
            else
            {
                return;
            }
        }
        catch (Exception ex)
        {
            lblError.Text = ex.Message;
        }
    }
    public void FindAndReplace(Word.Application WordApp, object findText, object replaceWithText)
    {
        object matchCase = true;
        object matchWholeWord = true;
        object matchWildCards = false;
        object matchSoundsLike = false;
        object forward = true;
        object matchAllWordForms = false;
        object format = false;
        object matchKashida = false;
        object matchDiascritics = false;
        object matchAlefhamza = false;
        object matchControl = false;
        object read_only = false;
        object visible = true;
        object replace = 2;
        object wrap = 1;
        WordApp.Selection.Find.Execute(ref findText, ref matchCase, ref matchWholeWord, ref matchWildCards, ref matchSoundsLike, ref matchAllWordForms, ref forward, ref wrap, ref format, ref replaceWithText, ref replace, ref matchKashida, ref matchDiascritics, ref matchAlefhamza, ref matchControl);
    }



in my local system,its working fine for me.
but when uploading to server(Windows server 2008 having MS office 2000 installed),its shows error,ie

Retrieving the COM class factory for component with CLSID {000209FF-0000-0000-C000-000000000046} failed due to the following error: 80070005



I googled for this error,got many solutions that didnt helpd me yet.




Please help me to find a solution
Posted

1 solution

Did you set DCOM configuration?

http://social.msdn.microsoft.com/Forums/en/netfxbcl/thread/aeea74db-ff7d-4d99-9b9f-69354abf38db[^]

I first opened DCOMCNFG from the command prompt, opened Component Services, expanded Computers/My Computer/DCOM Config. Then I Selected Microsoft Word Application, and in the resulting dialog selected Security tab. Under Security Tab I changed Launch and Activation Permissions to customize, Access Permissions to customize and configuration Permissions to customize. And in the all the three I selected the ASPNET account.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900