oreilly.comSafari Books Online.Conferences.


AddThis Social Bookmark Button

Programming Word from .NET
Pages: 1, 2, 3, 4, 5, 6, 7

Saving the File

Once the bookmarks are written, you want to save the file to a new name, so as not to overwrite the original. We'll name the new file using the patient's name:

object  newFileName = @"C:\Temp\" + patientName + ".doc";

Once again we must create all the arguments for the SaveAs method, and then pass them all by reference:

object  newFileName = @"C:\Temp\" + patientName + ".doc";
object  fileFormat = Type.Missing;
object  lockComments = Type.Missing;
object  WritePW = Type.Missing;
object  readOnlyRecommended = Type.Missing;
object  embedTrueTypeFonts = Type.Missing;
object  saveNativePictuormat = Type.Missing;
object  saveFormsData = Type.Missing;
object  saveAsAOCELetter = Type.Missing;
object  insertLineBreaks = Type.Missing;
object  allowSubstittions = Type.Missing;
object  lineEnding = Type.Missing;
object  AddBiDiMarks = Type.Missing;
object refWritePW = Type.Missing;
object saveNativePictureFormat = Type.Missing;
doc.SaveAs(ref newFileName , ref fileFormat, ref lockComments, ref passwordDoc,
    ref addToRecentFiles, ref WritePW, ref readOnlyRecommended, ref embedTrueTypeFonts,
    ref saveNativePictureFormat, ref saveFormsData, ref saveAsAOCELetter, ref encoding,
    ref insertLineBreaks, ref allowSubstittions, ref lineEnding, ref AddBiDiMarks);

Finally, we'll quit the application so as not to leave Word hanging in memory:

object saveChanges = Type.Missing;
object originalFormat = Type.Missing;
object routeDocument = Type.Missing;
wordApp.Quit(ref saveChanges, ref originalFormat, ref routeDocument);

We restore the cursor to the default cursor, and close the dialog box, and if we then open Windows Explorer, we'll find a new file in C:\Temp, as shown in Figure 10.

new letter
Figure 10. New letter in Explorer

Double-clicking on the new letter (Marvin Davis.doc) shows that the boilerplate has been personalized based on the information gathered at the current visit, as well as the information already on record for this patient (e.g., existing medications), as shown in Figure 11.

revised letter
Figure 11. Revised letter

I've added yellow to indicate where data was inserted based on the current visit, and green to indicate data extracted from the database.

Pages: 1, 2, 3, 4, 5, 6, 7

Next Pagearrow