Thursday, 21 July 2016

Only Number  allowed using Javascript


 function onlyNumbers(evt) {
        var charCode;
        if (window.event)
            charCode = window.event.keyCode;   //if IE
        else
            charCode = evt.which; //if firefox
        if (charCode > 31 && (charCode < 48 || charCode > 57)) {
            alert("Please Enter Only Numeric Value");
            return false;
        }
        return true;
    }



    function ValidateText(i) {
        if (i.value.length > 0) {
            i.value = i.value.replace(/[^\d]+/g, '');
        }
    }

Call :-

<asp:TextBox ID="txtSoWValue" runat="server" onkeyup="javascript:ValidateText(this)"   onkeypress="return onlyNumbers(event);"  CssClass="left" Style="width: 28%;"></asp:TextBox>


Only Number and Character and space also allowed using Javascript

    function ValidateText(i) {
        if (i.value.length > 0) {        
            i.value = i.value.replace(/[!@#$%^&<>?:;|,/]/g, "");
        }
    }


Only Number and Character allowed using Javascript

    function ValidateText(i) {
        if (i.value.length > 0) {
            i.value = i.value.replace(/[^A-Z0-9]+/ig, '');          
        }
    }

Call :-

<asp:TextBox ID="txtWBSID" runat="server" MaxLength="25"  onkeyup="javascript:ValidateText(this)"  ></asp:TextBox>


Check the length of character

    function CheckTextLength(text, long) {
        var maxlength = new Number(long); // Change number to your max length.
        if (text.value.length > maxlength) {
            text.value = text.value.substring(0, maxlength);
            alert(" Only " + long + " Characters Allowed");
        }
    }

Call :-

<asp:TextBox ID="txtFinanceRemarks" runat="server" TextMode="MultiLine" Width="900px"  placeholder="Maximum 500 Characters" onKeyUp="CheckTextLength(this,500)" onChange="CheckTextLength(this,500)" ></asp:TextBox>                

onChange="CheckTextLength(this,500)"

Wednesday, 13 July 2016

To Invisible the Active Directory User


To Invisible the Active Directory User

$cpm = Get-SPClaimProviderManager
$ad =  get-spclaimprovider -identity "AD"
$ad.Invisible = $False
$cpm.Update()

Tuesday, 12 July 2016

PowerShell Command for getting the backup of WSP


PowerShell Command for getting the backup of WSP 

$FolderPath = "z:\Solutions\12July2016"
foreach ($solution in Get-SPSolution)
{
   $id = $Solution.SolutionID
   $title = $Solution.Name
   $filename = $Solution.SolutionFile.Name
   $solution.SolutionFile.SaveAs("$FolderPath\$filename")
}  

Saturday, 19 March 2016

Project Name Start with "001"


Project Name Start with "001"

        public string GetProjectClientName(string URL, string ProjectClientName)
        {
            string strProjectCode = string.Empty;
            try
            {
                DataTable datatable = null;
                datatable = new DataTable();
                SPSecurity.RunWithElevatedPrivileges(delegate()
                {
                    using (SPSite osite = new SPSite(URL))
                    {
                        using (SPWeb oweb = osite.OpenWeb())
                        {
                            SPList oSpList = oweb.Lists.TryGetList(Utilities.ListNames.lstProjects);
                            {
                                if (oSpList != null)
                                {
                                    SPQuery oSpQuery = new SPQuery();
                                    oSpQuery.Query = @"<Where>                                
                                                        <Eq>
                                                            <FieldRef Name='ProjectClientName' />
                                                            <Value Type='Text'>" + ProjectClientName + @"</Value>
                                                        </Eq>                                        
                                                     </Where><OrderBy><FieldRef Name='ID' Ascending='False' /></OrderBy>";
                                    oSpQuery.ViewFields = string.Concat("<FieldRef Name='IBSProjectCode' />");
                                    datatable = oSpList.GetItems(oSpQuery).GetDataTable();
                                    if (datatable != null && datatable.Rows.Count > 0)
                                    {
                                        strProjectCode = Convert.ToString(datatable.Rows[0][0]);
                                        int ProjectCode = Convert.ToInt32(strProjectCode.Substring(strProjectCode.Length - 3));
                                        ProjectCode = ProjectCode + 1;
                                        if (Convert.ToString(ProjectCode).Length == 1)
                                        {
                                            ProjectClientName = GetFirstFourCharacters(Regex.Replace(ProjectClientName.ToUpper(), @"\s+", ""));
                                            ProjectClientName = ProjectClientName + "00" + ProjectCode;
                                        }
                                        else if (Convert.ToString(ProjectCode).Length == 2)
                                        {
                                            ProjectClientName = GetFirstFourCharacters(Regex.Replace(ProjectClientName.ToUpper(), @"\s+", ""));
                                            ProjectClientName = ProjectClientName + "0" + ProjectCode;
                                        }
                                    }
                                    else
                                    {
                                        ProjectClientName = GetFirstFourCharacters(Regex.Replace(ProjectClientName.ToUpper(), @"\s+", ""));
                                        ProjectClientName = ProjectClientName + "001";
                                    }
                                    strProjectCode = ProjectClientName;
                                }
                            }
                        }
                    }
                });
            }
            catch (Exception ex)
            {
                throw ex;
            }
            return strProjectCode;
        }

Remove the special Character from string AND Get first four characer from string.

Remove the special Character from string. AND Get first four characer from string.

        public string RemoveSpecialChars(string str)
        {
            string[] chars = new string[] { ",", ".", "/", "!", "@", "#", "$", "%", "^", "&", "*", "'", "\"", ";", "_", "(", ")", ":", "|", "[", "]", "=", "==" };
            for (int i = 0; i < chars.Length; i++)
            {
                if (str.Contains(chars[i]))
                {
                    str = str.Replace(chars[i], "");
                }
            }
            return str;
        }

Get first four characer from string.

        public string GetFirstFourCharacters(string s)
        {
            return (s.Length < 4) ? s : s.Substring(0, 4);
        }

Monday, 7 March 2016

Update Panel Timeout in Chrome

Update Panel Timeout in Chrome


Use below links
https://social.msdn.microsoft.com/Forums/sqlserver/en-US/c33d4a46-87d6-4dbc-a24c-cb8e5f9eb1ea/page-refresh-after-postback-from-updatepanel-in-sharepoint-2013?forum=sharepointdevelopment


Please script on page

<script type="text/javascript">
    $(document).ready(
    function () {
        ExecuteOrDelayUntilBodyLoaded(function () {
            try {
                if (Sys.WebForms.PageRequestManager.getInstance().digestFixed !== true) {
                    Sys.WebForms.PageRequestManager.getInstance().digestFixed = true;
                    Sys.WebForms.PageRequestManager.getInstance().add_beginRequest(function () {
                        if (typeof (UpdateFormDigest) === "function" && typeof (_spPageContextInfo) === "object")
                            UpdateFormDigest(_spPageContextInfo.webServerRelativeUrl, 3 * 60 * 1000);
                    });
                }
            }
            catch (e) { }
        });
    });
</script>



Tuesday, 5 January 2016

Difference between two dates

Difference between two dates

http://jsfiddle.net/mikeys4u/3TA4s/1/


<input type="text" id="startdate">
<input type="text" id="enddate">
<input type="text" id="days">

<script src="https://code.jquery.com/jquery-1.8.3.js"></script>
<script src="https://code.jquery.com/ui/1.10.0/jquery-ui.js"></script>
<link rel="stylesheet" href="http://code.jquery.com/ui/1.10.3/themes/redmond/jquery-ui.css" />
<script>
$(document).ready(function() {

$( "#startdate,#enddate" ).datepicker({
changeMonth: true,
changeYear: true,
firstDay: 1,
dateFormat: 'dd/mm/yy',
})

$( "#startdate" ).datepicker({ dateFormat: 'dd-mm-yy' });
$( "#enddate" ).datepicker({ dateFormat: 'dd-mm-yy' });

$('#enddate').change(function() {
var start = $('#startdate').datepicker('getDate');
var end   = $('#enddate').datepicker('getDate');

if (start<end) {
var days   = (end - start)/1000/60/60/24;
$('#days').val(days);
}
else {
alert ("You cant come back before you have been!");
$('#startdate').val("");
$('#enddate').val("");
$('#days').val("");
}
}); //end change function
}); //end ready
</script>