Saturday, 13 September 2014

To show flash type animated word by word message.

To show flash type animated word by word message. we can use below script on window load event.


var myString = "Welcome to the jungle";
var myArray = myString.split("");
var loopTimer;
function frameLooper() {
    if(myArray.length > 0) {
        document.getElementById("home_TypingText").innerHTML += myArray.shift();
    } else {
        clearTimeout(loopTimer); 
        return false;
    }
    loopTimer = setTimeout('frameLooper()',80);
}


window.addEventListener("load", frameLooper());

O/p: Welcome to the jungle

Friday, 1 August 2014

Example of SPService GetListItems with CAML and Deleting items one by one

var CamlQuery = "<Query><Where><Eq><FieldRef Name='List_Column_Internal_Name'/><Value Type='Text'>F</Value></Eq></Where></Query>";
var CamlViewFields = "<ViewFields><FieldRef Name='List_Column_Internal_Name' /></ViewFields>";
$().SPServices({
 operation: "GetListItems",
 webURL: "Web_URL",
 listName: "Scenarios",
 async: false,
 CAMLRowLimit: 1000,
 CAMLQuery: CamlQuery,
 CAMLViewFields: CamlViewFields,
 completefunc: function (xData, Status) {
  var cnt = 1;
  var dCnt = 1;
  $(xData.responseXML).find("z\\:row").each(function () {
   //Delete records
   $().SPServices({
     operation: "UpdateListItems",
     webURL: "Web_URL",
     async: true,
     debug: true,
     batchCmd: "Delete",
     listName: "Scenarios",
     ID: $(this).attr("ows_ID"),
     completefunc: function (xData, Status) {
     console.log(Status + dCnt);
     dCnt = dCnt + 1;
     }
   });
   cnt = cnt + 1;
   });
 }
});

In case, if you are using jQuery 1.7+, the syntax you are using to find the z:row elements no longer works. Use the SPFilterNode function instead.

So the code line $(xData.responseXML).find("z\\:row") will be $(xData.responseXML).SPFilterNode("z:row").

Saturday, 17 May 2014

Issue of Scrollbar not appearing in SharePoint 2013 app when using chrome control

Vertical scroll disappears and content below some height becomes invisible.

Resolution:
Step 1:
Add below line above <<form>> tag as shown below:
 
<div id="divSPChrome"></div>
<form id="form2" runat="server">
 
Step 2:
Add inline class
body {
            overflow-yscroll;
        }
 
        #chromeControl_stylesheet {
            overflowhidden !important;
        }
 
Now, the Scrollbar is displayed as expected.

JS Link in SharePoint 2013

Previously we used to have XSLT for list view customization (Pretty Complex Coding).
Now, JSLink is the new feature introduced in SharePoint 2013 which uses JavaScript to customize list view. 
Reference: http://code.msdn.microsoft.com/office/Client-side-rendering-JS-2ed3538a

Thursday, 15 May 2014

Missing feature issue occurred after migration

This article describes the missing feature issue occurred after migration:

Run the below cmd in powershell on the sharepoint server


function Remove-SPFeatureFromContentDB($ContentDb, $FeatureId, [switch]$ReportOnly)
{
    $db = Get-SPDatabase | where { $_.Name -eq $ContentDb }
    [bool]$report = $false
    if ($ReportOnly) { $report = $true }
   
    $db.Sites | ForEach-Object {
       
        Remove-SPFeature -obj $_ -objName "site collection" -featId $FeatureId -report $report
               
        $_ | Get-SPWeb -Limit all | ForEach-Object {
           
            Remove-SPFeature -obj $_ -objName "site" -featId $FeatureId -report $report
        }
    }
}

function Remove-SPFeature($obj, $objName, $featId, [bool]$report)
{
    $feature = $obj.Features[$featId]
   
    if ($feature -ne $null) {
        if ($report) {
            write-host "Feature found in" $objName ":" $obj.Url -foregroundcolor Red
        }
        else
        {
            try {
                $obj.Features.Remove($feature.DefinitionId, $true)
                write-host "Feature successfully removed from" $objName ":" $obj.Url -foregroundcolor Red
            }
            catch {
                write-host "There has been an error trying to remove the feature:" $_
            }
        }
    }
    else {
        #write-host "Feature ID specified does not exist in" $objName ":" $obj.Url
    }
}
Remove-SPFeatureFromContentDB -ContentDB "SP2007_Content" -FeatureId "367b94a9-4a15-42ba-b4a2-32420363e018"



Remove-SPFeatureFromContentDB  -ContentDB "WSS_ContentSP2007" -FeatureId "367b94a9-4a15-42ba-b4a2-32420363e018"

