OpenFileDialog openFileDialog1 = new OpenFileDialog();
this.openFileDialog1.InitialDirectory = "c:\\"; openFileDialog1.Filter = "txt files (*.txt)|*.txt" ;
openFileDialog1.FilterIndex = 1 ;
openFileDialog1.RestoreDirectory = true ; if(openFileDialog1.ShowDialog() == DialogResult.OK)
{
this.textBox1.Text = this.openFileDialog1.FileName;
}
this.openFileDialog1.InitialDirectory = "c:\\"; openFileDialog1.Filter = "txt files (*.txt)|*.txt" ;
openFileDialog1.FilterIndex = 1 ;
openFileDialog1.RestoreDirectory = true ; if(openFileDialog1.ShowDialog() == DialogResult.OK)
{
this.textBox1.Text = this.openFileDialog1.FileName;
}
解决方案 »
- 谁有office 可以在server 2003 64位上用的,不需要破译
- 关于面向对象的疑惑
- 请教,关于ExecuteScalar的返回值。
- 转向C#,问个新手问题,多谢
- 如何用。NETFRAME 2.0串口通讯(C#)?
- 有没有Avalon(Windows Presentation Foundation)的讨论区???
- 请教个数据库的问题
- DataTable汇出为xml文件时 日期格式 的问题
- 谢谢各位高手,再问一个问题,怎么让弹出的窗口在屏幕中间,并且弹到最上面,还有各位告诉我的方法,弹出窗口以后,在托盘中又出现了一个
- 水晶报表出错了,求助。
- 各位大虾:有没有代码可以创建sql server 客户端网络实用工具中的别名,还是一定要去手工创建,等待......
- ***哪位大哥给段代码实现login.aspx?ReturnUrl=default.aspx
private void open_Click(object sender, System.EventArgs e)
{
string lstrfilename="";
string lstrtemp="";
if( openFileDialog1.ShowDialog()==DialogResult.OK)
{
lstrfilename=openFileDialog1.FileName;
strdocumentname=lstrfilename;
}
else
{
return;
}
FileStream lfstream=null;
string lstrfilecontents="";
try
{
lstrtemp="";
int liretval=1;
lfstream=new FileStream(lstrfilename,FileMode.Open,FileAccess.Read);
Byte[] lbyte=new Byte[1024];
lbyte.Initialize();
for (;liretval!=0;)
{
lbyte.Initialize();
lstrtemp="";
liretval=lfstream.Read(lbyte,0,1024);
lstrtemp=Encoding.ASCII.GetString(lbyte,0,1024);
lstrfilecontents+=lstrtemp;
}
}
catch(FileNotFoundException el)
{string lstrMessage="File not found or permission denied";
MessageBox.Show(lstrMessage,"word pad",MessageBoxButtons.OK ,MessageBoxIcon.Error);
return;
}
catch(Exception e2)
{ string lstrError="Error:"+e2;
MessageBox.Show(lstrError,"word pad",MessageBoxButtons.OK ,MessageBoxIcon.Error);
return;
}
finally
{
if (lfstream!=null)
{lfstream.Close();
}
}
lstrtemp=lstrfilename.ToLower();
if(lstrtemp.EndsWith(".rtf"))
{
richTextBox1.Rtf=lstrfilecontents;
itypeofdocument=2;
}
else
{ richTextBox1.Text=lstrfilecontents;
itypeofdocument=1;
}
this.Text="word pad"+lstrfilename;
richTextBox1.Select(0,0);
bsaveflag=false;//这个用来判断是否保存的
}
string strFileName = info.Name; //取得纯文件名FileStream fs = new FileStream(strFilePath, FileMode.Open, FileAccess.Read);
byte[] bytes = new byte[fs.Length];
fs.Read(bytes, 0, bytes.Length);
fs.Close();这样就把文件读到了byte[]里