I currently have program that merges word. doc files together via user input. Once the user chooses an input folder and output destination, the documents are combined and the total number of files merged is displayed. here is an example of the code.
MessageBox.Show("A total of " + sourceFiles.Count() + " documents have been merged",
"Success", MessageBoxButtons.OK, MessageBoxIcon.Information);
The program and string.count work perfectly at the moment, however the issue I have is when I update the input folder's contents or choose to the output folder to be the same as in the input folder whilst the program is running
For Example: If I choose the input and output folders desired and run the program successfully, the user will eventually be greeted with a message box saying "a total of X documents have been merged" once the new file has been created.
If I drag an another file into the Input folder and immediately press the 'merge' button again, the "X documents merged" total will remain the same, even though an additional file has been inserted into that folder. The program will continue to make the combined files however the string.count total doesn't recognise the newly added documents. It's as if the program doesn't update folder's total contents
sourceFiles is declared as a
private string []
and is called when the user selects their desired folder using a folder browser dialog.
private void browseButton_Click(object sender, EventArgs e)
{
FolderBrowserDialog diagBrowser = new FolderBrowserDialog();
diagBrowser.Description = "Select a folder which contains files needing combined...";
string selectedFolder = "";
diagBrowser.SelectedPath = selectedFolder;
folderPath.Text = diagBrowser.SelectedPath;
if (DialogResult.OK == diagBrowser.ShowDialog())
{
selectedFolder = diagBrowser.SelectedPath;
folderPath.Text = diagBrowser.SelectedPath;
sourceFiles = Directory.GetFiles(selectedFolder, "*.doc");
}
The merge command is then called, combining the sourceFiles (total number of documents in the folder), the output file name which includes a date / time and page break between the files
MsWord.Merge(sourceFiles, outputFileName, pageBreaker);
Any suggestions to amend this issue? It is a small inconvenience however I would love to get it addressed
What I have tried:
Calling the sourceFiles when the user selects the merge button as opposed to when they select their input button