Search This Blog

Thursday 30 January 2014

Remove duplicate entries from Quicklaunch and Top Navigation (zine fame)

change the web URL in the attached powershell script file and run the script on powershell prompt.



RemoveDuplicateLinks.ps1.txt
**********************************



#New version of the detect and removal script:
#  You put the affected site collections into a textfile -> sites.txt <- which is stored in the same path as the ps script 
#  It will check all sites of each site collection of the sites.txt file to see if there are duplicates in the QuickLaunch and/or TopNavigation (NEW!)
#  Logging to a logfile commented out as it was not efficient (filling up disk space) …   
#  Tool will still output everything to the cmd prompt.


# THIS CODE-SAMPLE IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED 
# OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE IMPLIED WARRANTIES OF MERCHANTABILITY AND/OR 
# FITNESS FOR A PARTICULAR PURPOSE.
#
# This sample is not supported under any Microsoft standard support program or service. 
# The script is provided AS IS without warranty of any kind. Microsoft further disclaims all
# implied warranties including, without limitation, any implied warranties of merchantability
# or of fitness for a particular purpose. The entire risk arising out of the use or performance
# of the sample and documentation remains with you. In no event shall Microsoft, its authors,
# or anyone else involved in the creation, production, or delivery of the script be liable for 
# any damages whatsoever (including, without limitation, damages for loss of business profits, 
# business interruption, loss of business information, or other pecuniary loss) arising out of 
# the use of or inability to use the sample or documentation, even if Microsoft has been advised 
# of the possibility of such damages.
################################################################################################



Add-PSSnapin Microsoft.SharePoint.PowerShell -ErrorAction SilentlyContinue

function tryDeleteNode
{
    param
    (
        $node,$dictionary,$nodeCollection
    )

    $title = $node.Title
    
               
                   if(!$dictionary.ContainsKey($title))
                   {
                       $dictionary.Add($node.Title,$node.Url)
                   }
                   else
                   {
                       if($dictionary[$title] -eq $node.Url)
                       {
                           if($node.Children.Count -eq 0)
                           {
                               echo "       -> Deleting Duplicate Node: $title" 
                               $nodeCollection.Delete($node)
                               $global:didDelete= $true
                                            $temp = (get-date).ToString() +";"+ ($site.Url) +";"+ ($title)
                                            echo "$temp"
                           }
                           else
                           {
                               echo "       -> Dupe Node $title has children, Skipping..."
                           }
                       }
                              else
                       {
                   echo "       -> Duplicate title $title found, but mismatched link, Skipping..."
                       }
                   }
               
}

function deleteNodesRecurse
{
    $nodes = @{}
    foreach($node in $quickLaunch)
    {
        $childNodes = @{}
        foreach($child in $node.Children)
        {
            tryDeleteNode -node $child -dictionary $childNodes -nodeCollection $node.Children
        }

        tryDeleteNode -node $node -dictionary $nodes -nodeCollection $quickLaunch
    }
}
function deleteGlobalNodesRecurse
{
    $nodes = @{}
    foreach($node in $gnavNodes)
    {
        $childNodes = @{}
        foreach($child in $node.Children)
        {
            tryDeleteNode -node $child -dictionary $childNodes -nodeCollection $node.Children
        }

        tryDeleteNode -node $node -dictionary $nodes -nodeCollection $gnavNodes
    }
}


#$affectedSiteCollections = get-content sites.txt
#foreach ($sitecoll in $affectedSiteCollections)
#{
#    $sitecoll = Get-SPSite "http://isgdev5:43007"
#    write-host "SiteCollection: " $sitecoll.URL 
#               write-host "SiteCollection: " $sitecoll.URL 
#               foreach ($site in $sitecoll.AllWebs) 
#               { 
$site = Get-SPWeb "http://portal.ibsplc.com/crgltr"
                       write-host " -> Site: " $site.URL 
                              do
                              {
                                            $quickLaunch = $site.Navigation.QuickLaunch
                                            $global:didDelete = $false
                                            deleteNodesRecurse
                                            $pub= [Microsoft.SharePoint.Publishing.PublishingWeb]::GetPublishingWeb($site)
                                            $gnavNodes = $pub.Navigation.GlobalNavigationNodes;
                                            deleteGlobalNodesRecurse
                              }
                              while($global:didDelete)
                              $site.Dispose()
#}
#               $sitecoll.Dispose()
#}

File Upload control in sharepoint designer

Normally SharePoint provides Document Attachment in the ribbon. But in my case ribbon was hide from the user. So I need to add Attachment Control on the form instead of ribbon. So I achieve it using Client Object Model. Insert the following code in your form to make attachment field available in the Form.

<tr>
     <td rowspan="2" width="190px" valign="top" height="50px">
        <H3>
             Upload Evidence
        </H3>
     </td>
     <td valign="bottom" height="15" id="attachmentsOnClient">
         <span dir="ltr">
             <input type="file" name="fileupload0" id="onetidIOFile" size="56" title="Name" /> 
         </span>
     </td>
</tr>
<tr>
      <td colspan="4">
           <input id="attachOKbutton" type="BUTTON" onclick='OkAttach()' value="Upload" style="width: 12.8em; height: 2em"/>
           <span id="idSpace"/>
        </td>
</tr>

Thursday 23 January 2014

Find error using Correlation ID from across sharepoint Log files

Merge-SPLogFile -Path C:\zinelog.txt -Correlation bdfe6c9c-72f4-4023-47d2-44b445f95d05

How to make people picker read only in Edit form using jquery

<script language="javascript" src="/JSLibrary/jquery-1.9.0.min.js" type="text/javascript"></script>
<script language="javascript" type="text/javascript">
$(document).ready(function () {
var control = $("textarea[title='People Picker']")[0];
/* Detect browser*/
        if (navigator.appName == 'Microsoft Internet Explorer') {
        control.parentNode.parentNode.parentNode.parentNode.parentNode.parentNode.childNodes[1].style.display = "none";
        }
        else {
        control.parentNode.parentNode.parentNode.parentNode.parentNode.parentNode.childNodes[2].style.display = "none";
        }
var innerHtml = control.parentNode.parentNode.innerHTML;
control.parentNode.style.display = "none";
control.parentNode.parentNode.parentNode.parentNode.parentNode.innerHTML = control.parentNode.parentNode.parentNode.parentNode.parentNode.innerHTML + "<span class='fieldsTitle'>" + $('.ms-inputuserfield #content').text() + "</span>";
});
</script>

Thursday 9 January 2014

Sharepoint: could not save the list changes to the server

delete all the content of the folder "C:\Users\user1\AppData\Local\Microsoft\WebSiteCache" where User1 is the actual user.

This is a SPD problem.