Thursday, April 17, 2014

Little trick regarding "SharePoint Server Publishing Infrastructure" and "save site as template"

In theory, if the site feature "SharePoint Server Publishing" is deactivated, we can save the site as a template, which can be used to generate other sites.

However, this is not true.

The problem is not about the site feature "SharePoint Server Publishing", but the site collection feature "SharePoint Server Publishing Infrastructure".

When "SharePoint Server Publishing Infrastructure" is activated, a lot of stuff are created; but, when it's deactivated, not all relevant content are removed completely.

I cannot find the explanation of that. During my test on SharePoint 2010 SP2 + CU201308, after reactivating "SharePoint Server Publishing Infrastructure", I got the error message below when clicking "Page layouts and site templates", or "save site as template", or enable site feature "SharePoint Server Publishing", or test the new site based on a generated site template.

In summary,

1. Don't deactivate site collection feature "SharePoint Server Publishing Infrastructure".


2. Don't save the site as a template if "SharePoint Server Publishing Infrastructure" is activated.

==============

Unable to open Lookup list '{64D9347E-BCBC-471D-B038-4AED71833C6D}'.[Error was 0x81020026]


Event ListItem throws an argument exception on web url http://site1.sharepoint.local/sites/test1 and item id 170


Unable to open Lookup list '{64D9347E-BCBC-471D-B038-4AED71833C6D}'.[Error was 0x81020026]


Not enough information to determine a list for module "XSLStyleSheets". Assuming no list for this module.


Failed to instantiate file "ContentQueryMain.xsl" from module "XSLStyleSheets": The specified list does not exist.


The element of type 'Module' for feature 'PublishingResources' (id: aebc918d-b20f-4a11-a1db-9ed84d79c87e) threw an exception during activation: Failed to instantiate file "ContentQueryMain.xsl" from module "XSLStyleSheets": The specified list does not exist.

Feature Activation: Threw an exception, attempting to roll back.  Feature 'PublishingResources' (ID: 'aebc918d-b20f-4a11-a1db-9ed84d79c87e').  Exception: Microsoft.SharePoint.SPException: Failed to instantiate file "ContentQueryMain.xsl" from module "XSLStyleSheets": The specified list does not exist. ---> System.Runtime.InteropServices.COMException (0x81070588): Failed to instantiate file "ContentQueryMain.xsl" from module "XSLStyleSheets": The specified list does not exist.  
 at Microsoft.SharePoint.Library.SPRequestInternalClass.EnableModuleFromXml(String bstrSetupDirectory, String bstrFeatureDirectory, String bstrUrl, String bstrXML, Boolean fForceUnghost, ISPEnableModuleCallback pModuleContext)  
 at Microsoft.SharePoint.Library.SPRequest.EnableModuleFromXml(String bstrSetupDirectory, String bstrFeatureDirectory, String bstrUrl, String bstrXML, Boolean fForceUnghost, ISPEnableModuleCallback pModuleContext)     -
 -- End of inner exception stack trace ---  
 at Microsoft.SharePoint.Administration.SPElementDefinitionCollection.ProvisionModules(SPFeaturePropertyCollection props, SPSite site, SPWeb web, SPFeatureActivateFlags activateFlags, Boolean fForce)  
 at Microsoft.SharePoint.Administration.SPElementDefinitionCollection.ProvisionElements(SPFeaturePropertyCollection props, SPWebApplication webapp, SPSite site, SPWeb web, SPFeatureActivateFlags activateFlags, Boolean fForce)  
 at Microsoft.SharePoint.SPFeature.Activate(SPSite siteParent, SPWeb webParent, SPFeaturePropertyCollection props, SPFeatureActivateFlags activateFlags, Boolean fForce)


The feature 'f6924d36-2fa8-4f0b-b16d-06b7250180fa' depends on feature 'aebc918d-b20f-4a11-a1db-9ed84d79c87e' which failed to activate: Microsoft.SharePoint.SPException: Failed to instantiate file "ContentQueryMain.xsl" from module "XSLStyleSheets": The specified list does not exist. ---> System.Runtime.InteropServices.COMException (0x81070588): Failed to instantiate file "ContentQueryMain.xsl" from module "XSLStyleSheets": The specified list does not exist.  
 at Microsoft.SharePoint.Library.SPRequestInternalClass.EnableModuleFromXml(String bstrSetupDirectory, String bstrFeatureDirectory, String bstrUrl, String bstrXML, Boolean fForceUnghost, ISPEnableModuleCallback pModuleContext)  
 at Microsoft.SharePoint.Library.SPRequest.EnableModuleFromXml(String bstrSetupDirectory, String bstrFeatureDirectory, String bstrUrl, String bstrXML, Boolean fForceUnghost, ISPEnableModuleCallback pModuleContext)     -
 -- End of inner exception stack trace ---  
 at Microsoft.SharePoint.Administration.SPElementDefinitionCollection.ProvisionModules(SPFeaturePropertyCollection props, SPSite site, SPWeb web, SPFeatureActivateFlags activateFlags, Boolean fForce)  
 at Microsoft.SharePoint.Administration.SPElementDefinitionCollection.ProvisionElements(SPFeaturePropertyCollection props, SPWebApplication webapp, SPSite site, SPWeb web, SPFeatureActivateFlags activateFlags, Boolean fForce)  
 at Microsoft.SharePoint.SPFeature.Activate(SPSite siteParent, SPWeb webParent, SPFeaturePropertyCollection props, SPFeatureActivateFlags activateFlags, Boolean fForce)  
 at Microsoft.SharePoint.SPFeatureCollection.AddInternal(SPFeatureDefinition featdef, Version version, SPFeaturePropertyCollection properties, SPFeatureActivateFlags activateFlags, Boolean force, Boolean fMarkOnly)  
 at Microsoft.SharePoint.SPFeatureCollection.CheckSameScopeDependency(SPFeatureDefinition featdefDependant, SPFeatureDependency featdep, SPFeatureDefinition featdefDependency, Boolean fActivateHidden, Boolean fUpgrade, Boolean fForce, Boolean fMarkOnly)


