TECHNOLOGIES
FORUMS
JOBS
BOOKS
EVENTS
INTERVIEWS
Live
MORE
LEARN
Training
CAREER
MEMBERS
VIDEOS
NEWS
BLOGS
Sign Up
Login
No unread comment.
View All Comments
No unread message.
View All Messages
No unread notification.
View All Notifications
Answers
Post
An Article
A Blog
A News
A Video
An EBook
An Interview Question
Ask Question
Forums
Monthly Leaders
Forum guidelines
a_k93
NA
10
0
word automation one more time
Sep 21 2010 10:09 AM
Hi there,
document.saveAs function raises an error below is my code list. Any assistance will be appreciated.
using framework 2.0 with MS word 2003.
//
System.Runtime.InteropServices.COMException (0x80010105): The server threw an exception. (Exception from HRESULT: 0x80010105 (RPC_E_SERVERFAULT))
//
Object oMissing = System.Reflection.Missing.Value;
Object oTrue = true;
Object oFalse = false;
Word.Application oWord = new Word.Application();
Word.Document oWordDoc = new Word.Document();
oWord.Visible = true;
Object oTemplatePath = "C:\\testTemplate\\mytest2.dot";
oWordDoc = oWord.Documents.Add(ref oTemplatePath, ref oMissing, ref oMissing, ref oMissing);
foreach (Word.Field myfld in oWordDoc.Fields)
{
Word.Range rngFieldCode = myfld.Code;
string fieldText = rngFieldCode.Text;
if (fieldText.StartsWith(" MERGEFIELD"))
{
Int32 endMerge = fieldText.IndexOf("\\");
Int32 fieldNameLength = fieldText.Length - endMerge;
String fieldName = fieldText.Substring(11, endMerge - 11);
fieldName = fieldName.Trim();
if (fieldName == "abc")
{
myfld.Select();
oWord.Selection.TypeText(dr.Cells["abc"].Value.ToString());
}
if (fieldName == "pqr")
{
myfld.Select();
oWord.Selection.TypeText(dr.Cells["pqr"].Value.ToString());
}
}
}
string fl = "C:\\testTemplate\\" + ".doc";
Object oSaveAsFile = (Object)fl;
//RAISES AN ERROR IN BELOW LINE
oWordDoc.SaveAs(ref oSaveAsFile, ref oMissing, ref oMissing, ref oMissing,
ref oMissing, ref oMissing, ref oMissing, ref oMissing, ref oMissing,
ref oMissing, ref oMissing, ref oMissing, ref oMissing, ref oMissing,
ref oMissing, ref oMissing);
oWordDoc.Close(ref oFalse, ref oMissing, ref oMissing);
oWord.Quit(ref oMissing, ref oMissing, ref oMissing);
Thnx in advance
a_k93
Reply
Answers (
0
)
How to build class library with cetain file extension
Com Callable .NET Assembly