| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 904 人关注过本帖
标题:关于openFileDialogl ,saveFileDialogl使用方法。
只看楼主 加入收藏
weilight2008
Rank: 1
等 级:新手上路
帖 子:111
专家分:4
注 册:2005-10-5
结帖率:50%
收藏
 问题点数:0 回复次数:7 
关于openFileDialogl ,saveFileDialogl使用方法。
大家好,请问openFileDialogl ,saveFileDialogl的实现代码是怎么使用的。
搜索更多相关主题的帖子: 代码 
2005-10-20 16:14
zhangyingcai
Rank: 1
等 级:新手上路
帖 子:55
专家分:0
注 册:2005-9-3
收藏
得分:0 
OpenFileDialog dlg = new OpenFileDialog();
dlg.Title = "Open File";
dlg.ShowHelp = true;
dlg.Filter = "Text Files(*.txt)|*.txt|All Files(*.*)|*.*";
if(dlg.ShowDialog() != DialogResult.OK)
{
  return;
}
// 后面可以使用dlg.FileName和dlg.FileNames等属性来进行下面的操作

SaveFileDialog使用方法和OpenFileDialog类似,看看MSDN就差不多了。

2005-10-20 20:19
weilight2008
Rank: 1
等 级:新手上路
帖 子:111
专家分:4
注 册:2005-10-5
收藏
得分:0 
我试验了一下,代码可以用,但是怎么文件打不开阿?

生活不相信眼泪,勇敢去拼。
2005-10-21 10:42
weilight2008
Rank: 1
等 级:新手上路
帖 子:111
专家分:4
注 册:2005-10-5
收藏
得分:0 
我还看过下面的代码:
openFileDialog1.FilterIndex = 2 ;
   openFileDialog1.RestoreDirectory = true ;
请问是什么意思?

生活不相信眼泪,勇敢去拼。
2005-10-21 11:08
zhangyingcai
Rank: 1
等 级:新手上路
帖 子:55
专家分:0
注 册:2005-9-3
收藏
得分:0 

FileDialog.FilterIndex Property

Gets or sets the index of the filter currently selected in the file dialog box. // 获得或设置文件对话框中filter当前选中的内容序号。

FileDialog.RestoreDirectory Property

Gets or sets a value indicating whether the dialog box restores the current directory before closing. // 获得或设置对话框关闭前是否储存当前目录为默认目录,就是每次打开对话框都显示上次访问的目录的意思。 这是MSDN里面的原话,建议楼主学习的时候最好能够参考帮助文档,这样比较有效,还可以提高自己的自学能力。


2005-10-21 12:56
唐伯猫
Rank: 8Rank: 8
等 级:贵宾
威 望:45
帖 子:5323
专家分:58
注 册:2005-8-9
收藏
得分:0 
先加Io命名空间.
打开为:
OpenFileDialog openFileDialog=new OpenFileDialog();
   openFileDialog.InitialDirectory="D:\\";
   openFileDialog.Filter="文本文件|*.*|C#文件|*.cs|所有文件|*.*";
   openFileDialog.RestoreDirectory=true;
   openFileDialog.FilterIndex=1;
   if(openFileDialog.ShowDialog()==DialogResult.OK)
   {
    string fname=openFileDialog.FileName;
    StreamReader sr=File.OpenText(fname);
    string str;
    while((str=sr.ReadLine())!=null)
    {
     this.richTextBox1.Text+=str;
    }
   }
保存为:
SaveFileDialog sf=new SaveFileDialog();
    sf.Filter="文本文件|txt.txt|c#文件|*.cs|所有文件|*.*";
    sf.FilterIndex=2;
    sf.RestoreDirectory=true;
    if(sf.ShowDialog()==DialogResult.OK)
    {
     string fName=sf.FileName;
     StreamWriter sw=File.AppendText(fName);
     sw.Write(this.richTextBox1.Text);
     sw.Flush();
     sw.Close();
    }

<iframe name="alimamaifrm" frameborder="0" marginheight="0" marginwidth="0" border="0" scrolling="no" width="300" height="170" src="/go/app/tbk_app/chongzhi_300_170.php?pid=mm_28854300_2441872_11377541&page=chongzhi_300_170.php&size_w=300&size_h=170&stru_phone=1&stru_game=1&stru_travel=1" ></iframe>
2005-10-22 22:32
unpowertome
Rank: 1
等 级:新手上路
帖 子:8
专家分:0
注 册:2007-5-6
收藏
得分:0 
openFileDialog1.Filter="txt(*.txt)|*.txt|allfill(*.*)|*.*";
openFileDialog1.FilterIndex=1;
openFileDialog1.RestoreDirectory=true;
if(openFileDialog1.ShowDialog()==DialogResult.OK)
{
this.crystalReportViewer1.ReportSource=openFileDialog1.FileName;
}

2007-05-06 11:57
unpowertome
Rank: 1
等 级:新手上路
帖 子:8
专家分:0
注 册:2007-5-6
收藏
得分:0 
SaveFileDialog sd=new SaveFileDialog();
sd.Filter="txt(*.txt)|*.txt|allfill(*.*)|*.*";
sd.RestoreDirectory=true;
if(sd.ShowDialog()==DialogResult.OK)
{
string flname=sd.FileName;
StreamWriter sw=new StreamWriter(flname);
sw.Write(this.textBox1.Text);
sw.Flush();
sw.Close();
}

2007-05-06 12:39
快速回复:关于openFileDialogl ,saveFileDialogl使用方法。
数据加载中...
 
   



关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.012194 second(s), 7 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved