Point Deep

Mundeep's Tech Blog

Archive for the ‘Sharepoint’ Category

Clearing Timer Services

Posted by mundeep on August 13, 2012

The following error appears in (a) Event Viewer & (b) Health Analyzer as a critical item:

The SharePoint Health Analyzer detected an error. One or more services have started or stopped unexpectedly.
The following services are managed by SharePoint, but their running state does not match what SharePoint expects: SPAdminV4. This can happen if a service crashes or if an administrator starts or stops a service using a non-SharePoint interface. If SharePoint-managed services do not match their expected running state, SharePoint will be unable to correctly distribute work to the service.
SharePoint was unable to automatically repair this error.

To stop or start a service managed by SharePoint, use the SharePoint service management interface in the SharePoint Central Administration Site. If a service has crashed, restart the service manually on the affected servers by running “net start [service name]” from a command prompt. For more information about this rule, see “http://go.microsoft.com/fwlink/?LinkID=142683”.

I checked the server to ensure the SharePoint Timer Service was running (even restarted it) but that didn’t help so I tried to run the SharePoint Configuration Wizard on the box that CA could not see the Timer Service on. It gave me the following error:

08/13/2012 14:57:46 11 ERR Exception: Microsoft.SharePoint.Administration.SPUpdatedConcurrencyException: An update conflict has occurred, and you must re-try this action. The object AnalysisServicesDiagnostics was updated by DOMAIN\SP2010SetupUser, in the psconfigui (1608) process, on machine CENTRALADMINSERVERNAME. View the tracing log for more information about the conflict.
at Microsoft.SharePoint.Administration.SPConfigurationDatabase.StoreObject(SPPersistedObject obj, Boolean storeClassIfNecessary, Boolean ensure)
at Microsoft.SharePoint.Administration.SPConfigurationDatabase.Microsoft.SharePoint.Administration.ISPPersistedStoreProvider.PutObject(SPPersistedObject persistedObject, Boolean ensure)
at Microsoft.SharePoint.Administration.SPPersistedObject.BaseUpdate()
at Microsoft.SharePoint.Administration.SPDiagnosticsServiceBase.Update()
at Microsoft.SharePoint.Administration.SPDiagnosticsService.Update()
at Microsoft.SharePoint.PostSetupConfiguration.ServicesTask.InstallServiceInConfigDB(Boolean provisionTheServiceToo, String serviceRegistryKeyName)
at Microsoft.SharePoint.PostSetupConfiguration.ServicesTask.InstallServices(Boolean provisionTheServicesToo)
at Microsoft.SharePoint.PostSetupConfiguration.ServicesTask.Run()
at Microsoft.SharePoint.PostSetupConfiguration.TaskThread.ExecuteTask()

Apparently this is caused by the timer job cache being in an inconsistent state (in my
case due to server restore from a snapshot).

Clearing the timer job cache solved the issue.

Summary of the steps to clear the timer job:

  • Stop SharePoint Timer service on all servers in the farm.
  • Browse to C:\ProgramData\Microsoft\SharePoint\Config\{GUID} where the {GUID} folder contains a bunch of XML files and NOT the files with a “.PERSITEDFILE” extension.
  • Delete all the XML files
  • Update the contents of the Cache.ini file to just say “1” (without quotes).
  • Restart the SharePoint Timer service on each server
  • Reanalyze the isse in Health Analyzer
  • Advertisements

    Posted in Sharepoint | Tagged: , | 2 Comments »

    Sharepoint 2010 Remote Debugging

    Posted by mundeep on August 5, 2011

    The following is a realy good article about Remote Debugging Sharepoint 2010 webparts and worth a read if you are ever having trouble getting it working:

    Essentially the main things to ensure are:

    1. You are running Visual Sudio Remote Debugger (msvsmon.exe)
    2. You are using an account with permissions to debug.
    3. You have placed the pdb files in the approriate folder (usually in GAC)
    4. The version of code running on the remote server is exactly the same as in the Visual Studio project you have opened (If possible it is always good to perform fresh build and deployment before trying to debug.

    Posted in .NET, Sharepoint | Tagged: , , | 1 Comment »

    Powershell Script to Import Sharepoint Organization Profiles from Active Directory

    Posted by mundeep on November 8, 2010

    Here is one of my first Powershell scripts (so improvement suggestions welcome 🙂

    The requirement was to script the creation of SharePoint Organization Profiles from Active Directory Organizational Units, including building the hierarchy and setting the Profile Subtype appropriately. Creation of the Organizational Profiles was based on the C# code in the How to: Create User Profiles and Organization Profiles MSDN article.

    Before running this note that i had a predefined list of profile subtypes that corresponded to the level of the organizational unit in the hierarchy. The top level was Root, next level was Group, then Division, Branch & finally Section. The following is an example of the organizational structure in terms of Profile Subtypes.

    • Department (Root Level)
      • Group #1
        • Division #1
          • Branch #1
            • Section #1
        • Division #2
          • Branch #2
            • Section #2
            • Section #3
            • Section #4
          • Branch #3
            • Section #5
            • Section #6
        • Division #4
          • Branch #7
      • Group #2
        • Division #5
          • Branch #8
            • Section #9
        • Division #6
          • Branch #9
            • Section #10
            • Section #11
            • Section #12
        • Division #6
          • Branch #9
    #Create All Organisation Profiles from AD OU's
    #Load Sharepoint Snapin
    Add-PSSnapin Microsoft.SharePoint.PowerShell
    #Declare Some Globals for Profile Management
    $context = Get-SPServiceContext -Site http://{sharepointwebappurl}/
    $psm = [Microsoft.Office.Server.UserProfiles.ProfileSubtypeManager]::Get($context);
    $opm = New-Object Microsoft.Office.Server.UserProfiles.OrganizationProfileManager($context)
    $rootOrg = $opm.RootOrganization
    #Find All Children OU's Based on Parent OU's Distinguished Name (DN)
    function Find-Child-OUs
    Param ([string]$sParentDN)
    	$ldapPath = "LDAP://" + $sParentDN
    	$query = new-object system.directoryservices.directorysearcher([ADSI]$ldapPath)
    	#Only Search for OUs
    	$query.filter = "(objectClass=organizationalUnit)"
    	#Only Search One Level Deep (ie. Children)
    	$query.SearchScope = "OneLevel"
    	$results = $query.findAll()
    	Write-Host $sParentDN " has " $results.Count " children"
    	return $results
    #Create an Organization Profile under parentOrg for provided OU
    function Create-Organization {
    Param ($ou, $parentOrg, $levelTitle)
    	Write-Host "Creating:" $ou.description "under" $parentOrg.DisplayName "of type" $levelTitle
    	$subType = $psm.GetProfileSubtype($levelTitle);
    	$orgProfile = $opm.CreateOrganizationProfile($subType, $parentOrg)
    	$orgProfile.DisplayName = $ou.description
    	return $orgProfile
    #Determine Subtype Based on Level
    function Get-Level-ProfileSubtype {
    Param ($level)
    	$subtypeTitle = $level
    	switch ($level) {
    		0 { $subtypeTitle = "Root"; break }
    		1 { $subtypeTitle = "Group"; break }
    		2 { $subtypeTitle = "Division"; break }
    		3 { $subtypeTitle = "Branch"; break }
    		4 { $subtypeTitle = "Section"; break }
    		default { $subtypeTitle = "Other" }
    	return $subtypeTitle
    #Create Organization Profiles for All OU's underneath the provided OU and Organization Profile
    function Create-Child-Orgnizations
    Param ([string]$currentOuDn, $parentOrg, $level)
    	#Create the Organization
    	Write-Host "Searching for Children for: " $currentOuDn
    	$children = Find-Child-OUs $currentOuDn
    	if ($children -ne $null) {
    		Write-Host -ForegroundColor red $children.Count "OU's found under:" $currentOuDn
    		Foreach($childOu in $children)
    			$ou = $childOu.GetDirectoryEntry()
    			$ouDn = $ou.distinguishedname
    			$levelTitle = Get-Level-ProfileSubtype($level)
    			#Create the Child Organization
    			$newOrg = Create-Organization $ou $parentOrg $levelTitle
    			Write-Host -ForegroundColor green "OU Created: " $newOrg.DisplayName " = " $newOrg.ProfileSubtype.Name
    			$nextLevel = $level + 1
    			Create-Child-Orgnizations $ouDn $newOrg $nextLevel
    #Create All Organization Profiles Starting from Provided OU DN
    function Create-All-Organizations {
    Param ([string]$rootOuDn)
    	Create-Child-Orgnizations $rootOuDn $rootOrg 1

    Once you have loaded all the globals and declared all the functions above the following two lines (can be done in one) will begin the profile creation.

    #Run Creation From Root Orgnization Unit, Make sure the following matches the LDAP query to the Root OU in your AD structure.
    $rootOu = "OU=Department,DC=depttest,DC=gov,DC=au"
    Create-All-Organizations $rootOu

    To help with testing & re-running code i also created a couple of functions to (a) List all Organizational Profiles under a parent and (b) Delete all Organization Profiles under a parent.

    #Retrieve existing Org Profiles
    function List-OrgProfiles {
    	if ($parentOrg.HasChildren) {
    		foreach ($childOrg in $parentOrg.GetChildren()) {
    			Write-Host $parentOrg.DisplayName "-" $childOrg.DisplayName
    			List-OrgProfiles $childOrg
    #Delete existing Org Profiles
    function Delete-OrgProfiles {
    	# If Parent Has Children Delete them first
    	if ($parentOrg.HasChildren) {
    		foreach ($childOrg in $parentOrg.GetChildren()) {
    			#Write-Host $childOrg.DisplayName " - " $parentOrg.DisplayName
    			Delete-OrgProfiles $childOrg
    		#Once children are deleted remove the current org
    		if ($parentOrg.RecordId -ne $opm.RootOrganization.RecordId) {
    			Write-Host "Removing(" $parentOrg.DisplayName ")"
    		else {
    			Write-Host "KEEP (" $parentOrg.DisplayName ")"
    	else {
    		#If not children then delete the current org
    		if ($parentOrg.RecordId -ne $opm.RootOrganization.RecordId) {
    			Write-Host "RemovingChildless(" $parentOrg.DisplayName ")"
    		else {
    			Write-Host "Childless KEEP(" $parentOrg.DisplayName ")"

    Posted in Powershell, Sharepoint | Tagged: , , , , | Leave a Comment »

    Bug in Editing Sharepoint Organization Profiles

    Posted by mundeep on October 27, 2010

    There appears to be a bug in editing Sharepoint 2010 Organization Profiles. If you try to edit the Profile SubType without editing any other field your change is not saved. The work around is to update any other field at the same time (and then don’t forget to change that field back).

    Refer to the comments on MSDN http://msdn.microsoft.com/en-us/library/ms545122.aspx for an example on how to do this in code.

    Posted in Sharepoint | Leave a Comment »

    Sharepoint 2007 Calculated Fields

    Posted by mundeep on October 27, 2010

    This is just a quick brain dump of some research into Calculated Field formulas for MOSS that i’ve had sitting as a Draft for a while.

    UPDATE: This appears to be the most comprehensive offical guide on Formulas and Functions that can be used:

    Posted in Sharepoint | Leave a Comment »

    Updating the Created Date of a Document or List Item Programmatically

    Posted by mundeep on May 22, 2009

    A common tasks developers are required to do with Sharepoint is migrated documents from either legacy systems or older Sharepoint sites into a document library. There are many ways to do this documented out there (most commonly using the Files.Add method of the API), but one of the common requirements during this ‘migration’ is to retain the Created Date or Created By fields. Sowmyan’s blog has a good description of how to set the Created By/Modified By user fields here.

    Updating the Created Date of a document or list item in Sharepoint is even easier, simply set the “Created” field of the item to the value you wish to set. For example if using the Files.Add methods in the API (as described by Dave Hunter) then the following code snippet will update the Created Date:

    // add the file   
    SPFile file = docLib.RootFolder.Files.Add(newFileName, inputStream);   
    // get the list item for that file   
    SPItem item = file.Item;   
    //Set the Created Date
    item["Created"] = "2009-02-26 15:00:00";

    Posted in .NET, Sharepoint | Tagged: , , , | Leave a Comment »

    Checking if a SPFolder Exists

    Posted by mundeep on February 24, 2009

    Ran into a colleague’s code that was incorrectly trying to check if a folder existed. It was something like:

    private bool CheckFolderExists(SPWeb parentWeb, string folderName) {
        SPFolder folder = parentWeb.GetFolder(folderName);
        if (folder == null) {
            return false;
        else {
             return true;

    however this always returns an actual SPFolder object, and the correct way is to check the Exists property of the returned object ie:

    private bool CheckFolderExists(SPWeb parentWeb, string folderName) {
        SPFolder folder = parentWeb.GetFolder(folderName);
        return folder.Exists;

    NB: Yes, this post is almost identical to my earlier one about checking if an SPWeb object exists.

    Posted in .NET, Sharepoint | Tagged: , , | 10 Comments »

    InfoPath Forms Services is not turned on

    Posted by mundeep on February 17, 2009

    While trying to deploy an InfoPath Form to sharepoint via stsadm commands i received the error:

    InfoPath Forms Services is not turned on.

    Initially thinking that the Enterprise features where not enabled in the Site Collection i was deploying to i tried activating the “Office SharePoint Server Enterprise Site Collection features”, however that did not make a difference.

    Turns out the problem was that the account i was trying to deploy under (my own) did not have sufficient permissions (to what i am not sure – but i am guessing the configuration database), running the deployment under an account with more priveleges solved the problem.

    Summary: If you get the above error make sure to try your deployment/stsadm commands under an account with higher priveleges (most likely access to the config database).

    Posted in Sharepoint | Tagged: , , , | Leave a Comment »

    Converting InfoPath Forms into Visual Studio Projects

    Posted by mundeep on February 16, 2009

    I was recently trying to converting some InfoPath froms that had been created as per default in the InfoPath client application (and using Visual Studio Tools for Applications for Code-Behind) into a Visual Studio project to be opened in Visual Stdio 2005 as per the MSDN HowTo. However when i reached the last step and opened the masnifest.xsf it would just me show me the xml contents of the file and not the visual form editing GUI that you see in the InfoPath client. Solution was to install Visual Studio 2005 Tools for Office Second Edition (VSTO 2005 SE) and then reopen the project.

    Posted in .NET, Sharepoint | Tagged: , , , , | Leave a Comment »

    sgen.exe exited with code 1

    Posted by mundeep on February 12, 2009

    While developing a Sharepoint solution using WSPBuilder and Visual Studio 2005 i noticed that i would get the following error when trying to compile a Release build (on further examination i noticed that it would occur whenever i switched between release & debug builds):

    “sgen.exe exited with code 1”

    After doing some research i found a several different suggested solutions:

    1. Remove and re-add the project from the solution as per this forum post.
    2. Turn off the “Generate serialization assembly” option in the Build tab of Project Properties see this blogpost and this one.
    3. Remove the previous version of the assembly from the GAC as per this blogpost.

    To determine which solution i should use required some more research on sgen.exe does. As per the MSDN article:

    When the XML Serializer Generator is not used, a XmlSerializer generates serialization code and a serialization assembly for each type every time an application is run. To improve the performance of XML serialization startup, use the Sgen.exe tool to generate those assemblies the assemblies in advance. These assemblies can then be deployed with the application.

    The XML Serializer Generator can also improve the performance of clients that use XML Web service proxies to communicate with servers because the serialization process will not incur a performance hit when the type is loaded the first time.

    These generated assemblies cannot be used on the server side of a Web service. This tool is only for Web service clients and manual serialization scenarios.

    If the assembly containing the type to serialize is named MyType.dll, then the associated serialization assembly will be named MyType.XmlSerializers.dll.

    This means that as well as being impractical the first solution doesn’t really solve the problem.

    The second solution ‘solves’ the probelm, however based on the MSDN article it may result in a minor performance hit if the serialization class is required.

    In my case i was performing some manual serialization and thus decided to live with the minor annoyance of soltuion #3 and removing the existing assemblies from the GAC whenever i ran into the error.

    Posted in .NET, Sharepoint | Tagged: , , , , | Leave a Comment »