C# openfiledialog 点取消 提示 空路径名是非法的 错误
我用trycatch把这个错误屏蔽了。。请问还有什么办法能够使他不提示非法?privatevoid打开ToolStripMenuItem_Click(objectsend...
我用try catch 把 这个错误屏蔽了 。。请问还有什么办法能够使他不提示非法?
private void 打开ToolStripMenuItem_Click(object sender, EventArgs e)
{
try
{
System.Windows.Forms.OpenFileDialog txt = new System.Windows.Forms.OpenFileDialog();
txt.Title = "打开";
txt.ShowDialog();
String txtname = txt.FileName;
StreamReader s = new StreamReader(txtname,System.Text .Encoding.Default );
String txtcontent;
txtcontent = s.ReadToEnd();
textBox1.Text = txtcontent;
}
catch( Exception ex)
{ }
} 展开
private void 打开ToolStripMenuItem_Click(object sender, EventArgs e)
{
try
{
System.Windows.Forms.OpenFileDialog txt = new System.Windows.Forms.OpenFileDialog();
txt.Title = "打开";
txt.ShowDialog();
String txtname = txt.FileName;
StreamReader s = new StreamReader(txtname,System.Text .Encoding.Default );
String txtcontent;
txtcontent = s.ReadToEnd();
textBox1.Text = txtcontent;
}
catch( Exception ex)
{ }
} 展开
1个回答
展开全部
if (txt.ShowDialog()==DialogResult.OK)
{
String txtname = txt.FileName;
StreamReader s = new StreamReader(txtname,System.Text .Encoding.Default );
String txtcontent;
txtcontent = s.ReadToEnd();
textBox1.Text = txtcontent;
}
{
String txtname = txt.FileName;
StreamReader s = new StreamReader(txtname,System.Text .Encoding.Default );
String txtcontent;
txtcontent = s.ReadToEnd();
textBox1.Text = txtcontent;
}
本回答被提问者采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询