如何在C#桌面应用程序中获取FileUpload [英] How to Get FileUpload in C# Desktop Application
问题描述
如何在C#桌面应用程序中获取FileUpload,就像我们在ASP.NET中拥有一个控件名称fileupload一样,在C#窗口窗体中具有
How to get FileUpload in C# Desktop Application ,, as we have in ASP.NET a control Name fileupload do we have in C# Window Form
推荐答案
按钮单击下面的代码:单击按钮后,其行为类似于浏览按钮.
Write the below code on button click: after clicking the button it behaves like browse button.
OpenFileDialog OpenFileDialog1 = new OpenFileDialog();
OpenFileDialog1.InitialDirectory = "c:\\";
OpenFileDialog1.Filter =
"CSV Files (*.csv)|*.csv|" +
"Excel Files (*.xls)|*.xls|" +
"All Files (*.*)|*.*";
OpenFileDialog1.FilterIndex = 2;
OpenFileDialog1.RestoreDirectory = true;
if (OpenFileDialog1.ShowDialog() == DialogResult.OK)
{
fName = OpenFileDialog1.FileName;
}
//u can also save or see the path
this.textBox1.Text = fName;
请参考:手动创建文件上传功能 [ http://msdn2.microsoft.com/en-us/librar /system.net.webclient(VS.80).aspx [ http://msdn2.microsoft.com/en-us /library/system.net.webclient.uploadfile(VS.80).aspx [ http://msdn2.microsoft.com/en-us/library/36s52zhs(VS .80).aspx [ ^ ]
Refer: Manually Create File upload Functionality[^]
====
You can also up-load the file by using UploadFile Method of WebClient.
Please refer to the MSDN library for details:
WebClient Class
http://msdn2.microsoft.com/en-us/librar/system.net.webclient(VS.80).aspx[^]
WebClient.UploadFile Method
http://msdn2.microsoft.com/en-us/library/system.net.webclient.uploadfile(VS.80).aspx[^]
WebClient.UploadFile Method (String, String)
http://msdn2.microsoft.com/en-us/library/36s52zhs(VS.80).aspx[^]
这篇关于如何在C#桌面应用程序中获取FileUpload的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!