如何以窗口形式上传文件? [英] How to upload a file in window forms?
本文介绍了如何以窗口形式上传文件?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
在窗体中,如何上传文件,我没有找到任何文件上传控件.你能给我任何参考吗?我想将文档存储在我的系统驱动器中.谢谢.
In window forms, how to upload a file, I did not found any file upload control. Can you give me any reference? I want to store the document with in my systems drive. Thank you.
推荐答案
您可以使用以下代码放置表单按钮并为其创建单击处理程序:
You can put on your form button and create click handler to it with the following code:
private void buttonGetFile_Click(object sender, EventArgs e)
{
OpenFileDialog dialog = new OpenFileDialog();
dialog.Filter = "Text files | *.txt"; // file types, that will be allowed to upload
dialog.Multiselect = false; // allow/deny user to upload more than one file at a time
if (dialog.ShowDialog() == DialogResult.OK) // if user clicked OK
{
String path = dialog.FileName; // get name of file
using (StreamReader reader = new StreamReader(new FileStream(path, FileMode.Open), new UTF8Encoding())) // do anything you want, e.g. read it
{
// ...
}
}
}
这篇关于如何以窗口形式上传文件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文