我正在关注互联网上的教程,我稍微更改了我的目的代码,现在它不工作。我选择使用OpenFileDialog
的路径,然后试图通过反斜线像下面混淆关于拆分反斜杠
C到拆分选定的文件:\的Inetpub \日志\ LogFiles文件\ W3SVC1
,它总是返回form1
而不是文件名,什么我做错了吗?
string filename(string text)
{
string s = Text;
string[] arr = s.Split('\\');
string[] dot = arr[arr.Length - 1].Split('.');
return dot[0];
}
private void button1_Click(object sender, EventArgs e)
{
OpenFileDialog ofd = new OpenFileDialog();
ofd.ShowDialog();
textBox1.Text = ofd.FileName;
label1.Text = filename(textBox1.Text);
}
'Path.GetFileNameWithoutExtension()' – SLaks