Exception was thrown while ensuring dependencies met for feature 'PublishingSite' (id: f6924d36-2fa8-4f0b-b16d-06b7250180fa): Microsoft.SharePoint.SPException: Failed to instantiate file "ContentQueryMain.xsl" from module "XSLStyleSheets": The specified list does not exist. ---> System.Runtime.InteropServices.COMException (0x81070588): Failed to instantiate file "ContentQueryMain.xsl" from module "XSLStyleSheets": The specified list does not exist.  
 at Microsoft.SharePoint.Library.SPRequestInternalClass.EnableModuleFromXml(String bstrSetupDirectory, String bstrFeatureDirectory, String bstrUrl, String bstrXML, Boolean fForceUnghost, ISPEnableModuleCallback pModuleContext)  
 at Microsoft.SharePoint.Library.SPRequest.EnableModuleFromXml(String bstrSetupDirectory, String bstrFeatureDirectory, String bstrUrl, String bstrXML, Boolean fForceUnghost, ISPEnableModuleCallback pModuleContext)     -
 -- End of inner exception stack trace ---  
 at Microsoft.SharePoint.Administration.SPElementDefinitionCollection.ProvisionModules(SPFeaturePropertyCollection props, SPSite site, SPWeb web, SPFeatureActivateFlags activateFlags, Boolean fForce)  
 at Microsoft.SharePoint.Administration.SPElementDefinitionCollection.ProvisionElements(SPFeaturePropertyCollection props, SPWebApplication webapp, SPSite site, SPWeb web, SPFeatureActivateFlags activateFlags, Boolean fForce)  
 at Microsoft.SharePoint.SPFeature.Activate(SPSite siteParent, SPWeb webParent, SPFeaturePropertyCollection props, SPFeatureActivateFlags activateFlags, Boolean fForce)  
 at Microsoft.SharePoint.SPFeatureCollection.AddInternal(SPFeatureDefinition featdef, Version version, SPFeaturePropertyCollection properties, SPFeatureActivateFlags activateFlags, Boolean force, Boolean fMarkOnly)  
 at Microsoft.SharePoint.SPFeatureCollection.CheckSameScopeDependency(SPFeatureDefinition featdefDependant, SPFeatureDependency featdep, SPFeatureDefinition featdefDependency, Boolean fActivateHidden, Boolean fUpgrade, Boolean fForce, Boolean fMarkOnly)  
 at Microsoft.SharePoint.SPFeatureCollection.CheckFeatureDependency(SPFeatureDefinition featdefDependant, SPFeatureDependency featdep, Boolean fActivateHidden, Boolean fUpgrade, Boolean fForce, Boolean fMarkOnly, FailureReason& errType)  
 at Microsoft.SharePoint.SPFeatureCollection.CheckFeatureDependencies(SPFeatureDefinition featdef, Boolean fActivateHidden, Boolean fUpgrade, Boolean fForce, Boolean fThrowError, Boolean fMarkOnly, List`1& missingFeatures)


Feature Activation: Failed to ensure feature dependencies for feature 'PublishingSite' (id: 'f6924d36-2fa8-4f0b-b16d-06b7250180fa'), exception thrown: Microsoft.SharePoint.SPException: Failed to instantiate file "ContentQueryMain.xsl" from module "XSLStyleSheets": The specified list does not exist. ---> System.Runtime.InteropServices.COMException (0x81070588): Failed to instantiate file "ContentQueryMain.xsl" from module "XSLStyleSheets": The specified list does not exist.  
 at Microsoft.SharePoint.Library.SPRequestInternalClass.EnableModuleFromXml(String bstrSetupDirectory, String bstrFeatureDirectory, String bstrUrl, String bstrXML, Boolean fForceUnghost, ISPEnableModuleCallback pModuleContext)  
 at Microsoft.SharePoint.Library.SPRequest.EnableModuleFromXml(String bstrSetupDirectory, String bstrFeatureDirectory, String bstrUrl, String bstrXML, Boolean fForceUnghost, ISPEnableModuleCallback pModuleContext)     -
 -- End of inner exception stack trace ---  
 at Microsoft.SharePoint.Administration.SPElementDefinitionCollection.ProvisionModules(SPFeaturePropertyCollection props, SPSite site, SPWeb web, SPFeatureActivateFlags activateFlags, Boolean fForce)  
 at Microsoft.SharePoint.Administration.SPElementDefinitionCollection.ProvisionElements(SPFeaturePropertyCollection props, SPWebApplication webapp, SPSite site, SPWeb web, SPFeatureActivateFlags activateFlags, Boolean fForce)  
 at Microsoft.SharePoint.SPFeature.Activate(SPSite siteParent, SPWeb webParent, SPFeaturePropertyCollection props, SPFeatureActivateFlags activateFlags, Boolean fForce)  
 at Microsoft.SharePoint.SPFeatureCollection.AddInternal(SPFeatureDefinition featdef, Version version, SPFeaturePropertyCollection properties, SPFeatureActivateFlags activateFlags, Boolean force, Boolean fMarkOnly)  
 at Microsoft.SharePoint.SPFeatureCollection.CheckSameScopeDependency(SPFeatureDefinition featdefDependant, SPFeatureDependency featdep, SPFeatureDefinition featdefDependency, Boolean fActivateHidden, Boolean fUpgrade, Boolean fForce, Boolean fMarkOnly)  
 at Microsoft.SharePoint.SPFeatureCollection.CheckFeatureDependency(SPFeatureDefinition featdefDependant, SPFeatureDependency featdep, Boolean fActivateHidden, Boolean fUpgrade, Boolean fForce, Boolean fMarkOnly, FailureReason& errType)  
 at Microsoft.SharePoint.SPFeatureCollection.CheckFeatureDependencies(SPFeatureDefinition featdef, Boolean fActivateHidden, Boolean fUpgrade, Boolean fForce, Boolean fThrowError, Boolean fMarkOnly, List`1& missingFeatures)  
 at Microsoft.SharePoint.SPFeatureCollection.CheckFeatureDependencies(SPFeatureDefinition featdef, Boolean fActivateHidden, Boolean fUpgrade, Boolean fForce, Boolean fMarkOnly)  
 at Microsoft.SharePoint.SPFeatureCollection.AddInternal(SPFeatureDefinition featdef, Version version, SPFeaturePropertyCollection properties, SPFeatureActivateFlags activateFlags, Boolean force, Boolean fMarkOnly)


System.Runtime.InteropServices.COMException: Failed to instantiate file "ContentQueryMain.xsl" from module "XSLStyleSheets": The specified list does not exist.  
 at Microsoft.SharePoint.Library.SPRequestInternalClass.EnableModuleFromXml(String bstrSetupDirectory, String bstrFeatureDirectory, String bstrUrl, String bstrXML, Boolean fForceUnghost, ISPEnableModuleCallback pModuleContext)  
 at Microsoft.SharePoint.Library.SPRequest.EnableModuleFromXml(String bstrSetupDirectory, String bstrFeatureDirectory, String bstrUrl, String bstrXML, Boolean fForceUnghost, ISPEnableModuleCallback pModuleContext)


Unknown SPRequest error occurred. More information: 0x80070002


File Not Found: C:\Program Files\Common Files\Microsoft Shared\Web Server Extensions\14\Template\Layouts\EditingMenu\SiteAction.xml


System.InvalidOperationException: Feature '94c94ca6-b32f-4da9-a9e3-1f3d343d7ecb' is not activated
 at this scope.  
 at Microsoft.SharePoint.SPFeatureCollection.Remove(Guid featureId, Boolean force)  
 at Microsoft.SharePoint.ApplicationPages.DeactivateFeaturePage.LnkbtnDeactivateFeature_Click(Object objSender, EventArgs evtargs)  
 at System.Web.UI.WebControls.LinkButton.OnClick(EventArgs e)  
 at System.Web.UI.WebControls.LinkButton.RaisePostBackEvent(String eventArgument)  
 at System.Web.UI.Page.RaisePostBackEvent(IPostBackEventHandler sourceControl, String eventArgument)  
 at System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint)


Error exporting the list named “Announcements” at the URL: Lists/Announcements

Sunday, April 6, 2014

Node.js, C# and SharePoint API

Just curious: is Microsoft plan to integrate Node.js features into C# and SharePoint server side API?

I think it's a MUST, at least for SharePoint online.

Don't know whether I am the only one got this issue: when deploying farm solutions to SharePoint Server, it's always slow. I have CPU Intel Core i7 3770, 32GB RAM, two SSD disks (Intel 520 and Samsung 840 Pro). From performance monitor, I can see that there is no performance bottleneck, but it's still slow.

I am not talking about "minutes", but something like "20 seconds". But it makes me confused: if CPU usage and SSD access is less than 1%, then, what make the deployment procedure so slow?

SharePoint has potential to be much, much faster.

Monday, March 24, 2014

SharePoint 2013 - don't try to run workflow as system account

On SharePoint 2010 or MOSS 2007 with SP1, we cannot trigger workflow automatically as system account. But, if we want, we can manually force the workflow to run under system account.  This is useful in Development environment.

But for SharePoint 2013, it's different.

We still can manually run "SharePoint 2010" edition workflow on SharePoint 2013, but, for "SharePoint 2013" edition workflow, once the workflow is triggered, the "Internal Status" of the workflow instance is first changed to "Started", then end as "Suspended".

So, we have to run workflow as "non-system account", even in Development environment.

Monday, March 17, 2014

SharePoint 2013 - SQL Server connection failure

All of sudden, my SharePoint 2013 development server stopped working.

It says that SharePoint server cannot connect to the configuration database.

