private void openFileDialog_FileOk(object sender, System.ComponentModel.CancelEventArgs e)
{
try
{
//我想通过openFileDialog在rtfTex中显示打开的文件,参 数怎么弄?
this.rtfText.LoadFile();
}
catch(System.IO.FileNotFoundException)
{
MessageBox.Show("No file to load yet");
}
}
{
try
{
//我想通过openFileDialog在rtfTex中显示打开的文件,参 数怎么弄?
this.rtfText.LoadFile();
}
catch(System.IO.FileNotFoundException)
{
MessageBox.Show("No file to load yet");
}
}
解决方案 »
- 很深奥的c#问题~
- c#多线程查找文件问题
- 用过股票软件的来看看
- 谁用过VS2005,上面好多控件名称是不是有很多都和VS2003不一样?
- 请教 DataGrid 的小问题:
- C1FlexGrid打印问题?
- 请问下为什么我装了VS2012 启动了就自动关闭?
- c#读多个串口,同时每个串口每次读十个字节。十个字节中前8个字节为数据位,第九个为CRC检验位,第十位为结束位。怎么写代码。求大神指点啊!
- 我怎么用http:://127.0.0.1时,出现提示让输入用户和密码??
- studio .net 注册
- 【求助】用UDP传输数据的问题。。。多谢
- 在VS2005中的“添加新项”中,“数据窗体向导”在哪???
OpenFileDialog openFileDialog=new OpenFileDialog();
openFileDialog.InitialDirectory="c:\\";//注意这里写路径时要用c:\\而不是c:\
openFileDialog.Filter="文本文件|*.*|C#文件|*.cs|所有文件|*.*";
openFileDialog.RestoreDirectory=true;
openFileDialog.FilterIndex=1;
if (openFileDialog.ShowDialog()==DialogResult.OK)
{
fName=openFileDialog.FileName;
File fileOpen=new File(fName);
isFileHaveName=true;
richTextBox1.Text=fileOpen.ReadFile();
richTextBox1.AppendText("");
}
}参考
http://singlepine.cnblogs.com/articles/255772.html
cOpenFileDialog.Filter = "wav files (*.wav)|*.wav|mp3 files (*.mp3)|*.mp3";
cOpenFileDialog.FilterIndex = 1;if (cOpenFileDialog.ShowDialog() == DialogResult.OK)
{
if (cOpenFileDialog.FileName == null || cOpenFileDialog.FileName == "")
{
MessageBox.Show("Please select a file.");
return;
}
if (File.Exists(cOpenFileDialog.FileName) == false)
{
MessageBox.Show("The picture file is not exist.");
return;
}
if (LoadVoiceFile(cOpenFileDialog.FileName) != SYS_RETURN.OK)
MessageBox.Show("Fail to open picture file.");
}
UTF8Encoding temp = new UTF8Encoding(true); while (fs.Read(b,0,b.Length) > 0)
{
Console.WriteLine(temp.GetString(b));
}
UnicodePlainText: A text stream that contains spaces in place of Object Linking and Embedding (OLE) objects. The text is encoded in Unicode. 这是 MSDN 上对这个枚举各个成员的解释。你根据你的文件的编码及格式选择正确的参数就行了。
{
if(this.openFileDialog1.ShowDialog() == DialogResult.OK)
{
System.IO.StreamReader sr = new System.IO.StreamReader(this.openFileDialog1.FileName,System.Text.Encoding.GetEncoding("GB2312"));
this.textBox1.Text = sr.ReadToEnd();
r.Close();
}
}