Tuesday, 6 May 2014

Site Orphan Issue

                                                              Site Orphan Issue

Before performig the below URL browse the site and confirm that the site not browsable.

This issue occurs with the tag of
"SiteOrphan" on CA

In the above case please run the below cmd and the result:

stsadm.exe -o enumallwebs | ConvertTo-xml | Out-file c:\mylogfile.xml

In the result search for InSiteMap="False" the false is orphan


Delete the site by taking the id as below cmd.

stsadm -o deletesite -force -siteid "fd5aed43-328c-4674-bff4-746b3931cd10" -databasename "DBNAme" -databaseserver "ServerName"

URL Redirection if a web application is partially upgraded

 

URL Redirection if a web application is partially upgraded


This is a case where, not all site collections within sharepoint1.in or any other web applications are upgraded.

  1. Configure two Domain Name Services (DNS) Host entries.
  2. One for the source Web application which is MOSS (New host name – Sharepoint 2007.in) and the second for the SharePoint 2010 (destination) Web application (re-point the original host name).
  3. Example: if the source Web app was http://sharepoint.in/, you can re-point that to the new 2010 destination Web application and create a new DNS entry maybe http://sharepoint1.in/ and reconfigure the source Web application to use it.
  4. Setup the target Web application AAM redirection settings to redirect failed site collection lookups to the source Web application. There is no user interface for this. You should use the STSADM add zoneurl operation.

You must run this command from SP2010 powershell window

STSADM.EXE -o addzoneurl -url http://sharepoint.in -urlzone default -zonemappedurl http://sharepoint.in -redirectionurl http://sharepoint1.in


Note: to remove the redirection , run below command

STSADM.EXE -o addzoneurl -url http://sharepoint.in -urlzone default -zonemappedurl http://sharepoint.in



Sharepoint Migration Missing assembly


This article describes solution of Missing assembly issue

MissingAssembly Error

MissingAssembly errors look similar to this one:

Category : MissingAssembly
Error : True
UpgradeBlocking : False

Message : Assembly [PAC.SharePoint.Tagging, Version=1.0.0.0, Culture=neutral, PublicKeyToken=b504d4b6c1e1a6e5] is referenced in the database [SP2010_Content], but is not installed on the current farm. Please install any feature/solution which contains this assembly.

Remedy : One or more assemblies are referenced in the database [SP2010_Content], but are not installed on the current farm. Please install any feature or solution which contains these assemblies.

I normally find MissingAssembly errors appear as the result of an event receiver, which is still registered on a list or library but part of a feature/solution no longer present on the farm.

In most cases, you may be able to look at the assembly name reported in this error and know what the problem is straight away. As before, the best way of resolving this is to reinstall the missing solution file. However, if you are not able to install the solution (e.g., maybe it only works in SharePoint 2007 and not 2010), then you may want to find the lists where the event receiver is installed and either remove the event receiver from the lists or delete the lists themselves.

To troubleshoot this issue we can re-use the Run-SQLQuery function used to help find missing web parts above. The table we need to look at this time though is called “EventReceivers”. For example, you would type the following command to find details of the assembly called “PAC.SharePoint.Tagging, Version=1.0.0.0, Culture=neutral, PublicKeyToken=b504d4b6c1e1a6e5”, as reported in the error above:


Run-SQLQuery -SqlServer "SQLSERVER" -SqlDatabase "SP2010_Content" -SqlQuery "SELECT * from EventReceivers where Assembly = ‘PAC.SharePoint.Tagging, Version=1.0.0.0, Culture=neutral, PublicKeyToken=b504d4b6c1e1a6e5'" | select Id, Name, SiteId, WebId, HostId, HostType | Format-List

This will produce an output similar to the following:

Id : 657a472f-e51d-428c-ab98-502358d87612
Name :
SiteId : 337c5721-5050-46ce-b112-083ac52f7f26
WebId : 2ae0de59-a008-4244-aa66-d8f76c79f1ad
HostId : 09308020-45a8-41e4-bbc0-7c8d8cd54132
HostType : 2

As with the MissingWebPart error before, we can use these GUIDs to get the site collection and site hosting the list with the missing event receiver, as follows:

$site = Get-SPSite -Limit all | where {$_.Id -eq "337c5721-5050-46ce-b112-083ac52f7f26"}
$web = $site | Get-SPWeb -Limit all | where {$_.Id -eq "2ae0de59-a008-4244-aa66-d8f76c79f1ad"}
$web.Url

