Pages

Sunday 8 September 2013

"The SPPersistedObject, CustomTimerJob Name=Sync User Details List, could not be updated because the current user is not a Farm Administrator." in SharePoint 2010

When deploying a custom timer job in our UAT enviornment I came across the following error message:
"The SPPersistedObject, CustomTimerJob Name=Sync User Details List, could not be updated because the current user is not a Farm Administrator."

Farm Config: SP2010 SP1, June 2011 CU


A few things that I checked:
  • OWSTIMER service account"SVC_XXXXXXX" was in the "Farm Administrator's Group"
  • Added the App Pool as the Farm Admin group (not sure if this the right way of doing it)
  • Set the "RemoteAdministratorAccessDenied" to false
  • Retracted the soltuion and redeployed it

Powershell command to set the RemoteAdministratorAccessDenied  to False:

//PowerShell code

function Set-RemoteAdministratorAccessDenied-False()
{
    [System.Reflection.Assembly]::LoadWithPartialName("Microsoft.SharePoint") > $null
    [System.Reflection.Assembly]::LoadWithPartialName("Microsoft.SharePoint.Administration") > $null

    # get content web service
    $contentService = [Microsoft.SharePoint.Administration.SPWebService]::ContentService
    # turn off remote administration security
    $contentService.RemoteAdministratorAccessDenied = $false
   $contentService.Update()         
}

Set-RemoteAdministratorAccessDenied-False

References:



Thursday 18 July 2013

Easiest way to find the template for the current site collection SharePoint 2010

By far the easiest way to find the template a site collection is based on:

  • Navigate to the relevant site collection : http://devsite.com
  • View source
  • Search for "wsaSiteTemplateId"
  • this should give you the Template ID

Site template ID to Name mapping:0 - GLOBAL (SetupPath=global) - "Global template"1 - STS - "windows SharePoint Services Site", "Team Site", "Blank Site", "Document Workspace"2 - MPS - "Basic Meeting Workspace", "Blank Meeting Workspace", "Decision Meeting Workspace", "Social Meeting Workspace", "Multipage Meeting Workspace"3 - CENTRALADMIN - "Central Admin Site"4 - WIKI - "Wiki Site"7 - BDR - "Document Center"9 - BLOG - "Blog"20 - SPS (OBSOLETE) - "SharePoint Portal Server Site"21 - SPSPERS - "SharePoint Portal Server Personal Space"22 - SPSMSITE - "Personalization Site"30 - SPSTOC (OBSOLETE) - "Contents area Template"31 - SPSTOPIC (OBSOLETE) - "Topic area template"32 - SPSNEWS (OBSOLETE) - "News area template"33 - SPSNHOME (SubWebOnly) - "News Home template"34 - SPSSITES - "Site Directory area template"36 - SPSCOMMU (OBSOLETE) - "Community area template"38 - SPSREPORTCENTER - "Report Center Site"39 - CMSPUBLISHING (SetupPath=SiteTemplates\PUBLISHING) - "Publishing and Team Collaboration Site"40 - OSRV (SetupPath=SiteTemplates\OSRV) - "Shared Services Administration Site"47 - SPSPORTAL - "Corporate Intranet Site"50 - SRCHCEN - "Search Center"51 - PROFILES - "Profiles"52 - BLANKINTERNETCONTAINER - "Internet Presence Web Site"53 - BLANKINTERNET - "Publishing Site", "Press Releases Site", "Publishing Site"54 - SPSMSITEHOST - "My Site Host"90 - SRCHCENTERLITE (SetupPath=SiteTemplates\SRCHCENTERLITE) - "Search Center Lite"6221 - PWA (SetupPath=SiteTemplates\PWA) - "Project Web Access Site"6215 - PWS (SetupPath=SiteTemplates\PWS) - "Project Workspace"14483 - OFFILE - "Records Repository", "Records Repository"



Tuesday 11 June 2013

How to get a list of all activated features for a site collection and a sub site in SharePoint 2010 using powershell

To get a list of Site collection features:

