简体   繁体   English

允许用户在C#中浏览文件的最佳方法是什么?

[英]What's the best way to allow a user to browse for a file in C#?

允许用户在C#中浏览文件的最佳方法是什么?

using (OpenFileDialog dlg = new OpenFileDialog())
{
    dlg.Title = "Select a file";
    if (dlg.ShowDialog()== DialogResult.OK)
    {
        //do something with dlg.FileName  
    }
}

我会说使用标准的“打开文件”对话框( OpenFileDialog ),这使得它对新用户来说不那么令人生畏,并且有助于使用一致的用户界面。

Close, Ryan, but you never showed the dialog. 关闭,Ryan,但你从未展示过对话框。 it should be: 它应该是:

if (dlg.ShowDialog() == DialogResult.OK)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 让用户在 C# 中选择子目录的最佳方法是什么? - What's the best way to let a user pick a subdirectory in C#? 在C#中将short []数组写入文件的最佳方法是什么? - What's the best way to write a short[] array to a file in C#? 还有另一种方法来浏览C#中的用户控件 - Is there another way to browse user controls in C# 在c#中确定程序员是通过IDE还是用户运行程序的最佳方法是什么? - What is the best way in c# to determine whether the programmer is running the program via IDE or it's user? 使用C#通过网络发送文件的最佳方法是什么? - What's the best way to send a file over a network using C#? 在C#中读取制表符分隔文本文件的最佳方法是什么? - What's the best way to read a tab-delimited text file in C# 在C#中对MS Excel文件运行正则表达式的最佳方法是什么? - What's the best way to run a regex against an MS Excel file in C#? 在C#中存储用户特定数据的最佳方法是什么? - What is the best way to to store user specific data in C#? 在 C# 和 sql 中管理应用程序用户选项的最佳方法是什么? - what is the best way to manage application user options in C# and sql? 在C#中实现动态代理的最佳方法是什么? - What's the best way to implement a dynamic proxy in C#?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM