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
Ameya Joshi
NA
26
2.4k
Unable to open doc file after editing in C#
Sep 28 2013 7:47 AM
I have written following Code to edit bookmarks of Word document., as document is generated doc is visible but if i close the same and tried to open the same doc again the word doc gives error as :
1.Check file permissions for file/ drive.
2.make sure there is sufficient memory and disk space.
private void GenerateApplication()
{
object readOnly = true;
object repair = false;
object bookMarkName = "applicantName";
object bookMarkCompany = "firmName";
object bookMarkPost = "postName";
fielName = @"C:\Documents and Settings\All Users\Desktop\OperateWordFromC#.dotx";
objDoc = wordApp.Documents.Open(ref fielName, ref missingValuesValues, ref readOnly, ref missingValuesValues, ref missingValuesValues,
ref missingValuesValues, ref missingValuesValues, ref missingValuesValues, ref missingValuesValues,
ref missingValuesValues, ref missingValuesValues, ref missingValuesValues, ref repair, ref missingValuesValues, ref missingValuesValues, ref missingValuesValues);
objDoc.Activate();
objDoc.Bookmarks.get_Item(ref bookMarkName).Range.Text = txtApplicantName.Text;
objDoc.Bookmarks.get_Item(ref bookMarkCompany).Range.Text = txtAppliedCompany.Text;
objDoc.Bookmarks.get_Item(ref bookMarkPost).Range.Text = txtAppliedPost.Text;
string outputFile = @"C:\Documents and Settings\All Users\Desktop\ApplicationOf-" + txtApplicantName.Text + ".docx";
bookMarkName = null;
bookMarkCompany = null;
bookMarkPost = null;
Object objSaveAsFile = outputFile;
Object objFileFormat = Microsoft.Office.Interop.Word.WdSaveFormat.wdFormatDocument;
wordApp.ActiveDocument.SaveAs(ref objSaveAsFile, ref repair, ref missingValuesValues, ref missingValuesValues, ref missingValuesValues,
ref missingValuesValues, ref missingValuesValues, ref missingValuesValues, ref missingValuesValues, ref missingValuesValues,
ref missingValuesValues, ref missingValuesValues, ref missingValuesValues, ref missingValuesValues, ref missingValuesValues, ref missingValuesValues);
wordApp.Visible = true;
}
Reply
Answers (
3
)
how beeing certified freely on Net in C# (no fees please)
Two chevron