Manually Create File upload Functionality

Posted by Shahkomil under Windows Forms category on | Views : 2163
there is no specific control for uploading file in windows application.
But you can do same functionality using below method:

(1) first take one button and textbox control.

(2) then add following code in your .cs file.

OpenFileDialog dlg = new OpenFileDialog();

[3]add following code in buttons click event.

dlg.Filter = "Audio File (*.mp3, *.wav)|*.mp3*;*.wav";
if (dlg.ShowDialog() == DialogResult.OK)
txtBox1.Text = dlg.FileName;

(4)show by this you can get filename in your textbox.

(5)now when you submit your form then write below code on your submit buttons click event.

FileInfo str = new FileInfo(dlg.FileName );
File.Copy(txtBox1.Text ,Application.StartupPath +"\\"+str.Name);
txtAodioPath.Text = Application.StartupPath + "\\" + str.Name;

(6)Now run your application. and check this functionality for uploading file.

Comments or Responses

Login to post response