我想单击“浏览”按钮时选择本地硬盘上的文件。我不知道如何使用OpenFileDialog
控件。谁能帮我?如何使用C#将浏览文件按钮添加到Windows窗体#
68
A
回答
86
这些链接举例
http://dotnetperls.com/openfiledialog
http://www.geekpedia.com/tutorial67_Using-OpenFileDialog-to-open-files.html
private void button1_Click(object sender, EventArgs e)
{
int size = -1;
DialogResult result = openFileDialog1.ShowDialog(); // Show the dialog.
if (result == DialogResult.OK) // Test result.
{
string file = openFileDialog1.FileName;
try
{
string text = File.ReadAllText(file);
size = text.Length;
}
catch (IOException)
{
}
}
Console.WriteLine(size); // <-- Shows file size in debugging mode.
Console.WriteLine(result); // <-- For debugging use.
}
35
var FD = new System.Windows.Forms.OpenFileDialog();
if (FD.ShowDialog() == System.Windows.Forms.DialogResult.OK) {
string fileToOpen = FD.FileName;
System.IO.FileInfo File = new System.IO.FileInfo(FD.FileName);
//OR
System.IO.StreamReader reader = new System.IO.StreamReader(fileToOpen);
//etc
}
17
OpenFileDialog fdlg = new OpenFileDialog();
fdlg.Title = "C# Corner Open File Dialog" ;
fdlg.InitialDirectory = @"c:\" ;
fdlg.Filter = "All files (*.*)|*.*|All files (*.*)|*.*" ;
fdlg.FilterIndex = 2 ;
fdlg.RestoreDirectory = true ;
if(fdlg.ShowDialog() == DialogResult.OK)
{
textBox1.Text = fdlg.FileName ;
}
在此代码解释它,你可以把你的地址在文本框中。
相关问题
- 1. 将文件浏览器按钮添加到MS Access窗体
- 2. C#添加WPF按钮到Windows窗体
- 3. 如何将浏览文件系统按钮添加到Visual Studio应用程序?
- 4. C#将项添加到Windows窗体
- 5. Windows窗体按钮在C#
- 6. 如何将XML文件加载到集合C#Windows窗体
- 7. 将用户控件添加到Windows窗体c时出错#
- 8. 如何添加电子邮件预览按钮到MS-Access 2003中的窗体
- 9. 如何将oAuth(DevDefined oAuth)添加到C#windows窗体项目中?
- 10. 在visual C++窗体窗体应用程序中浏览文件
- 11. Windows窗体浏览器骨架(C#/。NET)
- 12. 将Web窗体控件添加到Windows窗体
- 13. c#windows phone 8如何将样式添加到按钮
- 14. 如何将文本添加到按钮?
- 15. 如何将许多控件添加到Windows窗体选项卡?
- 16. 将方法添加到Windows窗体?
- 17. 将代理添加到Windows窗体
- 18. 将事件添加到Windows窗体中的用户控件
- 19. 如何将UIElement添加到Windows窗体应用程序?
- 20. 将按钮添加到窗口边框
- 21. 按钮点击Windows窗体c#
- 22. 如何将“浏览文件”对话框添加到transferText命令?
- 23. 如何在windows窗体中为按钮的文本添加上标?
- 24. 在Windows窗体中添加用户控件(WPF)到面板c#
- 25. 将搜索框添加到高亮显示文本的Windows窗体Web浏览器控件
- 26. WPF。使用c#将图像和文字添加到按钮中#
- 27. 如何在MATLAB中使用按钮打开浏览器窗口?
- 28. 如何将CSS和JavaScript添加到Windows窗体应用程序C#.net
- 29. 如何将我们自己的按钮添加到浏览器的标题栏
- 30. 使用C#添加和删除动态控件Windows窗体#
非常感谢你的快速回复....它帮了我很多.. – Harikasai 2011-02-16 04:34:41