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