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#保存对话框的文件路径


基础教程推荐
- 经典 Asp 中的 ResolveUrl/Url.Content 等效项 2022-01-01
- 错误“此流不支持搜索操作"在 C# 中 2022-01-01
- 将事件 TextChanged 分配给表单中的所有文本框 2022-01-01
- 如何动态获取文本框中datagridview列的总和 2022-01-01
- 首先创建代码,多对多,关联表中的附加字段 2022-01-01
- 全局 ASAX - 获取服务器名称 2022-01-01
- JSON.NET 中基于属性的类型解析 2022-01-01
- 是否可以在 asp classic 和 asp.net 之间共享会话状态 2022-01-01
- 在 VS2010 中的 Post Build 事件中将 bin 文件复制到物 2022-01-01
- 从 VS 2017 .NET Core 项目的发布目录中排除文件 2022-01-01