The HostId property is the GUID of the object containing the event receiver. The HostType is the object type – in this case, HostType “2” means the event receiver host is a list.
You can look at the other host types by checking this article on MSDN: http://msdn.microsoft.com/en-us/library/ee394866(v=prot.13).aspx.

Now we know the GUID refers to a list, we can get it using PowerShell with this command:

$list = $web.Lists | where {$_.Id -eq "09308020-45a8-41e4-bbc0-7c8d8cd54132"}

To remove the list completely, type the following command:

$list.Delete()

To keep the list intact and just remove the offending event receiver, copy the Id property from the Run-SQLQuery output into this command:

$er = $list.EventReceivers | where {$_.Id -eq "657a472f-e51d-428c-ab98-502358d87612"}
$er.Delete()

If you do decide to delete the list completely, ensure you also remove it from the site Recycle Bin and Site Collection Recycle Bin to ensure the file is removed from the content database.
If not, the error may not disappear from the Health Analyzer or Test-SPContentDatabase operation.

Missing feature issue occurred during migration

This article describes the missing feature issue occurred after migration

You will see the below type of errors in CA monitoring
MissingFeature....

Solution

Run the below cmd in powershell on the sharepoint server


function Remove-SPFeatureFromContentDB($ContentDb, $FeatureId, [switch]$ReportOnly)
{
$db = Get-SPDatabase | where { $_.Name -eq $ContentDb }
[bool]$report = $false
if ($ReportOnly) { $report = $true }

$db.Sites | ForEach-Object {

Remove-SPFeature -obj $_ -objName "site collection" -featId $FeatureId -report $report

$_ | Get-SPWeb -Limit all | ForEach-Object {

Remove-SPFeature -obj $_ -objName "site" -featId $FeatureId -report $report
}
}
}

function Remove-SPFeature($obj, $objName, $featId, [bool]$report)
{
$feature = $obj.Features[$featId]

if ($feature -ne $null) {
if ($report) {
write-host "Feature found in" $objName ":" $obj.Url -foregroundcolor Red
}
else
{
try {
$obj.Features.Remove($feature.DefinitionId, $true)
write-host "Feature successfully removed from" $objName ":" $obj.Url -foregroundcolor Red
}
catch {
write-host "There has been an error trying to remove the feature:" $_
}
}
}
else {
#write-host "Feature ID specified does not exist in" $objName ":" $obj.Url
}
}
Remove-SPFeatureFromContentDB -ContentDB "MOSS_Global_PAW2_Content" -FeatureId "367b94a9-4a15-42ba-b4a2-32420363e018"


Remove-SPFeatureFromContentDB -ContentDB "WSS_Content_IT_CPS_URSM" -FeatureId "367b94a9-4a15-42ba-b4a2-32420363e018"

PROFILE SYNC TROUBLESHOOTING STEPS for SHAREPOINT

                                     PROFILE SYNC TROUBLESHOOTING STEPS

Issue Event id 5553

"failure trying to synch site"

We may notice that the Profile Sync is not working on a specific Site Collection. There is a way to disable synching of a specific Site Collection. Running stsadm -o preparetomove -site would set a flag in the SSP database to not sync this Site Collection. When that is run (for whatever reason), the Site is prepared to be moved and certain features are stopped from taking place, Profile Syncs being one of them. When Moving is set to 1 for a Site Collection, the Profile Sync will not occur.

We can run an SQL query to find out what Site Collection are set to not sync:

use SSPdatabase

select * from sitesynch (nolock) where moving=1

You will see list with contentDB id's,

Running stsadm -o preparetomove -site -undo will undo that flag, allowing that site collection to sync with the next Profile Sync job. This command will set Moving=0 for that Site Collection.

Make a note of these contentDB id's,

Some times difficult to find the individual site collections, so run the below SQL Query against config database.

Example Query:

Select * from dbo.objects (nolock) where id in ( 'id of ContentDB in the event viwer', 'id of synch site in event log ')

This gives you the Database names,

Then Ran the below commands:

stsadm -o preparetomove -undo -contentdb sqlcdb01: Name of the db from above cmd


There is also a way to force all Profiles to be imported, regardless or whether they are marked as Active in a Site Collection.

To set sync to ignore the isActive and sync all:

stsadm -o sync -ignoreisactive 1

stsadm -o sync -deleteolddatabases 0

After running the above commands, Wait for the next profile Sync or If you can't wait, then run the below command.

stsadm -o sync -synctiming m:1

Once you are sure that the profiles are sync, change the sync timing back to hour.

stsadm -o sync -synctiming h:1

Wait for 10 to 15 minutes, then your are done.  :)

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: