如何在C#桌面应用程序中获取FileUpload

如何在C#桌面应用程序中获取FileUpload

问题描述:

如何在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[^]