OpenFileDialog openFileDialog1 =new OpenFileDialog();
openFileDialog1.Filter = "gif(*.gif)|*.gif";
openFileDialog1.RestoreDirectory = true;
if (openFileDialog1.ShowDialog() == DialogResult.OK)
{
MessageBox.show(openFileDialog1.FileName);
}
openFileDialog1.Filter = "gif(*.gif)|*.gif";
openFileDialog1.RestoreDirectory = true;
if (openFileDialog1.ShowDialog() == DialogResult.OK)
{
MessageBox.show(openFileDialog1.FileName);
}
{
}saveFileDialog类似
SaveFileDialog1.Filter = "编码器会话文件 (*.wme)|*.wme";
SaveFileDialog1.RestoreDirectory = true;
if (SaveFileDialog1.ShowDialog() == DialogResult.OK)
{
//存储源组配置文件到指定路径。
Encoder1.Save(SaveFileDialog1.FileName);
}
HttpPostedFile hpf=htmlInputFile.PostedFile;
char[] de={'\\'};
string[] AFilename=hpf.FileName.Split(de);
strflsize=hpf.ContentLength.ToString();//附件大小
strFlName="";//附件名
strFlName=AFilename[AFilename.Length-1];
if(hpf != null)
{//文件存在
hpf.SaveAs(Server.MapPath("../FileFolder/")+docmid.ToString()+strFlName);
//保存文件
file="(服务器相对路径)/FileFolder/"+docmid.ToString()+strFlName;
//文件保存路径
//-------------在数据库中保存此路径
}
else
{
file="";
}//下载附件
hlkfile.NavigateUrl="http://"+(读数据库中保存的路径).ToString();
public void SaveMyFile()
{
// Create a SaveFileDialog to request a path and file name to save to.
SaveFileDialog saveFile1 = new SaveFileDialog(); // Initialize the SaveFileDialog to specify the RTF extension for the file.
saveFile1.DefaultExt = "*.txt";
saveFile1.Filter = "Text Files|*.txt"; // Determine if the user selected a file name from the saveFileDialog.
if(saveFile1.ShowDialog() == System.Windows.Forms.DialogResult.OK &&
saveFile1.FileName.Length > 0)
{
// Save the contents of the RichTextBox into the file.
richTextBox1.SaveFile(saveFile1.FileName, RichTextBoxStreamType.PlainText);
}
}
打开文件:
public void LoadMyFile()
{
// Create an OpenFileDialog to request a file to open.
OpenFileDialog openFile1 = new OpenFileDialog(); // Initialize the OpenFileDialog to look for RTF files.
openFile1.DefaultExt = "*.txt";
openFile1.Filter = "Text Files|*.txt"; // Determine whether the user selected a file from the OpenFileDialog.
if(openFile1.ShowDialog() == System.Windows.Forms.DialogResult.OK &&
openFile1.FileName.Length > 0)
{
// Load the contents of the file into the RichTextBox.
richTextBox1.LoadFile(openFile1.FileName, RichTextBoxStreamType.PlainText);
}
}