Tuesday, 29 April 2014

Add Jquery and SP Services to debug from Console Tool

Use below source code to insert JQuery and SP Services from developer console:

var jq1 = document.createElement('script');
jq1.src = "//ajax.googleapis.com/ajax/libs/jquery/1.10.2/jquery.min.js";
document.getElementsByTagName('head')[0].appendChild(jq1);
 var jq2 = document.createElement('script');
jq2.src = "//cdnjs.cloudflare.com/ajax/libs/jquery.SPServices/2014.01/jquery.SPServices.min.js";
document.getElementsByTagName('head')[0].appendChild(jq2);


Now, It will appear in page source:




Now, you can use SPServices easily from developer console.

Enjoy Debugging :)

Monday, 21 April 2014

To Get All SharePoint designer enabled web application using Power Shell and Email to Users

#To get All Web Application to which SharePoint Designer is Activated

$CentAdm = Get-SPWebApplication -includecentraladministration | where {$_.DisplayName -eq "SharePoint Central Administration v4"}| Select Url;

$CentAdm1 = Get-SPAlternateURL -WebApplication $CentAdm.url -Zone Intranet
#Write-Host $CentAdm1.PublicUrl;
$CentAdm2 = "$($CentAdm1.PublicUrl)/_admin/WebApplicationList.aspx";
#Write-Host $CentAdm2;

####get all services for web applications
$contentWebAppServices = (Get-SPFarm).services |
? {$_.typename -eq "Microsoft SharePoint Foundation Web Application"}

$Temp="<html><body style='font-family: calibri; font-size: 10pt; '><table style='border: 1px solid black; background: #E5E4E2;'><th >Activated Web Application</th>";

foreach($webApp in $contentWebAppServices.WebApplications)
{
#####get designer enabled web application
if ($webApp.AllowDesigner -eq "true")
 {
   $Temp +="<tr><td  style = 'border: 1px solid black;  padding: 5px;'>  $($webApp.DisplayName)  </td><td  style = 'border: 1px solid black;  padding: 5px;'>  $($webApp.url)  </td></tr>";          
 }
}
$Temp+="</table></body></html>";

$smtp = "smtp.something.something"

$to = "abc123.gmail.com","abc1234.gmail.com","abc12345.gmail.com"

$cc = "abc129.gmail.com","abc1275.gmail.com"

$from = "abc.dummyorg.com"

$subject = "Designer Activated Web Applications" 

$body = "<span style='font-family: calibri; font-size: 11pt;'>Below are the Web Application's on which SharePoint Designer is Activated. </span> <br><br> "

$body += $Temp

$body +=  "<br><p style='font-family: calibri; font-size: 11pt;'>Please click <a href=$CentAdm2>Here</a>  to deactivate SharePoint designer </p>"

$body += "<br><p style='font-family: calibri; font-size: 12pt;'>This is system generated email, please do not reply!</p>"


####send the email using \> Send-MailMessage  
send-MailMessage -SmtpServer $smtp -To $to -Cc $cc -From $from -Subject $subject -Body $body -BodyAsHtml -Priority high 



####Final Result will be displayed as below.

Sunday, 20 April 2014

Script to get currently logged in user's badge status in SharePoint 2013

Script to get currently logged in user's badge status in SharePoint 2013

function getListItems(){
        var context = new SP.ClientContext.get_current();
        var list = context.get_web().get_lists().getByTitle('Community Members');
        var query = SP.CamlQuery.createAllItemsQuery();
        listItems = list.getItems(query);
        context.load(listItems);
        context.executeQueryAsync(onLoadItemsSuccess, onLoadItemsFail);
    }

    function onLoadItemsFail(sender, args) {
       curUserTitle =  args.get_message();
    }

    function onLoadItemsSuccess(sender, args) {
        var listEnumerator = listItems.getEnumerator();
        var item;
        while (listEnumerator.moveNext())  {
            item = listEnumerator.get_current();
if(curUserTitle.toLowerCase() === item.get_item('Title').toLowerCase())
{
 curUserBadge = item.get_item('GiftedBadgeText');
 break;
}
            //console.log(item.get_item('Title') + " " + item.get_item('GiftedBadgeLookup') + " " + item.get_item('GiftedBadgeText') );
        }
    }

var curUserTitle = "";
var curUserBadge = "";
function ViewUser() {
            var context = new SP.ClientContext.get_current();
            this.website = context.get_web();
            this.currentUser = website.get_currentUser();
            context.load(currentUser);
            context.executeQueryAsync(Function.createDelegate(this, this.success), Function.createDelegate(this, this.failed));
        }

        function success() {
            curUserTitle = (currentUser.get_title());
getListItems();
        }

        function failed(sender, args) {
             curUserTitle = args.get_message();
        }