Get-SPSite http://sharepoint2010 | % {

    $results = @()

    Get-SPFeature -Site $_ -Limit All | % {

    $feature = $_; 
        $featuresDefn = (Get-SPFarm).FeatureDefinitions[$_.ID]; 
        $cc = [System.Globalization.CultureInfo]::CurrentCulture;

        $obj = New-Object PSObject;
        $obj | Add-Member NoteProperty  Title  $($featuresDefn.GetTitle($cc));
        $obj | Add-Member NoteProperty  Hidden $($feature.Hidden);
        
        $results += $obj;
    }
    $results | FT -auto;
}
 
 
To get a list of features for a sub site:
 
Get-SPWeb http://sharepoint2010/subsite | % {

    $results = @()

    Get-SPFeature -Web $_ -Limit All | % {

        $feature = $_; 
        $featuresDefn = (Get-SPFarm).FeatureDefinitions[$_.ID]; 
        $cc = [System.Globalization.CultureInfo]::CurrentCulture;

        $obj = New-Object PSObject;
        $obj | Add-Member NoteProperty  Title  $($featuresDefn.GetTitle($cc));
        $obj | Add-Member NoteProperty  Hidden $($feature.Hidden);
        
        $results += $obj;
    }
    $results | FT -Auto;
} 


Shows both hidden and non-hidden features
 
Thanks to  Joe Rodgers (blogs.msdn.com/b/josrod/archive/2013/01/04/
powershell-to-list-activated-features-for-a-site-and-web.aspx)

Permissions for all authenticated users was corrupted in a Classic mode web application sharepoint 2010

Recently I was working on a Form library which stopped inheriting permissions from the parent.

Issue:

"All authenticated users" were added to the form library, however none of the users were able to access this list.

Upon investigating further (by clicking on the user account), found out that for some reason the account was claims based, even though the web application was classic mode;

This is what was displayed:
Account: (c:0(.s|true) 
Name: All Authenticated Users

Fix:

Deleted the account and re-added

Tuesday 4 June 2013

How to get the Folder structure tree view using MS DOS

When migrating content from a file system to a web based system, it is very help full to get a report on the file structure

Open command prompt

tree /a /f "directory path" > TreeReport.txt


/f Displays file names in each directory.
/a ext characters used for linking lines, instead of graphic characters. /a is used with code pages that do not support graphic characters and to send output to printers that do not properly interpret graphic characters.

Sunday 26 May 2013

How to flush invalid SPWebConfigModifications SharePoint 2010


Occasionally you modify the web.config using the SPWebCongiModification class. Some times the config entries are not removed from the web.config. You can use the code below to exactly do this:

This is an exact copy of the code mentioend by Luis:
http://stackoverflow.com/questions/10732808/how-to-flush-invalid-spwebconfigmodifications

This is for my reference and I take no credit for this solution, 100% credit goes to Luis :)

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.SharePoint;
using Microsoft.SharePoint.Navigation;
using Microsoft.SharePoint.Administration;

namespace ModTool
{
    class Program
    {
        static void Main(string[] args)
        {

            SPSite site = new SPSite(args[0]);
            SPWebService service = site.WebApplication.Farm.Services.GetValue<SPWebService>();


            if (args.Length == 1 || string.IsNullOrEmpty(args[1]))
            {
                Console.Out.WriteLine("Listing all Mods and Owners");
                foreach (SPWebConfigModification mod in service.WebConfigModifications)
                {
                    Console.Out.WriteLine("Mod:" + mod.Name + ", Owner:" + mod.Owner);
                }
            }
            else
            {
                Console.Out.WriteLine("Removing all mods owner:" + args[1] + ", reference site:" + args[0]);

                List<SPWebConfigModification> toDelete = new List<SPWebConfigModification>();

                foreach (SPWebConfigModification mod in service.WebConfigModifications)
                {
                    if (mod.Owner == args[1])
                    {
                        toDelete.Add(mod);
                    }
                }

                Console.Out.WriteLine("Found " + toDelete.Count + "Mods");



                foreach (SPWebConfigModification mod in toDelete)
                {
                    service.WebConfigModifications.Remove(mod);
                }
                service.Update();
                SPWebService.ContentService.ApplyWebConfigModifications();
                Console.Out.WriteLine("Done!!");
            }
        }
    }
}
 