Below is the error message I got from windows events log when testing from SQL Server Management studio. It seems that the database connection is in trouble.

Faulting application name: Ssms.exe, version: 2011.110.3000.0, time stamp: 0x5081c1cd
Faulting module name: clr.dll, version: 4.0.30319.18444, time stamp: 0x52717e84
Exception code: 0x80131506
Fault offset: 0x002237de
Faulting process id: 0xd70
Faulting application start time: 0x01cf38bbd9ec2ecd
Faulting application path: E:\Program Files (x86)\Microsoft SQL Server\110\Tools\Binn\ManagementStudio\Ssms.exe
Faulting module path: C:\Windows\Microsoft.NET\Framework\v4.0.30319\clr.dll
Report Id: d1ded40d-a4bb-11e3-8321-005056b4002b


Application: Ssms.exe
Framework Version: v4.0.30319
Description: The process was terminated due to an unhandled exception.
Exception Info: System.AccessViolationException
Stack:
   at SNINativeMethodWrapper.SNIClose(IntPtr)
   at System.Data.SqlClient.SNIHandle.ReleaseHandle()
   at System.Runtime.InteropServices.SafeHandle.InternalFinalize()
   at System.Runtime.InteropServices.SafeHandle.Dispose(Boolean)
   at System.Runtime.InteropServices.SafeHandle.Finalize()


Faulting application name: Ssms.exe, version: 2011.110.3000.0, time stamp: 0x5081c1cd
Faulting module name: ntdll.dll, version: 6.1.7601.22436, time stamp: 0x521eaa80
Exception code: 0xc0000005
Fault offset: 0x000222d2
Faulting process id: 0x6e0
Faulting application start time: 0x01cf38c8fe1da46d
Faulting application path: E:\Program Files (x86)\Microsoft SQL Server\110\Tools\Binn\ManagementStudio\Ssms.exe
Faulting module path: C:\Windows\SysWOW64\ntdll.dll
Report Id: 9775f54d-a4bc-11e3-8321-005056b4002b

After hours of investigation, I believe the problem roots in quite low level. My environment is ESX + Windows Server 2008 R2 + SharePoint Server 2013. I reinstalled windows OS, but the same problem is still there.

Not sure what happened. A ticket is logged with Microsoft, and they are working on it at the moment.

What I can do, is to change SQL Server connection protocol from TCPIP to Named Pipes. That "fixed" the problem.

I will let you know once find the cause.

Monday, March 3, 2014

One-way data integration in SharePoint (in non-real time)

BCS is the normal way to integrate external data source into SharePoint. If the "external data source" is MS SQL Server, it's relatively simple: we can do the job through SharePoint Designer.

However, if we need to grab the data from web services, and don't like Visual Studio (C#), what can we do?

PowerShell scripts.

With the help of Scheduled Tasks, we can import data into SharePoint list, or export data into external data source regularly.

From business users' point of view, the performance is great. And not like "external list" - we get full features of list view!

Thursday, February 27, 2014

The best approach to schedule workflow in SharePoint

You can choose freeware HareP​oint Workflow ​Scheduler to do the job. It's a full-trusted solution and there is no source code. I didn't deploy it to any production environment, but it looks nice.

Or, if you are a developer, you may build a similar module like what I did 3 years ago. You have full control of all features, but, it's not something can be done in a couple of hours.

Recently I switched to PowerShell script and Windows Task Scheduler.

Use Windows Task Scheduler to run PowerShell script which triggers workflows is a simple solution with many extra benefit.

1. Don't need the help from developers, and there is no outage during deployment.

2. No extra license cost.

3. Easy to maintain, easy to extend.

4. Easy to schedule workflows remotely.

5. No outage during maintenance.

etc.

Any drawback? You need to understand PowerShell :-)

Below is the script I built to run workflows.  If you found any bug in it, please let me know.

Thanks for the post from Levente Rög, which saved me a lot of time.

---------------------------------

Add-PSSnapin Microsoft.SharePoint.PowerShell -ErrorAction "SilentlyContinue"
cls

