Posts

Showing posts from June 20, 2015

Get Current Year From Created by Column

=IF([Created]="","",""&YEAR([Created]))

Get multiple users into a array of single SPListItem

string [] delimit = new string [] { ";#" }; DataRow dr = dt.NewRow(); string [] stringarray = item[ "TargetAudience" ].ToString().Split((delimit), StringSplitOptions .RemoveEmptyEntries); StringBuilder sb = new StringBuilder (); for ( int i = 0; i < stringarray.Length; i++) {     if (i % 2 != 0)     {         sb.Append(stringarray[i].ToString()+ "," );     } }

Remove last letter from the stirng Ex: test1, test2, test3, ß--- it willremove the last comma of the string

myString = myString . substr ( 0 , myString . length - 1 ) + '.' ;

It Gives mail to functionality if we click on the link it will automatically opens the send mail box

<a href=mailto:' + empEmailId + '>' + empEmailId + '</a>

Deployment Commands

Backup-SPSite -Identity "http://uscin2012v3:1234/sites/dev/" -Path "C:\Working\26thNov2014\cp.bak" -NoSiteLock Restore-SPSite -Identity "http://uscin2012v3:1234/sites/dev/" -Path "C:\Anil\25thFeb2015\cp.bak" Restore-SPSite http://uscin2012v3:1234/sites/dev1/ -Path C:\Anil\25thFeb2015\cp.bak

This url gives the list of wsp deployed in that site collection, if you dnt have CM this is way to know your wsp

http://uscin2012v3:5555/_catalogs/wp/Forms/AllItems.aspx

It gives the hidden users list in that particular site collection

http://uscin2012v3:5555/_catalogs/users/simple.aspx  

script will hide all the shareppoint default icons

$(document).ready(notRequiredElement); function notRequiredElement() {     $("a[id$='_share_button']").css("display", "none");     $("a[id$='_SyncPromotedAction']").css("display", "none");     $("a[id$='_follow_button']").css("display", "none");      $("a[id$='_SiteActionsMenu']").css("display", "none");       $("a[id$='_TopHelpLink']").css("display", "none");       $("a[id$='_fullscreenmodeBtn']").css("display", "none"); }

line of code is for Compaing to arrays

bool isExists = profileTagArray.SequenceEqual(ProfiletagformValue); 

Below line of code give you the array valu in sort order.

Array .Sort(ProfiletagformValue );//output 0 Dotnet                                          1 Hr                                          2 SharePoint   Array .Sort(profileTagArray);

code gives you SPFieldLookupValueCollection in array format

SPFieldLookupValueCollection fieldValues1 = new SPFieldLookupValueCollection (); foreach ( Control ctrl in PnlProfileTags.Controls )// Form Control Id {     CheckBox cb = ctrl as CheckBox ;     if (cb != null )     {         if (cb.Checked)         {             int TageID = Convert .ToInt32(cb.ID.Substring(4));   var TagItm = web.Lists[listTags.Title].GetItemById(TageID);  fieldValues1.Add( new SPFieldLookupValue (TagItm.ID, TagItm.Title));          }      }  } List < string > strValues = new List < string >();   foreach ( var item in fieldValues1)  {      strValues.Add(item.ToString().Split( '#' )[1]);  }   string [] ProfiletagformValue = strValues.ToArray(); // output 0 SharePoint                                                               1 Dotnet                                                               2 Hr           

Below code gives you how to bind Hyperlink field Using ECMA

var hyperValue = new SP.FieldUrlValue(); hyperValue.set_url( "/sites/Assetmgmt/SitePages/DisplayUserAccCretn.aspx?IID=" + idValue); hyperValue.set_description( "View" ); oListItem.set_item( "View" , hyperValue);

Getting Values from List using SP services

$().SPServices({ operation: "GetListItems" , async: false , listName: "User Account Requests" , CAMLRowLimit: "<RowLimit>1</RowLimit>" , CAMLQuery: '<Query><OrderBy><FieldRef Name="ID" Ascending="False" /></OrderBy></Query>' ,         completefunc: function (xData, Status) {             //alert(Status);             //alert(xData.responseText);             $(xData.responseXML).SPFilterNode( "z:row" ).each( function () {                // debugger;                 reqID = $( this ).attr( "ows_ID" );   //alert(getlistitemID);             });         }     });

Below one line Code is for reduce the width of PPL picker

$( "[id$=_ pplReportingTo_OuterTable ]" ).css( "width" , "187px" );Keep your PPl Picker Control     ID

Get Query String value using ECMA Script.

function getQueryStringValue(name) {     var queryStrJson = $.parseJSON( "{\"" + window.location.search.substring(1).replace( /&/g , ",\"" ).replace( /=/g , "\":" ) + "}" );     return queryStrJson[name]; }

Get date value as specified format like 10/27/2015

function convertToDateFormat(Datevalue) {     if (Datevalue != null ) {         var d = Datevalue;         var n = d.getMonth();         var n1 = d.getFullYear();         var n2 = 1;         var n3 = d.getDate();         var day = +n3 + +n2;         var x = +n + +n2;         curdate = x + '/' + day + '/' + n1;         return curdate;     } }

Get checkbox checked values using ECMA Script

function getCheckBoxselectedControl(controlName) {     var favorite = "" ;     $.each($( "input[name=" + controlName + "]:checked" ), function () {         favorite += ($( this ).val()) + "," ;     });     return favorite; }

Get Multiple list Data using ECMA in a Single Hit.

function GetRegisteredSoft() {     // debugger;     clientContext = new SP.ClientContext.get_current();     var camlQuery = SP.CamlQuery.createAllItemsQuery();     $.each(list, function (index, lstName) {         // debugger;         var oList = clientContext.get_web().get_lists().getByTitle(lstName);         $( "body" ).data(lstName, oList.getItems(camlQuery));         clientContext.load($( "body" ).data(lstName));     });     clientContext.executeQueryAsync(        Function.createDelegate( this , this .retrieveSoftwareInfoListItemsSuccess),        Function.createDelegate( this , this .retrieveSoftwareInfoListItemsFail)); } function retrieveSoftwareInfoListItemsSuccess() {     //debugger;     $.each(list, function (index, lstName) {         //debugger;         var result = $( "body" ).data(lstName);         var empBasicInfoListItemEnumerator = result.getEnumerator();         while (empBasicInfoListI