Usuage:
ModTool http://site - List all the mods for the farm, site is just an entry point
ModTool http://site owner -Deletes all the mods for in the farm forwhich the owner is "owner" 




Thursday 16 May 2013

The Security validation for this page is invalid. Click back in your web browser, refresh the page and try your operation again. After installing April 2013 CU for SharePoint server 2010

After installing the April 2013 CU for SharePoint Server 2010. InfoPath forms were throwing the following error:










MS have acknowledged that this issue was introduced by the April 2013 CU, A critical on demand (COD) will be available shortly.

I will update the post with the COD.

Monday 13 May 2013

How to create a new host named site collection in its own content database using Powershell


Step 1:  Add New Content Database to the Web Application
New-SPContentDatabase -Name <content_db_name> -WebApplication <web application URL>


Step 2: Get a reference to the hostnamed web application:
$webApp = Get-SPWebApplication "MyHostNamedWebApp" 
 
Step 3: Create a site collection 
new-spsite http://sharepointDev.com -ownerAlias "domain\user" -HostHeaderWebApplication $WebApp -ContentDatabase "WSS_Content_Dev_test" -template sts#0

Tuesday 7 May 2013

BCS Throttle Management - SharePoint 2010

In order to check theBCS item limit run the following command:

$bdcProxy = Get-SPServiceApplicationProxy | where {$_.GetType().FullName -eq ('Microsoft.SharePoint.BusinessData.SharedService.' + 'BdcServiceApplicationProxy')}
  
$dbRule = Get-SPBusinessDataCatalogThrottleConfig -Scope Database -ThrottleType Items -ServiceApplicationProxy $bdcProxy


Result:
Scope: Database
ThrottleType: Items
Enforced: True
Default : 3000
Max: 1000000



Reference:
http://blogs.msdn.com/b/bcs/archive/2010/02/16/bcs-powershell-introduction-and-throttle-management.aspx 

Monday 6 May 2013

Manage Visual Upgrades in sharePoint 2010

If you have a big site collection and some of the sub sites have not been upgraded to the UI version 4, then this powershell script will help:

# Gets the UI for each site in the


#create a txt file
"SitePath, SWebPath, UIVersion, UIVersion Configuration Enabled, MasterURL, Custom Master URL" > "UI-Version.txt" #Write the Headers in to a text file

$sc = Get-SPSite http://www.mySiteCollection.com; $sc.GetVisualReport() | Select-Object "SitePath", "SWebPath", "UIVersion", "UIVersion Configuration Enabled", "MasterURL", "Custom Master URL" >> UI-Version.txt

Restore a deleted site collection using PowerShell

In order to delete a sub site, one can recover using admin recyclebin. You can restore a sub site which has been deleted using the UI not SharePoint designer. But if you have to recover a site collection then you will need to use powershell.

Thanks to  Salaudeen Rajack


Get-SPDeletedSite - Displays list of sites deleted. 
Restore-SPDeletedSite - Restore a deleted site 
Remove-SPDeletedSite - To permanently remove the deleted site collection.

Permanently remove the deleted site collection:
Get-SPDeletedSite -webapplication http://sharepoint.company.com | Remove-SPDeletedSite

Wednesday 1 May 2013

How to get the SharePoint farm configuration

Occasionally you would want to get the entier SharePoint Farm configuration. Well, there is this awesome Executable on codeplex which just does this:

http://spsfarmreport.codeplex.com


Wednesday 10 April 2013

Issues faced when Copying/Moving a list in SP 2010





Just thought I will share my pain and some information that might safe guard you from making the same mistake as I did.

Problem:

User called up saying the list view has reached its threshold. The list was an Issues Register (name: Cut-Over Issues Register) and had versioning enabled. User requested we make a copy of list and name it “Issues Register” and delete all the closed items so only the Open items would remain in the new “Issues Register”

