Opening Word File from C# .net

0 views
Skip to first unread message

bcpdrp

unread,
Jul 14, 2005, 2:17:49 PM7/14/05
to DotNetDe...@googlegroups.com
I am trying to open the content of a WORD file from C#.NET which
resides in
the REMOTE SERVER, however I get an error:
"System.Runtime.InteropServices.COMException: Server execution failed"
when declaring new Word.ApplicationClass().
I am not able to open the instance of MS word only. Application just
fails.

string fileName = this.btnWorkOrder1.Value;
object readOnly = false;
object isVisible = false;
object saveChanges = false;
object missing = System.Reflection.Missing.Value;
object dynamic = 2;

//error here:
Word.ApplicationClass oWordApp = new Word.ApplicationClass();

Word.Document oWordDoc = oWordApp.Documents.Open(ref file, ref missing,
ref
readOnly, ref missing, ref missing, ref missing, ref missing, ref
missing,
ref missing,
ref missing, ref missing, ref isVisible);


Does anybody know how to solve it? Please help!!!

Thanks alot!!!

Majunu M

unread,
Aug 29, 2005, 10:06:34 AM8/29/05
to DotNetDe...@googlegroups.com
Hi,

Try this. This code is in vb .net


Response.CacheControl = "public"
Response.ContentType = "application/msword"
fileData = BinaryFileRead("c:\webapp2.chm")
Response.BinaryWrite(fileData)

Function BinaryFileRead(ByVal InpFileName) As Byte()

Dim fs As FileStream
Dim fi As FileInfo
fi = New FileInfo(InpFileName)
Dim arrData(fi.Length) As Byte

fs = New FileStream(InpFileName, FileMode.Open)
fs.Read(arrData, 0, arrData.Length)
fs.Close()

Return arrData

End Function


Regards,
Maj
Reply all
Reply to author
Forward
0 new messages