두 개의 다른 버튼을 사용하고 싶습니다. 하나의 버튼은 사용자가 특정 파일을 선택하기 위해 openfiledialog를 열 때 생성 버튼을 클릭하여 선택된 파일을 사용하여 모든 내용을 배열에 추가 할 수 있습니다.openfiledialog에서 포함 파일의 배열로 파일 경로를 읽는 방법
private void btnChoose_Click(object sender, EventArgs e)
{
OpenFileDialog openFileDialog = new OpenFileDialog();
openFileDialog1.Filter = "Text Files (.txt)|*.txt";
openFileDialog1.FilterIndex = 1;
openFileDialog1.Multiselect = true;
if (openFileDialog.ShowDialog() == DialogResult.OK)
{
string sFileName = openFileDialog.FileName;
string[] arrAllFiles = openFileDialog.FileNames;
txtScriptfile.Text = arrAllFiles[0];
}
}
그리고 여기에 내가 모든 읽기에 파일 경로를 사용하려면 :
어떻게 그 파일 경로가 난 파일 열기 대화 상자에이 코드를 가지고있는 System.IO.ReadAllLines(filepath)
에서 일을받을 수 있나요 라인 :
private void btnGenerate_Click(object sender, EventArgs e)
{
string sThirdID = "";
string sSiteName = "";
string sFile = "";
FilePathScript = "@\"" + txtScriptfile.Text + "\"";
FilePathSite = "@\"" + txtSiteFile.Text +"\"";
FilePathDestinationFolder = "@\"" + txtdestinationFolder.Text + "\"";
txtScriptfile.Text = FilePathScript;
txtSiteFile.Text = FilePathSite;
txtdestinationFolder.Text = FilePathDestinationFolder;
string[] Scriptlines = System.IO.File.ReadAllLines(FilePathScript);
string[] Sitelines = System.IO.File.ReadAllLines(FilePathSite);
경로에 @ ""을 추가하는 이유는 무엇입니까? 그 (것)들에서 그 (것)들을 축 어적으로 만드는 것을 예정하는 경우에, 당신은 그것을 필요로하지 않는다. 컴파일러가 특별한 문자를 무시하고 당신이 그것들을 벗어나지 않아도되도록 문자열에 @ ""를 추가해야만합니다. – BoeseB
_ "해당 파일 경로를 어떻게 작동 시키나요?"_ 현재 ** 작동하지 않는 ** 어떤 방식으로 작동합니까? –
하나의 파일 만 선택하려면'MultiSelect = True'가 필요하지 않습니다. 그냥'FileName' 속성을 사용하십시오. 그런 다음 선택한 파일을 큰 따옴표로 묶으려는 시도가 잘못되었습니다 ("\" ")를 사용하고 쓸모가 없습니다.) ReadAllLines 메소드는 파일 이름의 공백을 처리하는 방법을 알고 있습니다 – Steve