Open Word document and write another place.

Posted by Selvarajmgp under C# on 1/8/2012 | Points: 10 | Views : 2598 | Status : [Member] | Replies : 2
Hi,


How to Open Word[doc] File and write another place as word [doc] File..

While read word file i can get only some different format content so i do not write another word file properly.
Thanks and Regards,

Selvaraju.n




Responses

Posted by: Blessyjees on: 1/8/2012 [Member] Bronze | Points: 25

Up
0
Down
Hi,

Please provide your code.

Blessy Baby
Digitalmesh Softech pvt Ltd
https://blessybaby.wordpress.com/

Selvarajmgp, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Selvarajmgp on: 1/11/2012 [Member] Starter | Points: 25

Up
0
Down
Hi Blessyjees,



I have to convert Rtf format to doc . i am using following code its work fine in local system.

when i run this code in iis 7 still getting error as


System.Runtime.InteropServices.COMException (0x800A1066): Command failed

at Microsoft.Office.Interop.Word.Documents.Open(Object& FileName, Object& ConfirmConversions, Object& ReadOnly, Object& AddToRecentFiles, Object& PasswordDocument, Object& PasswordTemplate, Object& Revert, Object& WritePasswordDocument, Object& WritePasswordTemplate, Object& Format, Object& Encoding, Object& Visible, Object& OpenAndRepair, Object& DocumentDirection, Object& NoEncodingDialog, Object& XMLTransform)
at ServiceHost.Service1.ConvertToWordFormat(String FilePath) in F:\ServiceHost\Service1.svc.cs:line 151


my coding:

try
{
Microsoft.Office.Interop.Word.ApplicationClass objWord = new Microsoft.Office.Interop.Word.ApplicationClass();
object fltDocFormat = 8;//object fltDocFormat = 10;
object missing = System.Reflection.Missing.Value;
object readOnly = false;
object isVisible = false;
object FileName = FilePath;

string strFile = System.IO.Path.GetFileName(FilePath);
object FileToSave = System.AppDomain.CurrentDomain.BaseDirectory.ToString() + strFile;

object SaveFormat = Microsoft.Office.Interop.Word.WdSaveFormat.wdFormatDocument;
//Word.WdSaveFormat.wdFormatDocument
//FileName = @"E:\CT Share\sRaju\SampleFourLimited.doc";

objWord.Documents.Open(ref FileName, ref readOnly, ref missing, ref missing, ref missing, ref missing,
ref missing, ref missing, ref missing, ref missing, ref isVisible, ref missing, ref missing, ref missing,
ref missing, ref missing);

objWord.Visible = false;
Microsoft.Office.Interop.Word.Document oDoc = objWord.ActiveDocument;
//oDoc.SaveAs(ref FileToSave, ref fltDocFormat, 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);
oDoc.SaveAs(ref FileToSave, ref SaveFormat, 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);
object Fal = false;
oDoc.Close(ref Fal, ref missing, ref missing);
objWord.Quit(ref missing, ref missing, ref missing);

System.IO.File.Copy(Convert.ToString(FileToSave), FilePath, true);
System.IO.File.Delete(Convert.ToString(FileToSave));

return "true";
}
catch (Exception WordEx)
{
LogFile(WordEx.ToString());
return WordEx.ToString(); //WordEx.Message.ToString();
}

Advance Thanks,

Selvaraju.n


Selvarajmgp, if this helps please login to Mark As Answer. | Alert Moderator

Login to post response