Good morning I'm using the algorithm I show below, which gets me some values and injects them into a Word letter and causes a new document to be generated, then that document is saved in a route that I defined and the code I stay in the following way: (I would like to be able to make the user define where he wants to save the document that is generated, something like a save As). Thank you very much
document.SaveAs2(FileName: @"C:\Users\jtaboga\Desktop\" + CEDULA + ".docx");
document.Close();
application.Quit();
public static void GenerarCartaPreAdjudicacionPevi(DataTable[] datosCapturados)
{
int cantSelReg = datosCapturados.Length -1 ; //Cuenta la cantidad de registros que hay seleccionados
int cantMinReg = 0; //Contador para poder recorrer los registros seleccionados
while (cantMinReg <= cantSelReg)
{
foreach (DataRow Registro in datosCapturados[cantMinReg].Rows)
{
//prueba[0].Rows.Add(fila["VLR_SOL"]);
string NOMEPL = (Registro["NOM_EPL"].ToString());
string APEEPL = (Registro["APE_EPL"].ToString());
string VLRAPR = (Registro["VLR_APR"].ToString());
string CEDULA = (Registro["CEDULA"].ToString());
string NOMPRO = (Registro["NOM_PRO"].ToString());
var application = new Microsoft.Office.Interop.Word.Application();
var document = new Microsoft.Office.Interop.Word.Document();
document = application.Documents.Add(Template: @"D:\Proyectos\chc_deuda\resources\Document\cartaPreadj.docx");
application.Visible = false;
foreach (Microsoft.Office.Interop.Word.Field field in document.Fields)
{
if (field.Code.Text.Contains("NOMEPL"))
{
field.Select();
application.Selection.TypeText(NOMEPL);
}
else if (field.Code.Text.Contains("APEEPL"))
{
field.Select();
application.Selection.TypeText(APEEPL);
}
else if (field.Code.Text.Contains("VLRAPR"))
{
field.Select();
application.Selection.TypeText(VLRAPR);
}
else if (field.Code.Text.Contains("NOMPRO"))
{
field.Select();
application.Selection.TypeText(NOMPRO);
}
}
document.SaveAs2(FileName: @"C:\Users\jtaboga\Desktop\" + CEDULA + ".docx");
document.Close();
application.Quit();
}
cantMinReg++;
}
}