Solution:

Follow the technet article which uses PowerShell to export the list and then import the list back in. I found out this is not as easy as it looks in fact it was very hard and extremely painful, mainly due to the fact that the command does not cater for users that do not exist in AD anymore.

Why:
Well the list had versioning enabled and the worst part was that some of the users that had created an item have left NTG, which means the user account did not exist. So the restore process had overwritten the users that it could not find in AD with my user id and obviously that meant that we had lost the history.

Oh no… What can I do, unfortunately this is by design and the solution found on some forum sites was to reactivate those accounts in AD, copy the list and deactivate them again (not really an option if you have many users)

Things to do or look out for:

This exercise has highlighted some very important points:
·         If versioning is enabled on a list then do not copy/move. Suggest we create a new list based on the existing list definition and archive existing list by setting the list permission to read-only.
·         It can very difficult to recover your changes as even if you had a backup of the DB and thought you can just restore the list, you will not be able to do so. All the users that do not exist will be replaced with your user id, so in a sense you will never be able to recover an original list
·         If you get a request for a copy of a list, ensure there is no versioning enabled (List settings > versioning), if there is versioning then inform the requestor that they might lose historical info i.e. if any of the uses who modified/created an item and have left the organization then this will be replaced with your userid.

How to best solve the list view threshold issue (my recommendation):
·         Navigate to the list, then list settings, click on save as list template and specify a name (do not include content as most likely it will exceed the allowed file size of 500MB)
·         Create a new list based on the new template that you have created.
·         Archive the original list by setting the permission of the original list to read only.
·         This will need some planning before it carried out, as you may find that it may work in dev/uat but in PROD it won’t because of minimal testing carried out prior to moving your changes to PROD.


Sunday 24 March 2013

How to increase the timeout for an app pool when attaching from Visual Studio

As a developer you have to attach to the w3wp process from Visual studio to debug your code. This is straight forward, from Visual studio > tools > Attach to Process. (Note: To find the correct w3wp process, refer to this post)

But the problem is that you never have enough time to step through your code as the pool recycles. In order to increase the time so the process is attached and you get a lot longer to debug your code, follow these steps:

  1. In your development environment, open server manager or open IIS manager
  2. Under application pools > right the correct app pool and click on advanced settings > Change these 2 settings:
  3. Ping Enabled: Set this to False and Ping Maximum Response Time (seconds): Set this to 4294967 (which is the highest you can set)

And that's it, now you will see that you can attach to correct process for lot longer.

How to find the w3wp ProcessId when attaching to process from Visual Studio


When debugging from Visual Studio, you have to attach to the correct w2wp process.

To find the right w3wp process on a windows server 2008 R2 running IIS 7.5, run the following command:

  1. Open command prompt (right click run as administrator)
  2. if not already at c:\windows\system32. navigate to the location by this command cd   c:\windows\system32\inetsrv
  3. use this command to get a list of all the w3wp process
    appcmd list wp
  4. Identify the correct process from the list

That's is, now you can attach to the correct process rather than attaching to all :)

Monday 11 March 2013

Include managed meta data in your core search results web part SharePoint 2010

Issue:

So you have been asked to display managed metadata fields in your core results. These are the general steps I follow:

1: Add the managed metadata property to the Managed Property in Search Administration in CA. Here is how to do this: follow this blog post.

2: After you run a full crawl (ensure you have at least 1 item with data populated), we need to modify the core results web part to display the information. For example purpose we will call our field Visible-Internal (this is basically the department field which is a managed metadata field)

3: First we need to ensure that the field is actually being pulled: So navigate to your search page, edit the page and edit the search core results web part. Under Display Properties > Untick "Location Visualisation" > Click on XSL Editor, copy and save the existing text and then modify with the following code:

I generally use Notepad++ to make any changes

<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output method="xml" version="1.0" encoding="UTF-8" indent="yes"/>
<xsl:template match="/">
<xmp><xsl:copy-of select="*"/></xmp>
</xsl:template>
</xsl:stylesheet>


