Follow by Email

Thursday, April 4, 2013

save file using html file control in asp.net

save file using html file control in asp.net :

In My Default.aspx page i have added this below html controls:

<input type="file" name="file"/> <!--Html file upload control-->
<input type="submit" name="Upload" value="Upload" /><!-- Submit Button -->

Add both of this above controls under the form tag of the html page. In form tag define the enctype,Method and action(URL).

Refer this below image for example, Here i'm providing the action url to the same page i.e. default.aspx.



















In default.aspx.cs page we will write the code to save the file in the application directory folder. Add using System.Web.UI.HtmlControls namespace in the codebehind. I'm saving my file in Temp folder which is in the application root directory. You can create folder or save in any of your existing folders.



Now run the application and select the file u want to upload. and click on upload button. File Uploaded Successfully message will be displayed. Still u confirm by checking the folder where u wanted to save your file.
















Select File to Upload

File Saved in the folder successfully


Check the folder were u wanted to save the file. Cheers !!