Click here to Skip to main content
15,915,734 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
currently having an issue with individual files being selected via an 'openFileInput'. The idea is that a user selects between 1-5 docs using the open-file, the combine button then merges these into one document depending on the user output folder selection.

C#
private string[] selectedDocs;
    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);
    }


i currently having this working if the user selects a folder containing a list of documents, however i'm trying to enable this to work with individual file selection as opposed to folder selection. The issue seems to be flagged up here,

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


any advice or suggestions are welcomed, thank you

What I have tried:

combining the list of individual user selections into one path for merging
Posted
Updated 19-Mar-16 8:50am
v2

1 solution

I think your problem is in the Path.Combine(), this returns only one path, and not as you seem to expect multiple paths. See the description at:
Path.Combine Method (String, String, String, String) (System.IO)[^]
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900