1. 根据地址打开文件
AppDomain.CurrentDomain.BaseDirectory
Application.StartupPath // 根路径 :即进入到项目的Debug层
System.Diagnostics.Process.Start(@"Help操作说明.docx"); //直接打开文档
2. 使用资源文件
例如: Properties.Resources._48_label_24px_14018_easyicon_net
4.动态保存
#region 弹出保存文件夹选择窗口类 //一般选择文件保存地址都用弹出对话框来进行选择 public class DirectorySelect : FolderNameEditor { private FolderBrowser fb = new FolderBrowser(); private string fDescription = "Choose Directory"; private string fReturnPath = String.Empty; public string Description { set { fDescription = value; } get { return fDescription; } } public string ReturnPath { get { return fReturnPath; } } public DirectorySelect() { } private DialogResult RunDialog() { fb.Description = this.Description; fb.StartLocation = FolderBrowserFolder.MyComputer; fb.Style = FolderBrowserStyles.RestrictToSubfolders; //|FolderBrowserStyles.RestrictToDomain; return fb.ShowDialog(); } public DialogResult ShowDialog() { DialogResult dRes = DialogResult.None; dRes = RunDialog(); if (dRes == DialogResult.OK) this.fReturnPath = fb.DirectoryPath; else this.fReturnPath = String.Empty; return dRes; } } //一般选择文件保存地址都用弹出对话框来进行选择 //调用 //DirBrowser myDirBrowser=new DirBrowser(); //if(myDirBrowser.ShowDialog()!=DialogResult.Cancel) //MessageBox.Show(myDirBrowser.ReturnPath); public class DirBrowser : FolderNameEditor { FolderBrowser fb = new FolderBrowser(); public string Description { set { _description = value; } get { return _description; } } public string ReturnPath { get { return _returnPath; } } public DirBrowser() { } public DialogResult ShowDialog() { fb.Description = _description; fb.StartLocation = FolderBrowserFolder.MyComputer; DialogResult r = fb.ShowDialog(); if (r == DialogResult.OK) _returnPath = fb.DirectoryPath; else _returnPath = String.Empty; return r; } //private string _description = "Choose Directory"; //private string _returnPath = String.Empty; private string _description = "请选择文件夹"; private string _returnPath = String.Empty; } #endregion
//动态添加地址 DirectorySelect fileHlep = new DirectorySelect(); if (fileHlep.ShowDialog() == DialogResult.OK) { FilePath = fileHlep.ReturnPath + dr["FileName"].ToString(); } //保存 FileStream fs2 = new FileStream(filePath, FileMode.OpenOrCreate, FileAccess.ReadWrite); fs2.Write(byData , 0, byData .Length); fs2.Close();