Obtain file path of C# save dialog box(获取C#保存对话框的文件路径)
问题描述
我有一个保存对话框,当我按下按钮时会弹出.但是我当时不想保存文件,我想取名称并将其放在按钮旁边的文本框中,以便稍后使用该名称.
I've got a save dialog box which pops up when i press a button. However i dont want to save a file at that point, i want to take the name and place it in the text box next to the button, for the name to be used later.
谁能告诉我如何从保存对话框中获取文件路径以便以后使用?
Can anybody tell me how to obtain the file path from the save dialog box to use it later?
推荐答案
这是我刚刚写的非常快的示例代码......而不是 Console.Write 你可以简单地将路径存储在一个变量中并稍后使用它.
Here is a sample code I just wrote very fast... instead of Console.Write you can simply store the path in a variable and use it later.
SaveFileDialog saveFileDialog1 = new SaveFileDialog();
saveFileDialog1.InitialDirectory = Convert.ToString(Environment.SpecialFolder.MyDocuments);
saveFileDialog1.Filter = "Your extension here (*.EXT)|*.ext|All Files (*.*)|*.*" ;
saveFileDialog1.FilterIndex = 1;
if(saveFileDialog1.ShowDialog() == DialogResult.OK)
{
Console.WriteLine(saveFileDialog1.FileName);//Do what you want here
}
这篇关于获取C#保存对话框的文件路径的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:获取C#保存对话框的文件路径
基础教程推荐
- 如果条件可以为空 2022-01-01
- 更新 Visual Studio 中的 DataSet 结构以匹配新的 SQL 数据库结构 2022-01-01
- 获取C#保存对话框的文件路径 2022-01-01
- 将数据集转换为列表 2022-01-01
- Mono https webrequest 失败并显示“身份验证或解密失败" 2022-01-01
- 从 C# 控制相机设备 2022-01-01
- SonarQube C# 分析失败“不是指针的有效行偏移" 2022-01-01
- 在 VB6 或经典 ASP 中使用 .NET 2022-01-01
- C# 9 新特性——record的相关总结 2023-04-03
- 重新排序 WPF TabControl 中的选项卡 2022-01-01