Saturday, 19 March 2016

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>

Tuesday, 27 October 2015

LINKS

Links:-

https://msdn.microsoft.com/en-us/library/ee539350.aspx
https://msdn.microsoft.com/en-us/library/ee535717.aspx
https://msdn.microsoft.com/en-us/library/ee539429.aspx

http://www.learningsharepoint.com/2011/04/13/sharepoint-2010-object-model-tutorial-iii/
http://www.learningsharepoint.com/sharepoint-2010-ecmascriptjavascript-client-object-model-tutorialsamples/
http://expert-sharepoint.blogspot.in/2015/06/sharepoint-client-object-model.html
http://expert-sharepoint.blogspot.in/2015/06/create-new-sharepoint-website-using.html

Usefull Java Script

1.Only Numeric value with one dot like 10.50:-

    function isNumber(evt, element) {

        var charCode = (evt.which) ? evt.which : event.keyCode

        if (
            (charCode != 45 || $(element).val().indexOf('-') != -1) &&      // “-” CHECK MINUS, AND ONLY ONE.
            (charCode != 46 || $(element).val().indexOf('.') != -1) &&      // “.” CHECK DOT, AND ONLY ONE.
            (charCode < 48 || charCode > 57))
            return false;

        return true;

    }

Call the above method   onkeypress="return isNumber(event,this);"

2.Only Numeric value:-

    <script type="text/javascript">
        function numvalidate(text) {
            // numeric with decimal
            //var test_str = /(?!^0*$)(?!^0*\.0*$)^\d{1,9}(\.\d{1,2})?$/
            // only numeric value
            if (test_str.test(text.value))
            {
                if (text.value > 10000000)
                {
                    alert("Please enter a valid Amount.");
                    text.focus();
                    return false;
                }
                return true;
            }
            else {
                if (text.value == "")
                    return true;
                alert("Please enter a valid Amount.");
                text.focus();
                return false;
            }
        }

    </script>
Call below
                  <td>
                    <asp:TextBox ID="txtAmountLTC" runat="server" Text="" onblur="return numvalidate(this);" ToolTip="Only decimal value"></asp:TextBox>                  
                </td>


3. "Only nemeric with two decimal values allowed for ex. 5.23"

  <script type="text/javascript">

function QtyNPrice(me) {
            var str = me.value;
            var regexstr = /^[0-9]{1,12}(\.[0-9]{1,2})?$/;
            if (!str.match(regexstr) && str.length > 0) {
                alert("Only nemeric with two decimal values allowed for ex. 5.23");
                me.focus();
            }
        }
 </script>
  <asp:TextBox ID="txtAmountLTC" runat="server" Text="" onblur="QtyNPrice(this);" ToolTip="Only decimal value"></asp:TextBox>


4. Confirmation message by client side code
    <script type="text/javascript">
        function ConfirmMsg(msg)
      {
            var r = confirm(msg);
            if (r == true) {
                return true;
            }
            else {
                return false;
            }
        }  
    </script>
<asp:Button ID="btnResetAll" runat="server" Text="Reset All" onclick="btnResetAll_Click"
                    OnClientClick="return ConfirmMsg('Are you sure you want to reset this page?');" TabIndex="13" />


5. Valid PAN number
    <script type="text/javascript">
 function validatePANNo(idPAN) {
        var obj = document.getElementById(idPAN);
        //if (!validateTextBox(idPAN, 'Please enter PAN number')) { return false; }
        var regexstr = /[A-Za-z]{5}\d{4}[A-Za-z]{1}/; var str = obj.value;
        if (trim(str).length > 0 && trim(str).length < 11) {
            if (!str.match(regexstr)) { alert("Please enter valid PAN."); obj.focus(); return false; }
            else { return true; }
        }
        else {
            alert("Please enter valid PAN."); obj.focus(); return false;
        }
    }
    </script>

               <td>
                <span>PAN</span>
            </td>
            <td>
                <asp:TextBox ID="txtPAN" runat="server" Text="" onblur="javascript:return validatePANNo('txtPAN'); "></asp:TextBox>
            </td>

6. Only alphanumeric values are allowed.
<script type="text/javascript">
function isAlphanumeric(me) {
        if (me.value.length > 0) {
            var regexstr = /[^a-z 0-9.-\/\\ A-Z]/; regexstr.multiline = true; var str = me.value;
            if (str.match(regexstr)) { alert("Only alphanumeric values are allowed."); me.focus(); me.select(); return false; }
        } return true;
    }
    </script>