The above code displays all the fields that search is indexing, ensure your field is showing up in here, in our instance it is <visible-Internal>DATA</visible-internal>

4: Now for the fun part (well not so fun part), we need to format the results, by default Managed metadata is displayed as follows:

ID;#Value|GUID

This is fine but in order for a richer search experience we will look at formatting the results so we only display the "Display Name: VALUE"

5: Open XSLT editor and replace with the saved Text in Step 3

6: Add this to the top section of the XSLT code:
<xsl:param name="FieldName" /> in our case it is <xsl:param name="Visible-Internal" />

7: Under XSL:Choose add the following field:
            <xsl:if test="string-length(visible-internal) &gt; 0">  
                 <xsl:text disable-output-escaping="yes">&#8195;</xsl:text>
                 <xsl:value-of select="$visible-internal" />
                 <xsl:value-of select="visible-internalr" />
             </xsl:if>


8: Add this under <div class="srch-Metadata2">
    <xsl:call-template name="visible-internal">
    <xsl:with-param name="visible-internal" select="visible-internal" />
    </xsl:call-template>


9: Search for <xsl:template name="DisplayAuthors"> and add the following code:

 <xsl:template name="Visible-Internal">
    <xsl:param name="visible-internal" />
    <xsl:if test='string-length($visible-internal) &gt; 0'>
     Visible to:<xsl:value-of disable-output-escaping="yes" select="substring-after(substring-before($visible-internal, '|'),';#')"/>
     <xsl:text disable-output-escaping="yes"><![CDATA[&nbsp;]]></xsl:text>
     <xsl:text disable-output-escaping="yes"><![CDATA[&nbsp;]]></xsl:text>
    </xsl:if>
</xsl:template>


The magic happens in substring-before and substring-after.

10: Copy and paste it in the XSL editor and save the properties, you will have to save the page and close. Once you refresh, you should see your data as Visible to: Internal Staff

Hope this helps and please share your feedback.

Thursday 7 March 2013

Issue: Anonymous access site kept throwing 401 Resolution: View a list of all unpublished or checked out items

Issue:
 
Recently I had an issue where an anonymous site kep asking for user credentials, which was weird because the web app was set to anonymous and other sites did not prompt for authentication.

Resolution:

Turns out there were a lot of items that did not have a publsied version or had it checked out and were in draft state.

To find all unpublsied or draft versions:

Nagivate to "Manage Content and Structure > View: All Draft Document"

There are other various view that can help namely:

"Related Resources" - Which highlights all the other fiels that might have been checked out.


 

Monday 4 March 2013

Quick Launch links randomly disappear SharePoint 2010

Issue:

Recently a client had complained that the navigation items under current navigation (quick launch) in a sub site where disappearing. The user was removing them and it looked as if they were just dropping out. If the user went back and added those items again, then they appeared under quick launch


Resolution:

This solution posted at [1] seem to help a few so will try this fix:
  1. On the parent site of the site having the problem, create a “dummy” document library and leave the “Display on Quick Launch” option set to “Yes”. Once the library has been created, remove permission inheritance for the document library and the problem will be resolved for all sub-sites underneath this parent.
Yet to try out this option as the client had just added the navigation items back in, waiting for this to happen again so can apply this fix. Will update this post if Option #1 works for me


Ref:
 [1] http://social.technet.microsoft.com/Forums/pl-PL/sharepoint2010setup/thread/4439a80d-8e3e-4795-a21f-e63c221ed06b

Add new MIME type - open PDF files directly in browser


Unable to open PDF/HTML/XML files directly in browser in SharePoint 2010? Default configuration of SharePoint 2010 does not consider PDF documents safe for displaying in the browser.This script adds new MIME type to "AllowedInlineDownloadedMimeTypes" property list of defined SharePoint 2010 Web Application.


 
If ( (Get-PSSnapin -Name "Microsoft.SharePoint.PowerShell" -ErrorAction SilentlyContinue) -eq $null ) { 
    Add-PSSnapin "Microsoft.SharePoint.PowerShell" 
} 
 
Get-SPWebApplication 
 
$WebApp = Get-SPWebApplication $(Read-Host "`nEnter Web Application URL") 
 
Write-Host `n"Mime Type Examples:"`n"application/pdf, text/html, text/xml"`n 
 
If ($WebApp.AllowedInlineDownloadedMimeTypes -notcontains ($MimeType = Read-Host "Enter a required mime type")) 
{ 
  Write-Host -ForegroundColor White `n"Adding" $MimeType "MIME Type to defined Web Application"$WebApp.url 
  $WebApp.AllowedInlineDownloadedMimeTypes.Add($MimeType) 
  $WebApp.Update() 
  Write-Host -ForegroundColor Green `n"The" $MimeType "MIME type has been successfully added." 
} Else { 
  Write-Host -ForegroundColor Red `n"The" $MimeType "MIME type has already been added." 
}


Ref:
http://gallery.technet.microsoft.com/scriptcenter/Add-new-MIME-type-open-PDF-f6c57c32

Nintex Workflow would not start automatically after publishing in SharePoint 2010

Issue:

The workflow was set to automatically start when a new item was created and an existing item was modified. After adding a new item the workflow did not start and when selected the item and clicked on the workflow button from the ribbion there was error message "user cannot be found". Checked the server event logs and the following message was recorded:

Error loading and running event receiver Microsoft.SharePoint.Workflow.SPWorkflowAutostartEventReceiver in Microsoft.SharePoint, Version=14.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c. Additional information is below.

: User cannot be found.
Event ID: 6875


Debugging steps

I took over someone else and had to background knowledge as what had happened earlier. The current site was a SP 2010 site, with Nintex workflow 2010.
  • I tried creating a test workflow and that failed to start as well
  • created a test workflow in a different site collection and this worked fine, so the issue was with the current site collection

 Resolution:

I opened up SharePoint designer and clicked on wokflows, to my surprise I found that the out of the box user was set to a claims based format e.g. "0;#id", but the current web application was classic mode so I edited the workflow and saved it back (did not make any changes, just opened and saved) this updated the workflow with my current user id.

After which the workflows started working.

Hope this helps :)

Sunday 24 February 2013

How to replace an instance of a string within a string using javascript

If you have a long string, for  example "This is a long string, I want to remove the second string from this string" and you wanted to remove the 2nd instance of the word "string" from the long string using javascript. This method is helpful:

I am sure there are heaps of ways to do this, since I am new to javacript, I found this function helpful

function CustomReplace(strData, strTextToReplace, strReplaceWith, replaceAt) {
    var index = strData.indexOf(strTextToReplace);
    for (var i = 1; i < replaceAt; i++)
        index = strData.indexOf(strTextToReplace, index + 1);
    if (index >= 0)
        return strData.substr(0, index) + strReplaceWith + strData.substr(index + strTextToReplace.length, strData.length);
    return strData;
}


usage:

var txt = CustomReplace(txt,'string','',2);




Hope it helps :)

Monday 18 February 2013

Shutting down the mobile redirect for SharePoint 2010 sites

We had this problem the other day, where all internet requests were getting redirected to the mobile version and it kept prompting for credentials. 

The file that you need to modify is compat.browser
Location:  C:\inetpub\wwwroot\wss\VirtualDirectories\<webApp>\App_Browsers

Make a copy of the file in a different location and edit the file. Search for the entry:

<capability name=”isMobileDevice” value=”true” />. and change the value to false




For more detail visit this blog

Wednesday 13 February 2013

"Test Connection' button in Nintex Workflow 2010 does not work with MySQL connection strings

We had a situation where an end user was complaining about the connection string not working in Nintex Workflow 2010. My immediate conclusion was that the connection string was not correct, I double checked with www. connectionstrings.com and to my surprise it was fine.

The end user was testing by clicking on the test connection button 

 
The following error was returned:

 

Turns out that the "Test Connection" button defaults to MS SQL. The test connection button returned the following error but the workflow completed successfully.

There has been a support ticket logged with Nintex
http://connect.nintex.com/forums/thread/23150.aspx