CODE:
public void Print(string docLoc, string docSource)
{
try
{
Word.Application oWord = new Word.Application();
Word.Document oWrdDoc = new Word.Document();
oWord.Visible = true;
Object oTemplatePath = "C:\\Users\NAME\\Desktop\\B-AIAddChgDual10-06-NEW.doc";
oWrdDoc = oWord.Documents.Open(oTemplatePath);
Object oMissing = System.Reflection.Missing.Value;
oWrdDoc.MailMerge.OpenDataSource("C:\\Users\\NAME\\Desktop\\Test2.txt", oMissing, oMissing, oMissing,
oMissing, oMissing, oMissing, oMissing, oMissing, oMissing, oMissing, oMissing, oMissing, oMissing, oMissing, oMissing);
oWrdDoc.MailMerge.Execute();
}
catch (Exception ex)
{
MessageBox.Show("Source:\t" + ex.Source + "\nMessage: \t" + ex.Message + "\nData:\t" + ex.Data);
}
finally
{
//
}
}
When I process the above my Application Instance opens saying I'm locked out of the file because I myself am using it??? After I accept to open a Read-Only copy, I receive the following (in order):
After selecting how to replace the fields in the above:
Original Mail Merge Fields:
After Personal Selections:
How do I tell the Word Application to use the '!' character as the Field Delimiter in my C# code?
Also, how do I proceed with the dialogs? I'm assuming I receive each one due to my datasource not containing fields matching those listed as Mail Merge Fields?
Here are my Mail Merge Fields:
-fuldate -sys -memno -name -address1 -address2 -address3 -sal
And here are my Delimited fields from my .txt DataSource file:
memno!name!addr1!addr2!city!state!zip!old_addr1!old_addr2!old_city!old_state!old_zip