Link line from the txt file to the one selected in my chelistbox

0

My code brings the content of a txt file inside a checklistbox. Each line of this file (it's also a line in my checklistbox) is the contents of a variable that I'll swap in a Word document. I need that when selecting in my checklistbox the (name of the collaborator) he brings me from within the txt file only the line of the collaborator that I selected for me to store in my variable that will give replace in Word. Here is the code where I read all the rows and assign my strings I need to manipulate the contents of them to bring only the 'selected'.

FillReplace c = new FillReplace ();

                string filePath = @"C:\Teste\Lista_col.txt";
                string line;
                string[] array  = File.ReadAllLines(@"C:\Teste\Lista_col.txt");

                if (File.Exists(filePath))
                {
                    using (StreamReader reader = new StreamReader(filePath))

                    {
                        while ((line = reader.ReadLine()) != null)
                        {
                            string[] auxiliar = line.Split(';'); // faço um split separando onde possui barras e virgulas

                            c.codigo = auxiliar[0];
                            c.nome = auxiliar[1];
                            c.funcao = auxiliar[2];
                            c.setor = auxiliar[3];
    
asked by anonymous 25.10.2017 / 20:30

1 answer

0

For this, I use a function:

public static void ImprimirArquivoWord(string arquivo, bool preview)
{
    Microsoft.Office.Interop.Word.Application wordApp = new Microsoft.Office.Interop.Word.Application();
    Microsoft.Office.Interop.Word.Document aDoc = wordApp.Documents.Open(arquivo, ReadOnly: true, Visible: preview);

    if (preview)
    {
        wordApp.Visible = true;
        aDoc.Activate();
        aDoc.PrintPreview();
    }
    else
    {
        aDoc.PrintOut();
        ((Microsoft.Office.Interop.Word._Application)wordApp).Quit(true);
    }
}
  

The reference was used for: Microsoft Word 12.0 Object Library and Microsoft Office 12.0 Object Library

Putting it in context:

foreach (FileInfo Arqui in ck_arquivos.CheckedItems)
{
    ImprimirArquivoWord(Arqui.FullName,false);
}
    
25.10.2017 / 20:58