Hi nauna,
You actually don't have access to filesystem (for example reading and writing local files), however due to HTML5 File Api specification, there are some file properties that you do have access to, and the file size is one of them. For security reasons ajax / javascript isn't allowed to access the file stream or file properties before or during upload.
Code
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title></title>
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.8.3/jquery.min.js"></script>
<script type="text/javascript">
$(function () {
$("#btnUpload").bind("click", function () {
if (typeof ($("#fuVideo")[0].files) != "undefined") {
var size = parseFloat($("#fuVideo")[0].files[0].size / 1024).toFixed(2);
var sizeLimit = 1024 * 1;
if (size < sizeLimit) {
alert(size + " KB.");
}
else {
alert("Max allowed size is 1MB, You have uploaded " + (size / 1024).toFixed(2) + " MB.");
}
} else {
alert("This browser does not support HTML5.");
}
});
});
</script>
</head>
<body>
<form id="form1" runat="server">
<div>
<input type="file" name="fuVideo" id="fuVideo" />
<input type="submit" name="btnUpload" value="Upload" onclick="ValidateVideo();" id="btnUpload" />
</div>
</form>
</body>
</html>
Demo
Server Side
HTML
<div>
<asp:FileUpload ID="fuVideo" runat="server" />
<asp:RegularExpressionValidator ControlToValidate="fuVideo" runat="server" ValidationExpression="([a-zA-Z0-9\s_\\.\-:])+(.mkv|.wmv|.mp4)$"
ValidationGroup="g" ErrorMessage="Please select a valid video file." ForeColor="Red"></asp:RegularExpressionValidator>
<br />
<asp:Button ID="btnUpload" Text="submit" runat="server" OnClick="ValidateVideo" ValidationGroup="g" />
</div>
Code
protected void ValidateVideo(object sender, EventArgs e)
{
if (fuVideo.HasFile)
{
float bytesSize = fuVideo.PostedFile.ContentLength;
float sizeLimit = 1024 * 1024;
if (bytesSize < sizeLimit)
{
ClientScript.RegisterStartupScript(GetType(), "alert", "alert('" + (bytesSize / 1024) + " KB.');", true);
}
else
{
ClientScript.RegisterStartupScript(GetType(), "alert", "alert('Max allowed size is 1MB, You have uploaded " + ((bytesSize / 1024) / 1024) + " MB.');", true);
}
}
}
Screenshot