#rm function:/StartSiteWorkflow
function StartSiteWorkflow([string]$siteURL, [string]$siteWorkflow)
{
    Write-Host "StartSiteWorkflow start, ......" -ForegroundColor Green
    Write-Host "siteURL=$siteURL, siteWorkflow=$siteWorkflow" -ForegroundColor Green

    $site = Get-SPSite $siteURL
    $culture = [System.Globalization.CultureInfo]::InvariantCulture
    $wfAssociation = $site.RootWeb.WorkflowAssociations.GetAssociationByName($siteWorkflow, $culture)

    if ( $wfAssociation )
    {
        $assocData = $wfAssociation.AssociationData

        $wfRunOption = [Microsoft.SharePoint.Workflow.SPWorkflowRunOptions]::Synchronous
        $site.WorkflowManager.StartWorkflow($site, $wfAssociation, $assocData, $wfRunOption)
    }
    else
    {
        Write-Error "Workflow association '$siteWorkflow' not found on target web site '$siteURL'."
    }
}

function StartListWorkflows([string]$webURL, [string]$listName, [string]$listWorkflow)
{
    Write-Host "StartListWorkflows start, ......" -ForegroundColor Green
    Write-Host "webURL=$webURL, listName=$listName, listWorkflow=$listWorkflow" -ForegroundColor Green

    $web = Get-SPWeb -Identity $webURL
    $manager = $web.Site.WorkFlowManager

    $list = $web.Lists[$listName]
    if ($list -ne $null)
    {
        $culture = [System.Globalization.CultureInfo]::InvariantCulture
        $assoc = $list.WorkflowAssociations.GetAssociationByName($listWorkflow, $culture)
        if ($assoc -ne $null)
        {
            $data = $assoc.AssociationData

            $items = $list.Items
            $myArrayList = New-object System.Collections.Generic.List[int]
            Write-Host ""
            Write-Host "Collecting item id......"
            foreach($item in $items)
            {
                Write-Host -NoNewline ".";
                $myArrayList.add($item.ID)
            }  

            $arraycount = $myArrayList.Count;
            Write-Host ""
            Write-Host "Trigger all " $arraycount " workflows......"
            for ($i = 0; $i -lt $arraycount; $i++)
            {
                Write-Host -NoNewline "s";
                $itemCurrent = $list.GetItemById($myArrayList[$i])

                $itemCurrent["Action"] = "Update"    #may not need this step
                $itemCurrent.SystemUpdate()          #may not need this step

                $itemCurrent = $list.GetItemById($myArrayList[$i])
                $wfRunOption = [Microsoft.SharePoint.Workflow.SPWorkflowRunOptions]::Synchronous
                $wf = $manager.StartWorkFlow($itemCurrent,$assoc,$data,$wfRunOption)
                Write-Host -NoNewline "e";
            }
            Write-Host ""
            Write-Host ""
        }
        else
        {
            Write-Host "invalid workflow name." -ForegroundColor Red
        }
    }
    else
    {
        Write-Host "invalid list." -ForegroundColor Red
    }

    $manager.Dispose()
    $web.Dispose()
}

StartSiteWorkflow "http://SharePointServer/sites/site1" "Site Workflow Name"

StartListWorkflows "http://SharePointServer/sites/site1" "ListName" "List Workflow Name"

Tuesday, February 11, 2014

Error: Upload Multiple Documents Failed

After switching to NLB (network load balancing) server, "Upload Multiple Documents" failed on one of the web applications, but single document uploading works fine.

NLB is done through Citrix Netscaler. I cannot find anything wrong compare with other virtual servers (for other SharePoint web applications).

IIS site is created through SharePoint CA. Nothing different compare to other web application sites.

In the end, it turns out that the DNS record settings are incorrect. The record type should be "Host (A)" instead of "Alias (CNAME)".

I hope this can save you some time :-)

[Update: 2014-02-27]

May need to install a Microsoft Hotfix of Office 2010.