Skip to main content

Posts

Create a mailto htm with no character limit.

The HTML standard for the mailto link is 256 characters. You can get around this by loading the JavaScript redirect instead. var  body = escape(window.document.title + String.fromCharCode(13) + window.location.href + " actully  a Your long text here..." ); body = body.replace( /\//g ,  "%2F" ); body = body.replace( /\?/g ,  "%3F" ); body = body.replace( /=/g ,  "%3D" ); body = body.replace( /&/g ,  "%26" ); body = body.replace( /@/g ,  "%40" ); var  subject =  "Take a look at this!" ; window.location.href =  "mailto:?body="  + body +  "&subject="  + subject;

Get Sum of Columns in a SharePoint list (Threshold edition)

It is a known fact that once the treshold limit is reached in SP, everything seems frozen.  At this point you have some options. Increase the limit using powershell or from the Central Admin OR Index the columns that you will like to operate on and create views based on those. However programmatically if you want to sum a list that has reached its threshold.  You can do so in batches as hown below:          protected   void  GetSummary( out   long  ideas,  out   long  votes,  out   long  comments,  out   long  transform)         {              long  ideasum = 0;              long columntoSum = 0;              long  commentS...

Get the latest ID from a SharePoint list

  public   int MaximumID()         {              SPQuery  query =  new   SPQuery ();             query.Query =  " " ;             query.RowLimit = 1;              SPListItemCollection  items =  SPContext .Current.Site.RootWeb.Lists[ "ListName" ].GetItems(query);              int  maxId =  Convert .ToInt32(items[0][ "ID" ]);              return  maxId;         }

Create a jQuery alert programmatically

From the code behind:   Assuming you have jquery on your page already.   StringBuilder  strScriptFeatured =  new   StringBuilder (); strScriptFeatured.Append( "$(document).ready(function(){" ); strScriptFeatured.Append( "alert('Your alert here!');" ); strScriptFeatured.Append( "});" ); Page.ClientScript.RegisterStartupScript( this .GetType(),  "Script" , strScriptFeatured.ToString(),  true );   QED  

Create a random item in a list

To create a random item in a SharePoint list:     private   static   SPListItem  GetRandomItem( SPListItemCollection  list) { var  theIDs =  new   List < int >(); foreach  ( SPListItem  item  in  list) { theIDs.Add(item.ID); } theIDs.Shuffle(); Int32 val = theIDs.FirstOrDefault(); SPListItem  randomItem = list.GetItemById(val); return  randomItem; }   The randomization is done here:           public   static   void  Shuffle ( this   IList  list)         {              var  randomNumber =  new   Random (DateTime.Now.Millisecond);              var  n = list.Count;   ...