Thursday, 29 September 2016

Add Print Option to SharePoint Page to print one particular web Part using Content Editor Web Part

Add Print Option to SharePoint Page to print one particular web Part using Content Editor Web Part


Add Print Option to SharePoint Page to print one particular web Part using Content Editor Web Part

When the javascript code point to a particular Web Part by its web part ID, then the print option will try to print only the chosen web part.

<input type="button" ID="printBtn1" OnClick="javascript:void(PrintWebPart())" value="Print only tranSMART WebPart">

<script language="JavaScript">

//Controls which Web Part or zone to print
var WebPartElementID = "WebPartWPQ2";

//Function to print Web Part
function PrintWebPart()
{
var bolWebPartFound = false;
if (document.getElementById != null)
{
//Create html to print in new window
var PrintingHTML = '<HTML>\n<HEAD>\n';
//Take data from Head Tag
if (document.getElementsByTagName != null)
{
var HeadData= document.getElementsByTagName("HEAD");
if (HeadData.length > 0)
PrintingHTML += HeadData[0].innerHTML;
}
PrintingHTML += '\n</HEAD>\n<BODY>\n';
var WebPartData = document.getElementById(WebPartElementID);
if (WebPartData != null)
{
PrintingHTML += WebPartData.innerHTML;
bolWebPartFound = true;
}
else
{
bolWebPartFound = false;
alert ('Cannot Find Web Part');
}
}
PrintingHTML += '\n</BODY>\n</HTML>';
//Open new window to print
if (bolWebPartFound)
{
var PrintingWindow = window.open("","PrintWebPart", "toolbar,width=800,height=600,scrollbars,resizable,menubar");
PrintingWindow.document.open();
PrintingWindow.document.write(PrintingHTML);

// Open Print Window
PrintingWindow.window.print();
PrintingWindow.document.close();

}
}
</script>

We can find the web part ID by viewing the source of a page.

Leave your comments below.








Add Print Option to SharePoint Page using Content Editor Web Part

Add Print Option to SharePoint Page

Print option can be added to a content Editor Web Part. This will enable Printing of all content within a SharePoint Page without the top part and left navigation.

<script type="text/javascript" src="http://sample.com/sites/test/JSFiles/jquery-1.4.2.min.js"></script>

<div>
<input id="printBtn" type="button" Value="Print all WebParts" alt="Print this page" style="margin-top:10px;margin-left:10px;"/>
</div>

<script>

$(document).ready(function()
{
var strlink="";
$("link[rel='stylesheet']").each(function()
{
strlink+="<link rel = 'stylesheet' href='"+$(this).attr('href')+"' type='text/css'/>";
});

$("#printBtn").click(function()
{

var htmlStr ="<html><head>"+strlink+"</head><body>"+$("#MSO_ContentTable").parent().html()+"</body></html>";

var PrintingWindow = window.open("about:blank","","toolbar,width=800,height=600,scrollbars,resizable,menubar");

PrintingWindow.document.open();
PrintingWindow.document.write(htmlStr);
PrintingWindow.document.close();
PrintingWindow.focus();
PrintingWindow.document.getElementById("printBtn").style.display="none";
PrintingWindow.print();

});

});
</script>

Leave your comments below.










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>