<td>
                <span>Company Name</span>
            </td>
            <td>
                <asp:TextBox ID="txtCompany" runat="server" Text="" onblur="javascript:return isAlphanumeric(this);" Width="98%" BorderWidth="0px" ReadOnly="true"></asp:TextBox>
            </td>


7. Mobile number 
<script type="text/javascript">
function isMobileNumber(me) {
        if (me.value.length > 0) {
            var regexstr = /[^0-9]/;
            var str = me.value;
            if (me.value.length > 10 || (str.match(regexstr))) {
                alert("Only 10 digit mobile number is allowed");
            }
        }
    }
    </script>
<td>
                <span>Mobile No.</span>
            </td>
            <td>
                <asp:TextBox ID="txtMobile" runat="server" onblur="javascript:return isMobileNumber(this);"></asp:TextBox>
            </td>

8.Count the Grid Row
<script type="text/javascript">
function grdRowCount(grdID,errMsg)
    {
    try{
      var obj = document.getElementById(grdID);
       if(obj.rows.length<1)
       {
       alert(errMsg);
       return false;
       }
       else
       {
       return true;
       }
       }
       catch(err){
       alert(errMsg);
       return false;
       }
    }
    </script>

9.trim the String

  function trim(str) {
        str = str.replace(/^\s+/, '');
        for (var i = str.length - 1; i >= 0; i--) {
            if (/\S/.test(str.charAt(i))) { str = str.substring(0, i + 1); break; }
        } return str;
    }

10. Clear All controls of Div

    function ClearAllControls(divName) {
        var searchEles = document.getElementById(divName).children;
        for (var i = 0; i < searchEles.length; i++) {
            if (searchEles[i].tagName == 'INPUT') doc.value = "";
            if (searchEles[i].tagName == 'SELECT') doc.selectedIndex = 0;
        }
    }


 11.   function isAlphabetBorrower(me) {
        if (me.value.length > 0) {
            var regexstr = /[^a-z ,. A-Z]/; var str = me.value;
            if (str.match(regexstr)) { alert("Only alphabets and (,) are allowed."); me.focus(); me.select(); return false; }
        } return true;
    }
       function isNumericBorrower(me) {
        if (me.value.length > 0) {
            var regexstr = /[^0-9,]/; var str = me.value;
            if (str.match(regexstr)) { alert("Only Numeric and (,) are allowed without space."); me.focus(); me.select(); return false; }
        } return true;
    }




Tuesday, 15 September 2015

Read the Excel file

Config File :-      <add key ="Excel07ConString"  value="Provider=Microsoft.ACE.OLEDB.12.0;Data Source={0}; Extended Properties='Excel 12.0 Xml;HDR=YES';"/>


    <add key="sourceDirPath" value="D:\BIO10_DATA\PRD\SAP2INET\EmployeeMaster" />



string strSourcedirPath = ConfigurationManager.AppSettings["sourceDirPath"].ToString();

 try
            {
                FileInfo f = new FileInfo(ExcelFilePath);
                string FileName = Path.GetFileName(f.Name);
                string Extension = Path.GetExtension(f.Name);

                string conStr = "";
                switch (Extension)
                {
                    case ".xls": //Excel 97-03
                        conStr = ConfigurationManager.AppSettings["Excel03ConString"].ToString();
                        break;
                    case ".xlsx": //Excel 07
                        conStr = ConfigurationManager.AppSettings["Excel07ConString"].ToString();                  
                        break;
                }
                //string ConnStr = "Provider=Microsoft.ACE.OLEDB.12.0;Data Source=" + ExcelFilePath + "; Extended Properties='Excel 12.0 Macro;HDR=NO';";
                conStr = String.Format(conStr, ExcelFilePath);


                //OleDbConnection con = new OleDbConnection(conStr);
                //string strquery = "select * from [Sheet1$]";
                //OleDbDataAdapter oledbDA = new OleDbDataAdapter(strquery, con);
                //DataTable dt = new DataTable();
                //oledbDA.Fill(dt);



                //OleDbConnection connExcel = new OleDbConnection(conStr);
                //OleDbCommand cmdExcel = new OleDbCommand();
                //OleDbDataAdapter oda = new OleDbDataAdapter();
                //DataTable dtExcel = new DataTable();
                //cmdExcel.Connection = connExcel;
                //connExcel.Open();
                //DataTable dtExcelSchema;
                //dtExcelSchema = connExcel.GetOleDbSchemaTable(OleDbSchemaGuid.Tables, null);
                //string SheetName = dtExcelSchema.Rows[0]["TABLE_NAME"].ToString();          
                //cmdExcel.CommandText = "SELECT * From [" + SheetName + "]";
                //oda.SelectCommand = cmdExcel;
                //oda.Fill(dtExcel);

                OleDbConnection con = new OleDbConnection(conStr);
                //string connectionString = @"Provider=Microsoft.ACE.OLEDB.12.0;Data Source=" + ExcelFilePath + ";Extended Properties='Excel 12.0 Xml;HDR=YES'";
                //OleDbConnection con = new OleDbConnection(connectionString);
                string strquery = "select * from [Sheet1$]";
                OleDbDataAdapter oledbDA = new OleDbDataAdapter(strquery, con);
                DataTable dt = new DataTable();
                oledbDA.Fill(dt);

  }
            catch (Exception e)
            {
                Console.WriteLine(e.Message.ToString());
                Console.ReadKey();
            }




