i am getting Sequence1.xaml: No compiled code to run
error CS1513: } expected At line 44
error CS1022: Type or namespace definition, or end-of-file expected At line 54
string templatePath =“C:\Users\Lenovo\Downloads\letter_template.docx”;
string outputPath =“D:\New folder.docx”;
// Create a Word application object
dynamic wordApp = null;
dynamic doc = null;
try
{
wordApp = new Microsoft.Office.Interop.Word.Application();
// Disable the visibility of the application
wordApp.Visible = false;
// Open the template document
doc = wordApp.Documents.Open(templatePath);
// Field names and values passed as arguments
string fieldName1 = args.my_phone;
string value1 = args.phone_no;
string fieldName2 = args.my_email;
string value2 = args.value2;
// Find and replace the fields in the document
ReplaceFieldWithValue(doc, fieldName1, value1);
ReplaceFieldWithValue(doc, fieldName2, value2);
// Save the document with a different name or path
doc.SaveAs2(outputPath);
}
finally
{
// Close and release the document
if (doc != null)
{
doc.Close();
wordApp = null; // Release the reference to the document
}
// Quit and release the Word application
if (wordApp != null)
{
wordApp.Quit();
wordApp =null;
}
}
// Helper method to replace a field with a value
void ReplaceFieldWithValue(dynamic document, string fieldName, string value)
{
dynamic range = document.Content;
range.Find.ClearFormatting();
range.Find.Execute(fieldName, false, false, false, false, false, true, 1, false, value, 2);
}