2016-03-19 3 views
0

, в настоящее время проблема с отдельными файлами выбирается через «openFileInput». Идея состоит в том, что пользователь выбирает между 1-5 документами с использованием открытого файла, а затем объединяет их в один документ в зависимости от выбора выходной папки пользователя.выпуск с выбранными пользователями документами, которые объединяются в один

private string[] selectedDocs; 

    // input file 1 
    string selectedFile1 = @""; 
    private void browseFileButton1_Click(object sender, EventArgs e) 
    { 
     OpenFileDialog openFileInput1 = new OpenFileDialog(); 
     openFileInput1.Filter = "Word Documents|*.docx;*.doc"; 
     openFileInput1.Title = "Select a Word Document"; 

     // Default file, altered when the user selects file of choice 
     openFileInput1.FileName = selectedFile1; 

     // initial file path display 
     filePath1.Text = openFileInput1.FileName; 

     // 'OK' button being confirmed on the popup menu 
     if (openFileInput1.ShowDialog() == DialogResult.OK) 
     { 
      selectedFile1 = openFileInput1.FileName; 
      filePath1.Text = openFileInput1.FileName; 
     } 
    } 

    // ** INPUT FILE PROCESS AS SHOWN ABOVE REPEATED 4 MORE TIMES 
    // this allows user to insert 4 more files ** 


    // Output Destination - for separate files 
    private string outputFolder2 = @""; 
    private void browseButtonOut2_Click(object sender, EventArgs e) 
    { 
     FolderBrowserDialog diagBrowserOutput2 = new FolderBrowserDialog(); 
     diagBrowserOutput2.Description = "Select a folder location to save the document..."; 

     // Default folder, altered when the user selects folder of choice 
     diagBrowserOutput2.SelectedPath = outputFolder2; 

     // output file path display 
     outputPath2.Text = diagBrowserOutput2.SelectedPath; 

     if (DialogResult.OK == diagBrowserOutput2.ShowDialog()) 
     { 
      outputFolder2 = diagBrowserOutput2.SelectedPath; 
      outputPath2.Text = diagBrowserOutput2.SelectedPath; 
     } 
    } 

    // combine files in folder selected using MsWord.cs, 
    private void combineButton2_Click(object sender, EventArgs e) 
    { 
     string mixedFolder = Path.Combine(selectedFile1, selectedFile2, selectedFile3, selectedFile4, selectedFile5); 
     selectedDocs = Directory.GetFiles(mixedFolder, "*.doc"); 
     string outcomeFolder2 = outputFolder2; 
     string outputFile2 = "Combined-files.docx"; 
     string outputFileName2 = Path.Combine(outcomeFolder2, outputFile2); 

     MsWord.Merge(selectedDocs, outputFileName2, true); 
    } 

я в настоящее время имея эту работу, если пользователь выбирает папку, содержащую перечень документов, однако я пытаюсь включить эту работу с индивидуальным выбором файла, в отличии от папки выбора. Проблема, кажется, попадает сюда,

selectedDocs = Directory.GetFiles(mixedFolder, "*.doc");

Любые советы или предложения приветствуются - спасибо.

ответ

0

После некоторых экспериментов я, наконец, получил программу для работы.

private void combineButton2_Click(object sender, EventArgs e) 
    { 
     selectedDocs = new[] 
     { 
      selectedFile1, 
      selectedFile2, 
      selectedFile3, 
      selectedFile4, 
      selectedFile5 
     }; 
     string outcomeFolder2 = outputFolder2; 
     string outputFile2 = "Combined-files.docx"; 
     string outputFileName2 = Path.Combine(outcomeFolder2, outputFile2); 

     MsWord.Merge(selectedDocs, outputFileName2, true); 
    } 

вместо объединения файлов с помощью Path.Combine, вместо того, чтобы я создал массив с результатами файлами, выбранный пользователем, а затем объединить их с помощью MsWord.cs

Смежные вопросы