Thursday, 6 August 2015

hide some of the FormMenuItem Buttons on a New, Display or Edit form in SharePoint List 2007

To hide some of the FormMenuItem Buttons on a New, Display or Edit form in SharePoint is very easy.







All you have to do is to add a bit of Javascript to the form. You can quickly do this via the SharePoint designer.

Open the form on which you want to hide the menu item button in SharePoint Designer. Once opened switch to code view.



















Once you have the code view open, find the PlaceHolderBodyAreaClass section and insert the following code:

<script type="text/javascript"> 
  alert('Hello');
</script>










Save the form and hit F12 to view in browser.
You should now see an alert message popup when you access the form.
If you go the following message then it means that your Javascript is executing without any problems and that you can now proceed to add the relevant code to hide the desired buttons. 
  
  
  
  
  
  
  
  
  
  
  
So, in SharePoint Designer, at the same location where you added the Javascript code, replace the following code: 
<script type="text/javascript"> 

alert('Hello');
</script>
with:
<script type="text/javascript"> 

  hideFormMenuItems("Delete Item");


  function hideFormMenuItems()
  { 
   var titleToHide="";
   var anchorTag;
   var allAnchorTags = document.getElementsByTagName('a');
   for(var i = 0; i < hideFormMenuItems.arguments.length; i++ ) 
   { 
    titleToHide = hideFormMenuItems.arguments[i]; 
    if(titleToHide!='Alert Me')
    {
     for (var j = 0; j < allAnchorTags.length; j++)
     {
      anchorTag= allAnchorTags[j]; 
      if (anchorTag.title.indexOf(titleToHide)!=-1)
      { 
anchorTag.parentNode.parentNode.parentNode.parentNode.parentNode.style.display="none";
anchorTag.parentNode.parentNode.parentNode.parentNode.parentNode.nextSibling.style.display="none"; 
       break;
      }
     }
    }
    else
    {
     for (var k=0; k < allAnchorTags.length;k++)
     {
      anchorTag= allAnchorTags[k]; 
      if (anchorTag.id.indexOf("SubscribeButton")!=-1)
      { 
anchorTag.parentNode.parentNode.parentNode.parentNode.parentNode.style.display="none";
       break;
      }
     }
    }
   }
  var allSpanTags = document.getElementsByTagName("span"); 
  var spanTag;
  var toolbarRow;
  var lastCell;
  for(var m=0; m < allSpanTags.length;m++)
  {
   spanTag = allSpanTags[m];
   if(spanTag.id=='part1')
   {
    toolbarRow = spanTag.childNodes[2].firstChild.firstChild;
    lastCell = toolbarRow.lastChild.previousSibling 
    while(lastCell.style.display=='none')
    { 
     lastCell = lastCell.previousSibling; 
    } 
    if(lastCell.innerText == '')
    { 
     lastCell.style.display='none'; 
    } 
    break; 
   }
  }
 }
</script>


So, when done, save your form and run.... you will see the "Delete Item" button is hidden.
You can now add more javascript to only hide the button based on certain conditions.



Enjoy!!