//Final Page load call
_spBodyOnLoadFunctionNames.push("ViewUser");



Thursday, 17 April 2014

compare two Resources (.RESX) files using C#

Here is a simple logic to compare two Resources (.RESX) files using C#.

using System;
using System.Collections;
using System.Resources;

namespace ResourceComparer
{
    class Program
    {
        static void Main(string[] args)
        {
            ResXResourceReader rsxr1 = new ResXResourceReader(@"wikiplus.resx");
            ResXResourceReader rsxr2 = new ResXResourceReader(@"wikiplus.de.resx");

            // Iterate through the resources and display the contents
            foreach (DictionaryEntry d1 in rsxr1)
            {
                string value1 = d1.Key.ToString();

                bool secret = false;
                foreach (DictionaryEntry d2 in rsxr2)
                {
                    if (value1.ToString().Equals(d2.Key.ToString(), StringComparison.OrdinalIgnoreCase))
                    {
                        secret = true;
                    }

                    if (secret)
                    {
                        break;
                    }
                }

                if (!secret)
                {
                    Console.WriteLine(d1.Key.ToString());
                }
            }
        }
    }
}

Wednesday, 16 April 2014

Creation of quick alphabetical ladder for SharePoint View



Output result:

We will be getting a filtered data like below, filtered on top of title starting with alphabet.
 

Process to create this:
  • Create a calculated column<<Initial>> in the list having below formula:
=IF(OR(LEFT(Title)<"a",LEFT(Title)>"z"),"other",LEFT(Title))

        Above formula, will extract initial letter from the title text.


 
  • Create a ladder to show 

<table cellpadding=4 cellspacing=0>
<tr>
   <td><a href="#" onClick="showAll(); return false;">All</a></td>
   <td><a href="#" onClick="setFilter('a'); return false;">A</a></td>
   <td><a href="#" onClick="setFilter('b'); return false;">B</a></td>
   <td><a href="#" onClick="setFilter('c'); return false;">C</a></td>
   <td><a href="#" onClick="setFilter('d'); return false;">D</a></td>
   <td><a href="#" onClick="setFilter('e'); return false;">E</a></td>
   <td><a href="#" onClick="setFilter('f'); return false;">F</a></td>
   <td><a href="#" onClick="setFilter('g'); return false;">G</a></td>
   <td><a href="#" onClick="setFilter('h'); return false;">H</a></td>
   <td><a href="#" onClick="setFilter('i'); return false;">I</a></td>
   <td><a href="#" onClick="setFilter('j'); return false;">J</a></td>
   <td><a href="#" onClick="setFilter('k'); return false;">K</a></td>
   <td><a href="#" onClick="setFilter('l'); return false;">L</a></td>
   <td><a href="#" onClick="setFilter('m'); return false;">M</a></td>
   <td><a href="#" onClick="setFilter('n'); return false;">N</a></td>
   <td><a href="#" onClick="setFilter('o'); return false;">O</a></td>
   <td><a href="#" onClick="setFilter('p'); return false;">P</a></td>
   <td><a href="#" onClick="setFilter('q'); return false;">Q</a></td>
   <td><a href="#" onClick="setFilter('r'); return false;">R</a></td>
   <td><a href="#" onClick="setFilter('s'); return false;">S</a></td>
   <td><a href="#" onClick="setFilter('t'); return false;">T</a></td>
   <td><a href="#" onClick="setFilter('u'); return false;">U</a></td>
   <td><a href="#" onClick="setFilter('v'); return false;">V</a></td>
   <td><a href="#" onClick="setFilter('w'); return false;">W</a></td>
   <td><a href="#" onClick="setFilter('x'); return false;">X</a></td>
   <td><a href="#" onClick="setFilter('y'); return false;">Y</a></td>
   <td><a href="#" onClick="setFilter('z'); return false;">Z</a></td>
   <td><a href="#" onClick="setFilter('other'); return false;">Other</a></td>
 </tr>
</table>


  • Add below simple JavaScript snippet, It will filter on click of letters
    <script language="javascript">
    var strUrl = location.href;
    var strFilterField = "Initial";

     function showAll()
     {
           if(strUrl.indexOf("?") > -1)
       {
         strUrl = strUrl.split("?")[0];
       }
       location.href = strUrl;
     }

     function setFilter(strValue)
     {
       if(strUrl.indexOf("?") > -1)
       {
         strUrl = strUrl.split("?")[0];
       }
       location.href = strUrl + "?FilterField1=" +  strFilterField + "&FilterValue1=" + strValue;
     }
    </script>

  • Finally, On click on alphabets data will be displayed: