As the IE is not supporting the HTML 5 File API then what is the solution to check the file size. Well, with IE you can use FileSystem ActiveX object to get the file size. But the problem with latest IE versions (7,8 and 9) is that by default they don't allow ActiveX objects from security reason perspective. If you want to run this, then you have to explicitly allow ActiveX object by changing the settings of IE. To allow ActiveX -> Go to Tools->Internet Options-> Security->Custom Level->Choose Enable or Prompt ActiveX. But this is not a perfect solution as you can't ask your end-users to do these kind of settings. Hope that IE 10 will support the HTML 5 API. So the complete code looks like below code. It first checks if browser is IE or not. If it's IE then using ActiveX object gets the file size. If not then get the file size using HTML 5 API. $(document).ready(function() { $("#flUpload").change(function () { var iSize = 0; if($.browser.msie) { var objFSO = new ActiveXObject("Scripting.FileSystemObject"); var sPath = $("#flUpload")[0].value; var objFile = objFSO.getFile(sPath); var iSize = objFile.size; iSize = iSize/ 1024; } else iSize = ($("#flUpload")[0].files[0].size / 1024); if (iSize / 1024 > 1) { if (((iSize / 1024) / 1024) > 1) { iSize = (Math.round(((iSize / 1024) / 1024) * 100) / 100); $("#lblSize").html( iSize + "Gb"); } else { iSize = (Math.round((iSize / 1024) * 100) / 100) $("#lblSize").html( iSize + "Mb"); } } else { iSize = (Math.round(iSize * 100) / 100) $("#lblSize").html( iSize + "kb"); } }); }); //Code Ends
A place where Web Developer can get awesome articles in asp.net, windows phone 7 / 8 application codes. We aimed at providing the maximum help in the Software Development and Design :)
Thursday, February 21, 2013
How to validate the File Size using JQuery
Saturday, February 16, 2013
Regular Expressions for Validations in Jquery
1. Allow alphabets only:
var regExpressions = "^([a-zA-Z]+(_[a-zA-Z]+)*)(\s([a-zA-Z]+(_[a-zA-Z]+)*))*$";
2. var validEmail = "^[-!#$%&'*+/0-9=?A-Z^_a-z{|}~](\.?[-!#$%&'*+/0-9=?A-Z^_a-z{|}~])*@[a-zA-Z](-?[a-zA-Z0-9])*(\.[a-zA-Z](-?[a-zA-Z0-9])*)+$"
Wednesday, February 13, 2013
Large File Upload in asp.net
I was trying to upload a larger file to my website (which was recently shifted to IIS7 from IIS6) when I start getting weird error and most common was
"404 not found
The requested document was not found on this server."
with almost a blank white page. I checked my web.config for maxRequestLength attribute and which was properly set that is maxRequestLength = 10240 i.e. I was allowing 10 MB file to be uploaded whereas the file I was trying to upload was just 3 MB, and it was known that files under 10 MB were successfully uploaded in past.
I started googling for the error but unfortunately there wasn't much about this error over the internet.
Started thinking that what special was done with the website recently. There wasn't anything special but the shift from IIS6 to IIS7.
Now when I searched for setting file size in IIS7 I came to know that maxRequestLength is no more functional inIIS7. We have to set maxAllowedContentLength under . Made the required change and whoaaa it start working again.
A thing to remember is that maxAllowedContentLength takes value in Bytes whereas maxRequestLengthaccepts value in Kilo Bytes.
So to set maxAllowedContentLength for 10MB you have to set maxAllowedContentLength = 10485760.
Following is the web.config code which should be set for IIS7 to allow 10MB(say) files.
</system.webServer>
"404 not found
The requested document was not found on this server."
with almost a blank white page. I checked my web.config for maxRequestLength attribute and which was properly set that is maxRequestLength = 10240 i.e. I was allowing 10 MB file to be uploaded whereas the file I was trying to upload was just 3 MB, and it was known that files under 10 MB were successfully uploaded in past.
I started googling for the error but unfortunately there wasn't much about this error over the internet.
Started thinking that what special was done with the website recently. There wasn't anything special but the shift from IIS6 to IIS7.
Now when I searched for setting file size in IIS7 I came to know that maxRequestLength is no more functional inIIS7. We have to set maxAllowedContentLength under
A thing to remember is that maxAllowedContentLength takes value in Bytes whereas maxRequestLengthaccepts value in Kilo Bytes.
So to set maxAllowedContentLength for 10MB you have to set maxAllowedContentLength = 10485760.
Following is the web.config code which should be set for IIS7 to allow 10MB(say) files.
<system.webServer>
<security>
<requestFiltering>
<requestLimits maxAllowedContentLength="10485760"/>
</requestFiltering>
</security>
Wednesday, January 30, 2013
Query for fetching the records in Parent-Child DB table in SQL Server
DECLARE @FileTreeIdINT = 300 (For instance) ;WITH FileTreeHierarchy AS
( SELECT FileTreeID, Company, Parent, Name, 1 AS 'Level' FROM FileTree WHERE FileTreeID = @FileTreeId UNION ALL SELECTF.FileTreeID,F.Company,F.Parent,F.Name,
FH.Level + 1 AS 'Level' FROM FileTree F INNER JOIN FileTreeHierarchyFHONFH.Parent =F.FileTreeID
)
SELECT FileTreeId, Company CompanyId, Parent, Name,
[Level] = CAST([Level] as int)
FROM FileTreeHierarchy Order By [Level] Desc
Tuesday, January 29, 2013
Add Dynamic textboxes using Jquery
<head>
<script type="text/javascript">
function AddMoreTextboxes() {
var counter = 1;
var firstTextboxValue = $("#txtselectedValue").val();
if (firstTextboxValue == '') {
alert('Enter the value in First Textbox !');
return;
}
else {
if (counter > 5) {
alert("Only 5 textboxes allow");
return false;
}
var newTextBoxDiv = $(document.createElement('div'))
.attr("id", 'TextBoxDiv' + counter);
newTextBoxDiv.attr("class", "newTextBoxDiv");
newTextBoxDiv.after('<label></label>' + '<input type="text" name="textbox' + counter +
'" id="textbox' + counter + '" />').html('<label></label>' +
'<input type="text" style="width:200px;" class="newTextbox" name="textbox' + counter + '" id="textbox' + counter + '" value="" />');
newTextBoxDiv.appendTo("#TextBoxesGroup");
counter++;
}
}
</script>
</head>
<body>
<div>
<img src="../../Images/plus.png" width="16" height="16" id="ImgAddMoreTextbox" onclick="AddMoreTextboxes();" />
</div>
</body>
<script type="text/javascript">
function AddMoreTextboxes() {
var counter = 1;
var firstTextboxValue = $("#txtselectedValue").val();
if (firstTextboxValue == '') {
alert('Enter the value in First Textbox !');
return;
}
else {
if (counter > 5) {
alert("Only 5 textboxes allow");
return false;
}
var newTextBoxDiv = $(document.createElement('div'))
.attr("id", 'TextBoxDiv' + counter);
newTextBoxDiv.attr("class", "newTextBoxDiv");
newTextBoxDiv.after('<label></label>' + '<input type="text" name="textbox' + counter +
'" id="textbox' + counter + '" />').html('<label></label>' +
'<input type="text" style="width:200px;" class="newTextbox" name="textbox' + counter + '" id="textbox' + counter + '" value="" />');
newTextBoxDiv.appendTo("#TextBoxesGroup");
counter++;
}
}
</script>
</head>
<body>
<div>
<img src="../../Images/plus.png" width="16" height="16" id="ImgAddMoreTextbox" onclick="AddMoreTextboxes();" />
</div>
</body>
Monday, January 21, 2013
Delete all User-Defined Stored Procedures in SQL Server
declare @procName varchar(500)
declare cur cursor
for select [name] from sys.objects where type = 'p'
open cur
fetch next from cur into @procName
while @@fetch_status = 0
begin
exec('drop procedure ' + @procName)
fetch next from cur into @procName
end
close cur
deallocate cur
Thursday, September 27, 2012
Increase File Upload Size in asp.net using Command Prompt
You can run the following from a command prompt while in the C:\Inetpub\AdminScripts directory instead of editing the Metabase.xml file directly as mentioned in above method.
1. At a command prompt, type the following command, & then press ENTER:
cd C:
cd C:\Inetpub\AdminScripts
2. At a command prompt, type the following command, & then press ENTER to check the current upload limit:
cscript adsutil.vbs get w3svc/ASPMaxRequestEntityAllowed
C:\Inetpub\AdminScripts>cscript adsutil.vbs get w3svc/ASPMaxRequestEntityAllowed
Microsoft (R) Windows Script Host Version 5.6
Copyright (C) Microsoft Corporation 1996-2001. All rights reserved.
ASPMaxRequestEntityAllowed : (INTEGER) 204800
It displays the current/present value that is set to 204800 ie: 200KB.
3. Now to change the value to any higher one, run the following command:
cscript adsutil.vbs set w3svc/ASPMaxRequestEntityAllowed size
In this command, size is a placeholder for the largest file size upload that you want to allow. The maximum value is 1,073,741,824 bytes. Set this value to the lowest possible value that allows for the functionality that you want.
To change the value to 100MB, run the following command:cscript adsutil.vbs set w3svc/AspMaxRequestEntityAllowed 104857600
C:\Inetpub\AdminScripts>cscript adsutil.vbs set w3svc/AspMaxRequestEntityAllowed 104857600
Microsoft (R) Windows Script Host Version 5.6
Copyright (C) Microsoft Corporation 1996-2001. All rights reserved.
AspMaxRequestEntityAllowed : (INTEGER) 104857600
4. Run iisreset /restart to restart the web services & for the changes to come into effect.
You can confirm the changes by checking the ASPMaxRequestEntityAllowed using the GET command [as in step 2]:
C:\Inetpub\AdminScripts>cscript adsutil.vbs get w3svc/ASPMaxRequestEntityAllowed
Microsoft (R) Windows Script Host Version 5.6
Copyright (C) Microsoft Corporation 1996-2001. All rights reserved.
ASPMaxRequestEntityAllowed : (INTEGER) 104857600
The example above updates the metabase.xml file & sets the maximum uploadable value to 100MB
1. At a command prompt, type the following command, & then press ENTER:
cd C:\Inetpub\AdminScripts
cscript adsutil.vbs get w3svc/ASPMaxRequestEntityAllowed
Microsoft (R) Windows Script Host Version 5.6
Copyright (C) Microsoft Corporation 1996-2001. All rights reserved.
ASPMaxRequestEntityAllowed : (INTEGER) 204800
3. Now to change the value to any higher one, run the following command:
cscript adsutil.vbs set w3svc/ASPMaxRequestEntityAllowed size
In this command, size is a placeholder for the largest file size upload that you want to allow. The maximum value is 1,073,741,824 bytes. Set this value to the lowest possible value that allows for the functionality that you want.
To change the value to 100MB, run the following command:cscript adsutil.vbs set w3svc/AspMaxRequestEntityAllowed 104857600
Microsoft (R) Windows Script Host Version 5.6
Copyright (C) Microsoft Corporation 1996-2001. All rights reserved.
AspMaxRequestEntityAllowed : (INTEGER) 104857600
You can confirm the changes by checking the ASPMaxRequestEntityAllowed using the GET command [as in step 2]:
Microsoft (R) Windows Script Host Version 5.6
Copyright (C) Microsoft Corporation 1996-2001. All rights reserved.
ASPMaxRequestEntityAllowed : (INTEGER) 104857600
Subscribe to:
Posts (Atom)