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­>
<­security­>
<­requestFiltering­>
<­requestLimits maxAllowedContentLength="10485760"­/­>
<­/­requestFiltering­>
<­/­security­>
<­/­system­.­webServer­>

Wednesday, January 30, 2013

Query for fetching the records in Parent-Child DB table in SQL Server

DECLARE @FileTreeId INT = 300 (For instance)

;WITH FileTreeHierarchy AS
(
    SELECT FileTreeID, Company, Parent, Name, 1 AS 'Level'
    FROM FileTree 
    WHERE FileTreeID = @FileTreeId

    UNION ALL

    SELECT F.FileTreeID, F.Company, F.Parent, F.Name, 
    FH.Level + 1 AS 'Level'
    FROM FileTree F
    INNER JOIN FileTreeHierarchy FH ON FH.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>

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