C#winform读取与保存⽂件//读取
private void Get_data_Click(object sender, EventArgs e){
OpenFileDialog GetData = new OpenFileDialog(); //以打开的⽅式
GetData.Multiselect = false; //该值确定是否可以选择多个⽂件
GetData.Title = "请选择⽂件"; //标题
GetData.InitialDirectory = @"C:\"; //默认打开C:\路径(可更改)
//限制只显⽰⽂件夹及后缀为sql的⽂件(可根据需求更改)
GetData.Filter = "SQL⽂件(*.sql)|*.sql";
string script = " ";
if (GetData.ShowDialog() == DialogResult.OK){ //如果选择了⽂件
script = GetData.FileName; //script赋值为所选⽂件的路径
}
}
//保存
private void Save_Data_Click(object sender, EventArgs e){
SaveFileDialog SaveData = new SaveFileDialog(); //以保存⽂件的⽅式打开
SaveData.Title = "请选择路径"; //标题getsavefilename
SaveData.InitialDirectory = @"C:\"; //默认路径是C:\,可更改
SaveData.Filter = "SQL⽂件(*.sql)|*.sql"; //只能保存为sql⽂件(可根据需求更改)
string script = " ";
SaveData.FileName = "script"; //默认⽂件名是script(.sql是⾃动补的)
if (SaveData.ShowDialog() == DialogResult.OK){ //如果选定路径按下保存按钮
script = SaveData.FileName; //script赋值为选择保存的路径
}
}
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系QQ:729038198,我们将在24小时内删除。
发表评论