Monday, January 2, 2012

How to use simple ASP.NET FileUpload with RegularExpressionValidator and ValidationSummary

In this tutorial we are performing uploading of file task which has become so simple with ASP.NET FileUpload control and here we are also performing particular validation on this control.

Step1:  File->New->Website

Step 2: Create a folder with a name "files" in Solution Explorer. This Folder will be used to store uploaded data.

Step 3:  
aspx page code split view
Here we are using RegularExpressionValidator for validation of the file to be uploaded as we have restricted user with uploading only doc, docx or pdf files. we are also using ValidationSummary control to show all error messages.
(click on image to enlarge it)

Step 4:
aspx.cs page code(C# code)
This code is executing on submit button click on users input page(aspx page). Here we have restricted user with file selection, file size(not more than 1 mb is allowed) and providing the path of the "files" folder to store uploaded file in that folder. When the file uploaded successfully we are providing file name and link to that file as output.

Step 5:
View in Browser:

No comments:

Popular Posts