I need to validate the file which is to be uploaded to the server. The validation must be done before uploading it. i.e., validation completed at client side. This task shou
.Net MVC Solution:
I am using the data type of HttpPostedFileBase
In your Views > Shared
Folder, create a new folder called "EditorTemplates" and use this:
@model HttpPostedFileBase
@Html.TextBox("", null, new { type = "file" })
I then pass this HttpPostedFileBase
object from the controller to a method that does the following:
public Files Upload(HttpPostedFileBase files)
{
if (files.ContentLength > 0) {
.....
}
The ContentLength property on the HttpPostedFileBase class contains the number of bytes in the posted file
This will make it so you have a file uploading box available.
On the ASP.NET WebForms Solution:
Make a button with a OnClick or OnCommand event that does something like this:
if (fuPictures.HasFile == true)
{
int fileSize = fuPictures.FileBytes;
}
That will give you the file size. Hope this helps.