C#问题,用户选择的文档合并为一个 [英] C# issue with user selected docs being merged into one
问题描述
目前通过'openFileInput'选择单个文件存在问题。想法是用户使用打开文件选择1-5个文档,然后根据用户输出文件夹选择将组合按钮合并到一个文档中。
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.
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目前有此工作,但我正在尝试启用此选项可以处理单个文件选择而不是文件夹选择。这个问题似乎在这里被标记出来了。
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,
selectedDocs = Directory.GetFiles(mixedFolder, "*.doc");
any欢迎提出意见或建议,谢谢
我的尝试:
将单个用户选择列表合并为一个路径以合并
any advice or suggestions are welcomed, thank you
What I have tried:
combining the list of individual user selections into one path for merging
推荐答案
我认为您的问题出在Path.Combine()
,这只返回一个路径,而不是你似乎期望多个路径。请参阅以下说明:
Path.Combine Method (String,String,String,String)(System.IO) [ ^ ]
I think your problem is in thePath.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)[^]
这篇关于C#问题,用户选择的文档合并为一个的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!