Create WSP (Cab) file on SharePoint Server using SharePoint Built-in functionality

SharePoint Server 2010 and Foundation too has a namespace “Microsoft.SharePoint.Utilities.Cab”. In this namespace there are all functions you need to create CAB=WSP files. – I have already used this functionality in a private project: https://blog.kenaro.com/2012/02/29/demo-generating-sandboxed-solutions-through-code-for-sharepoint-2010/

Here is the PowerShell script to create create CAB = WSP files on a SharePoint server:

# Written by Ingo Karstein (https://blog.kenaro.com)
#   v0.1.0.0 / 2012-05-01

$destWSPfilename = "C:UsersAdministratorSourceMyWSP.wsp"
$sourceSolutionDir = [System.IO.DirectoryInfo]"C:UsersAdministratorSourceMyWSP_Content"

##################################

$a = [System.Reflection.Assembly]::LoadWithPartialName("Microsoft.SharePoint")
$ctor = $a.GetType("Microsoft.SharePoint.Utilities.Cab.CabinetInfo").GetConstructors("Instance, NonPublic")[0]

$cabInf = $ctor.Invoke($destWSPfilename );

$mi = $cabInf.GetType().GetMethods("NonPublic, Instance, DeclaredOnly")
$mi2 = $null
foreach( $m in $mi ) {
    if( $m.Name -eq "CompressDirectory" -and $m.GetParameters().Length -eq 4 ) {
        $mi2 = $m;
        break;
    };
}

$mi2.Invoke($cabInf, @( $sourceSolutionDir.FullName, $true, -1,$null ));

Error in crawl log: “The SharePoint item being crawled returned an error when attempting to download the item”

Another error in the crawl log:

SNAGHTML3dde524

Using Fiddler I figured out that the pages report an “incompatible browser” error if the SharePoint crawler opens that pages. It seems that the gantt view only renders content for an up-to-date Internet Explorer – identified by the user agent.

The solution is to change the user agent used by the SharePoint crawler component.

Microsoft’s “procmon” showed me this registry key:

HKEY_LOCAL_MACHINESOFTWAREMicrosoftOffice Server14.0SearchGlobalGathering ManagerUserAgent

I set this to the IE9 user agent string found here: http://blogs.msdn.com/b/ie/archive/2010/03/23/introducing-ie9-s-user-agent-string.aspx

It’s:

Mozilla/5.0 (compatible; MSIE 9.0; Windows NT 6.1; Trident/5.0)

After the next crawl the errors related to this problem where gone.

Error in crawl log: “The server is unavailable and could not be accessed. The server is probably disconnected from the network.” (SharePoint 2010)

I got this error messages a thousand times:

image

Solution 1:

I added the root certification authority certificates and the intermediate certification authority certificates of all SSL certificates to the SharePoint root cert store:

$rootca = New-Object System.Security.Cryptography.X509Certificates.X509Certificate2("$(join-path (split-path $MyInvocation.MyCommand.Path) 'root-ca.cer')") 
$interca = New-Object System.Security.Cryptography.X509Certificates.X509Certificate2("$(join-path (split-path $MyInvocation.MyCommand.Path) 'inter-ca.cer')") 

New-SPTrustedRootAuthority –Name "GlobalSign Root CA" –Certificate $rootca 
New-SPTrustedRootAuthority –Name "GlobalSign Domain Validation CA" –Certificate $interca 

In my case both certificates are saved as CER files in the same directory as the script file above.

 

To get the root and intermediate CA cert open the Internet Explorer and navigate to the SharePoint site.

Click the “Security Report” button:

image

Click “View certificates”

image

Select every certificate in the tree but not the last level: this last certificate is your SSL certificate itself. The top certificate is the “root certification authority certificate” and all certificates (1 or more) between the top node and the “last” certificate are the “intermediate certification authority certificates”. Select each of them and click “View Certificate”.

image

In the next dialog click “Details” and then click “Copy to file”

image

Solution 2:

Maybe this is another solution for the problem.

First open the Farm Search Administration page (http(s)://<ca>:<port>/searchfarmdashboard.aspx).

Then change the setting “Ignore SSL warnings” to “yes”:

image

Demo: Generating Sandboxed Solutions Through Code for SharePoint 2010

Some weeks ago I startet a new private dev project.

To reach one of the goals of the project I thought about the possibility to create Sandboxed Solutions at runtime. I’ve extracted this aspect of the project to show you how to create Sandboxed Solutions on the fly.

 

In my demo scenario for this blog article I’d like to have a custom list that enables me to create entries in the “Edit Control Block” at runtime. For every list item that is created in the custom list a Sandboxed Solution will be created and uploaded to the solution gallery of the site collection.

 

Let’s have a look:

 

1. First we look into the solution gallery of “http://sharepoint.local”. It’s empty.

image

2. I’ve created my demo solution and deployed it. This solution contains a list template and list instance. The list instance is shown in the Quick Launch as “Dynamic Menu”.

image

3. Now I create a new entry in this list:

image

image

4. Now we look into the solution gallery:

image

There is a new Sandboxed Solution in it!!

5. In the Shared Documents libary I have a single file “My PDF”. Now I open the files context menu:

image

image

6. After creating a new item in the “Dynamic Menu” I get a new entry in the Edit Control Menu:

image

image

This opens a new Outlook Window with the item URL as body.

image

7. For every generated solution there is an entry in the Site Collection Features list:

image

image

 

How does it work?

1. First I’ve created a list template and list instance.

2. Then I’ve created a Event Receiver.

image

There are two methods:

  • Utilities.RemoveSolution
  • Utilities.AddSolution

3. Method “Utilities.AddSolution”

This static method creates the Sandboxed Solution.

Therefore internal non-public methods of SharePoint are invoked. This is the most interesting aspect of the demo project!

ConstructorInfo ctor = typeof(Microsoft.SharePoint.SPSolutionExporter).Assembly.GetType("Microsoft.SharePoint.Utilities.Cab.CabinetInfo").GetConstructors(BindingFlags.Instance | BindingFlags.NonPublic)[0];
object cabInf = ctor.Invoke(new object[] { solutionFileName });

MethodInfo[] mi = cabInf.GetType().GetMethods(BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly);
MethodInfo mi2 = null;
foreach( var m in mi )
    if( m.Name == "CompressDirectory" && m.GetParameters().Length == 4 )
    {
       mi2 = m;
       break;
    };

mi2.Invoke(cabInf, new object[] { solutionDir.FullName, true, -1, null });

 

In the source code before this snippet I create the structure of a WSP file in a temporary folder in the file system. The shown code creates the WSP file that I upload into the solution gallery.

4. Utilities.RemoveSolution

This static method removes the solution from the solution gallery.

5. You can download the complete code from codeplex:

http://spautogensolution.codeplex.com/

Minify JavaScript and PowerShell scripts by using PowerShell

There are several tools out there to minify JavaScript files. – You don’t know “minification”? Look here: http://en.wikipedia.org/wiki/Minification_(programming)

Common tools are:

For those of you that like PowerShell as I like it I’ve created a PowerShell module that let’s you minify JavaScript files and PowerShell script files.

Here it is on Codeplex:

http://minifyps.codeplex.com/

You can use the module like this:

cls

#module in the same path as the script:
Import-Module (join-path (split-path $MyInvocation.mycommand.path) "minjs")

#module in a default module path like "C:WindowsSystem32WindowsPowerShellv1.0ModulesminifyPS"
#Import-Module "minjs"

$str = @"
    var test = 'some JavascriptCode';
"@

$min = (minify -inputData $str -inputDataType "js")

[System.Windows.Forms.Clipboard]::SetText($min )

The module works like this:

1. Split script source code into typed chunks:

  • Code
  • Single Quoted String
  • Double Quoted String
  • Multiline Comment
  • End-of-line Comment

2. Remove all unwanted chunks such as comments

3. Process all remaining chunks by using regular expressions

4. Combine all processed chucks to a result string

 

For every language (JavaScript and PowerShell) there is a config section in the script.

image

There are two files in the package at Codeplex:

image

  • “minJS.psm1” => This is the module
  • “minJSDemo.ps1” => This is a demo script that uses the module

The demo script contains a piece of JavaScript that will be minified. And the script will minify itself and the module to an “output” sub directory that is created by the script if it does not exist.

This is a screenshot after running the demo script:

image

If you execute “minJSDemo.min.ps1” in the output folder you execute the minified version of “minJSDemo.ps1” and the minified version of the module itself (“minJSmin.psm1”).

 

The module is ALPHA at the moment. I’ve tested it in some projects and it seems to work as expected.

I’ve tested it with a huge JavaScript file: “core.debug.js” of Microsoft SharePoint:

C:Program FilesCommon FilesMicrosoft SharedWeb Server Extensions14TEMPLATELAYOUTS<lcid>CORE.debug.js

I’ve renamed the original file to “core.debug.js.bak”, minified it and saved the result as “code.debug.js”. So it’s used in the browser. (The minification of ~360KB takes 90 seconds.The minification module is slow…)  

It’s not possible to use the minified version. It seems that the original “code.debug.js” has some bugs. For example in line 42: There is no trailing “;”

image

But because of removing the line break this results in:

image

This causes the following JavaScript error in Internet Exlorer:

image

I’d be happy to hear about your experiences with the module. Please post comment, write me an e-mail or join the Codeplex-project!

Walkaround for common “TaxonomyPicker.ascx” error in Windows Event Log: SharePoint Feature that renames the file

There is a common error in SharePoint 2010: On almost every (web frontend) server you can find this error in the Windows Event Log “Application”:

Event Type: Error
Event Source: SharePoint Foundation
Event Category: None
Event ID: 7043
Computer: SERVERNAME
Description: Load control template file /_controltemplates/TaxonomyPicker.ascx failed: Could not load type ‘Microsoft.SharePoint.Portal.WebControls.TaxonomyPicker’ from assembly ‘Microsoft.SharePoint.Portal, Version=14.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c’.

image

The problem is described in many blogs and sites, e.g.:

To solve the problem there’s no other way than renaming the “TaxonomyPicker.ascx” file.

On a single-server farm it’s not that problem but in a huge farm with about 100 servers … ?

I’ve created simple SharePoint 2010 solution that will do the job for you.

The solution deploys a SharePoint Timer Job Definition and the farm feature event receiver creates two timer jobs for every web application on the system. The first timer job is a “one-time” job, the other one is a “daily” job. Each job checks the SharePoint hive on the local disk of every server and renames the “TaxonomyPicker.ascx” file to “TaxonomyPicker.ascx.disabled”, if the file is present. If the file “TaxonomyPicker.ascx” not present or already renamed it does nothing.

the “one-time” job runs some seconds after the feature activation and will delete itself after running. The “daily” job executes every day between 1am and 2am.

You can download this code at Codeplex. Please feel free to modify it, but please send me your improvements or request “edit” permissions on codeplex. – I’m sure there are possible improvements. It’s a “quick dev project”.

http://spdisabletaxpicker.codeplex.com/

When you disable the farm feature the file “TaxonomyPicker.ascx.disabled” is renamed back to “TaxonomyPicker.ascx”!

Be sure you test the feature in a dev system before you use it in a live system!!!! I only provide the source code he. Please compile it by yourself und use the solution as you want.

Walkaround for problems accessing a diffrent web by “Linq to SharePoint” inside server code.

At the weekend I tried to access a diffrent SharePoint Web (SPWeb) from inside server code (ASPX application page).

Before I created interface classes to the “diffrent SharePoint Web” by using SPMetal.

In the server side code I used this snipped to access the “diffrent SharePoint Web” by using the generated interface:

using System;
using Microsoft.SharePoint;
using Microsoft.SharePoint.WebControls;

namespace myProject
{
public partial class ManageFeature : LayoutsPageBase
{
protected void Page_Load(object sender, EventArgs e)
{

string diffrentWebUrl = “http://diffrentWebUrl”;
using( DiffrentWebDataContext dc = new DiffrentWebDataContext(diffrentWebUrl) )
{
var x1 = from x in dc.ListOnDiffrentWeb
                             select x;
var x2 = x1.ToList();
}
}
}
}

This failed because inside server code you cannot access a diffrent Web by using Linq to SharePoint.

Read this blog post Chun Liu:

http://blogs.msdn.com/b/chunliu/archive/2010/04/17/linq-to-sharepoint-query-across-site-collections.aspx

Here is a suggestion how to solve this by Pascal Be:

http://social.technet.microsoft.com/Forums/sv-SE/sharepoint2010programming/thread/715ddcbb-619d-4688-8d99-d7a6aa078307

I’ve created a helper class for this workaround:

using System;
using System.IO;
using System.Web;
using Microsoft.SharePoint;
using Microsoft.SharePoint.WebControls;

namespace ik.SharePoint2010
{
    public class CustomSPContext : IDisposable {
        private HttpContext originalContext;

        public static CustomSPContext CreateSPCustomContext(SPWeb contextWeb)
        {
            return new CustomSPContext(contextWeb);
        }

        private CustomSPContext(SPWeb contextWeb)
        {
            originalContext = HttpContext.Current;

            string url = contextWeb.Url;
            HttpRequest httpRequest = new HttpRequest("", url, "");
            HttpContext.Current = new HttpContext(httpRequest, new HttpResponse(new StringWriter()));
            SPControl.SetContextWeb(HttpContext.Current, contextWeb);
        }

        public void Dispose()
        {
            HttpContext.Current = originalContext;
        }
    }
}

 

You can use it like this:

using System;
using Microsoft.SharePoint;
using Microsoft.SharePoint.WebControls;

namespace kc.GlobalNotification
{
    public partial class ManageFeature : LayoutsPageBase {
        protected void Page_Load(object sender, EventArgs e)
        {
            string diffrentWebUrl = "http://diffrentWebUrl";

            using( var site = new SPSite(diffrentWebUrl) )
            {
                using( var web = new SPWeb(diffrentWebUrl) )
                {
                    using( ik.SharePoint2010.CustomSPContext.CreateSPCustomContext(web) )
                    {

using( DiffrentWebDataContext dc = new DiffrentWebDataContext(diffrentWebUrl) ){

                           var x1 = from x in dc.ListOnDiffrentWeb
                                    select x;
                           var x2 = x1.ToList();

}

                    }
                }
            }
        }
    }
}

Walkthrough: Create simple WCF Web Service for SharePoint 2010 with Visual Studio 2010

In this “Walkthrough” I’d like to show you how to create a simple WCF Web Service for SharePoint 2010.

This Web Service will provide two methods:

  • Ping => Just as test.
  • GetUsedEmailAliasses => This method reports all aliasses used for “E-Mail enabled lists” in SharePoint.

Here is the code: http://spwcfwebservicedemo.codeplex.com/

Let’s start.

1. Create a new SharePoint 2010 project in Visual Studio 2010. Use the “Empty Project” template. Name the project “ik.SharePoint2010.SPWCFWebServiceDemo”.

image

2. In the project creation wizard specify the Central Administration address as deployment location. You need to deploy as “Farm Solution”:

image

3. Now add this Assembly References:

  • Microsoft.SharePoint.Client
  • Microsoft.SharePoint.Client.Runtime
  • Microsoft.SharePoint.Client.ServerRuntime
    (You may need to locate this assembly in the file system: “C:WindowsassemblyGAC_MSILMicrosoft.SharePoint.Client.ServerRuntime14.0.0.0__71e9bce111e9429cMicrosoft.SharePoint.Client.ServerRuntime.dll”)
  • System.Configuration
  • System.ServiceModel
  • System.ServiceModel.Web

Now my Assembly Reference tree looks like this:

4. Now map the SharePoint hive folder “Layouts” to your project:

a) Right click your project in the Solution Explorer Pane

b) In the context menu open sub menu “Add” and click “SharePoint Mapped Folder”

c) Select this:

image

d) Click “OK”

5. Create a sub folder named “ik.SharePoint2010.SPWCFWebServiceDemo” in folder “Layouts”

6. Add a new project item of type “Interface” to your project. Name it “ISPWCFSvc.cs”.

using System;
using System.Collections.Generic;
using System.Linq;
using System.Runtime.Serialization;
using System.Runtime.InteropServices;
using System.ServiceModel;
using System.ServiceModel.Web;

namespace ik.SharePoint2010.SPWCFWebServiceDemo
{
    [ServiceContract(Namespace="http://schemas.microsoft.com/sharepoint/soap/"),      Guid("f01e2ff6-c291-4b8b-a154-cd7059ed4900")]
    public interface ISPWCFSvc  {
        [OperationContract, WebInvoke(Method = "GET")]
        List<string> GetUsedEmailAliasses();

        [OperationContract, WebInvoke(Method = "GET")]
        string Ping();
    }
}
7. Add a new project item of type “Class” and name it “SPWCFSvc.cs”
using System;
using System.Collections.Generic;
using System.Reflection;
using System.Runtime.InteropServices;
using System.Security.Permissions;
using System.ServiceModel;
using System.ServiceModel.Activation;
using System.Web;
using Microsoft.SharePoint;
using Microsoft.SharePoint.Administration;
using Microsoft.SharePoint.Client;
using Microsoft.SharePoint.Security;

namespace ik.SharePoint2010.SPWCFWebServiceDemo
{
    [Guid("ae428eb5-02d1-4e50-8cee-eb3806f16ffd"),
    ServiceBehavior(Namespace = "http://schemas.microsoft.com/sharepoint/soap/"),
    AspNetCompatibilityRequirements(RequirementsMode = AspNetCompatibilityRequirementsMode.Required),
    ClientRequestServiceBehavior,
    SharePointPermission(SecurityAction.Demand, ObjectModel = true),
    AspNetHostingPermission(SecurityAction.Demand, Level = AspNetHostingPermissionLevel.Minimal)]
    public class SPWCFSvc : ISPWCFSvc  {
        [SharePointPermission(SecurityAction.Demand, ObjectModel = true)]
        public List<string> GetUsedEmailAliasses()
        {
            List<string> l = new List<string>();

            SPProcessIdentity pi = SPContext.Current.Site.WebApplication.Farm.TimerService.ProcessIdentity;
            string userName = pi.Username;
            object configDB = pi.GetType().GetProperty("ConfigurationDatabase", BindingFlags.Instance | BindingFlags.NonPublic).GetValue(pi, null);
            SPServer server = (SPServer)configDB.GetType().GetProperty("Server").GetValue(configDB, null);
            string dbName = (string)configDB.GetType().GetProperty("Name").GetValue(configDB, null);
            string serverName = server.Name;

            SPSecurity.RunWithElevatedPrivileges(() =>
            {
                System.Data.SqlClient.SqlConnection s = new System.Data.SqlClient.SqlConnection(new System.Data.SqlClient.SqlConnectionStringBuilder {
                    DataSource = serverName,
                    InitialCatalog = dbName,
                    IntegratedSecurity = true }.ConnectionString);

                SPConfigDBDataContext dc = new SPConfigDBDataContext(s);

                foreach( var item in dc.EmailEnabledLists )
                {
                    l.Add(item.Alias);
                }
            });

            return l;
        }

        [SharePointPermission(SecurityAction.Demand, ObjectModel = true)]
        public string Ping()
        {
            return "Pong";
        }
    }
}
8. Now add a new “Text File” project item and name it “spwcfsvc.svc”
<% @ServiceHost Service="$SharePoint.Type.ae428eb5-02d1-4e50-8cee-eb3806f16ffd.AssemblyQualifiedName$" Factory="Microsoft.SharePoint.Client.Services.MultipleBaseAddressWebServiceHostFactory, Microsoft.SharePoint.Client.ServerRuntime, Version=14.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c"%>

Here we use an existing service factory of SharePoint that will handle the service instanciation for us.

In this file we use the token replacement functionality of Visual Studio 2010 for SharePoint 2010 development. We like to replace the token “$SharePoint.Type.ae428eb5-02d1-4e50-8cee-eb3806f16ffd.AssemblyQualifiedName$” through the “real” full qualified name during package creation.

By default *.svc files will not be processed by the token replacement engine. We need to specify *.svc files for that build step. Therefore we edit the C# project file in notepad.  Insert this line as shown in the screenshot:

<TokenReplacementFileExtensions>svc</TokenReplacementFileExtensions>

image

After deploying the solution you may have a look into the SharePoint hive and look into “spwcfsvc.svc”

9. Now Copy & Paste this file into the you folder in the mapped Layouts folder:

C:Program FilesCommon FilesMicrosoft SharedWeb Server Extensions14ISAPIweb.config

10. You need to edit this file. Remove the complete “<system.web>” tag and the (four) “location” tags at the beginning of the copied file! – The configuration settings in the copied & modified web.config file will manage the diffrent authentication methods for us. This works by using the class attribute “ClientRequestServiceBehavior” in the code above.

11. Now we add a “Linq to SQL” connection to the SharePoint Configuration database. Be sure only to read this DB!!!

12. Add a new project item of type “Linq to SQL Classes” to the project. Name it “SPConfigDB.dbml”

image

13. In the Server Explorer of Visual Studio 2010 create a connection to the SharePoint Configuration DB of your development environment. – After that, open the connection, open the “Table” node and select “EmailEnabledLists”.

image

14. Drag the “EmailEnabledLists” node to the “SPConfigDB.dbml” canvas. – It looks like this:

image

15. In the Properties Pane set the “Context Namespace” property to “ik.SharePoint2010.SPWCFWebServiceDemo”. (If you do not see this properties like in the screenshot below you need to right click the “SPConfigDB.dbml” project item node in the Solution explorer and click “Properties” in the context menu.

image

16. Now you should be able to compile and deploy your project.

17. Edit the startup settings. In the “Debug” select “Start browser with URL” and enter there the URL to your webservice: “http://<central-administration-url-and-port>/_layouts/ik.sharepoint2010.spwcfwebservicedemo/spwcf.svc/GetUsedEmailAliasses”

SNAGHTML4b070d4

18. Now start the project. You get something like this:

SNAGHTML4acbe57

I’ve only one e-mail enabled list or library in my current dev system.

Migration Issue – Error in Upgrade Log: “Exception thrown while applying the global template to the web with URL “(unknown)” (Id: ”) from site with URL “(unknown)” (Id: ”). Adding web to the exceptions list. Exception: System.IO.FileNotFoundException: The site with the id could not be found.”

In my curent migration project I got this error in an Content Database upgrade log on the new SharePoint 2010 farm:

Template MPS#0: Exception thrown while applying the global template to the web with URL “(unknown)” (Id: ‘a98475b1-385d-4ac6-bc1b-226f2e35a27e’) from site with URL “(unknown)” (Id: ‘3e800bc3-296f-47f0-a04d-b1e4ae385cb8’). Adding web to the exceptions list. Exception: System.IO.FileNotFoundException: The site with the id 3e800bc3-296f-47f0-a04d-b1e4ae385cb8 could not be found.

Template <templateId>: Exception thrown while applying the global template to the web with URL “(unknown)” (Id: ‘<guid>‘) from site with URL “(unknown)” (Id: ‘<guid>’). Adding web to the exceptions list. Exception: System.IO.FileNotFoundException: The site with the id <guid> could not be found.

This is a piece of text of the upgrade log file:

 
[ScriptEditor] [SPWebTemplateSequence] [DEBUG] [12/8/2011 7:04:24 PM]: Template MPS#0: Exception thrown while applying the global template to the web with URL "(unknown)" (Id: 'e5c2cec5-7d3a-483b-ac55-0ca60a7ba432') from site with URL "(unknown)" (Id: '3e800bc3-296f-47f0-a04d-b1e4ae385cb8'). Adding web to the exceptions list. Exception: System.IO.FileNotFoundException: The site with the id 3e800bc3-296f-47f0-a04d-b1e4ae385cb8 could not be found.
   at Microsoft.SharePoint.SPSite..ctor(Guid id, SPFarm farm, SPUrlZone zone, SPUserToken userToken)
   at Microsoft.SharePoint.SPSite..ctor(Guid id)
   at Microsoft.SharePoint.Upgrade.SPWebTemplateSequence.ApplyGlobalTemplateToWebs(List`1 lstwebinfoToUpgrade, List`1& lstwebinfoExceptions)
[ScriptEditor] [SPWebTemplateSequence] [DEBUG] [12/8/2011 7:04:24 PM]: Template MPS#0: Exception thrown while applying the global template to the web with URL "(unknown)" (Id: 'a98475b1-385d-4ac6-bc1b-226f2e35a27e') from site with URL "(unknown)" (Id: '3e800bc3-296f-47f0-a04d-b1e4ae385cb8'). Adding web to the exceptions list. Exception: System.IO.FileNotFoundException: The site with the id 3e800bc3-296f-47f0-a04d-b1e4ae385cb8 could not be found.
   at Microsoft.SharePoint.SPSite..ctor(Guid id, SPFarm farm, SPUrlZone zone, SPUserToken userToken)
   at Microsoft.SharePoint.SPSite..ctor(Guid id)
   at Microsoft.SharePoint.Upgrade.SPWebTemplateSequence.ApplyGlobalTemplateToWebs(List`1 lstwebinfoToUpgrade, List`1& lstwebinfoExceptions)
[ScriptEditor] [SPWebTemplateSequence] [DEBUG] [12/8/2011 7:04:24 PM]: Template MPS#0: Exception thrown while applying the global template to the web with URL "(unknown)" (Id: '71f74b12-8ba9-4483-8554-38894878a620') from site with URL "(unknown)" (Id: '3e800bc3-296f-47f0-a04d-b1e4ae385cb8'). Adding web to the exceptions list. Exception: System.IO.FileNotFoundException: The site with the id 3e800bc3-296f-47f0-a04d-b1e4ae385cb8 could not be found.
   at Microsoft.SharePoint.SPSite..ctor(Guid id, SPFarm farm, SPUrlZone zone, SPUserToken userToken)
   at Microsoft.SharePoint.SPSite..ctor(Guid id)
   at Microsoft.SharePoint.Upgrade.SPWebTemplateSequence.ApplyGlobalTemplateToWebs(List`1 lstwebinfoToUpgrade, List`1& lstwebinfoExceptions)
[ScriptEditor] [SPWebTemplateSequence] [DEBUG] [12/8/2011 7:04:24 PM]: Template MPS#0: Exception thrown while applying the global template to the web with URL "(unknown)" (Id: '48b3e9f9-e9fa-4981-93ce-3dec85dc3ee7') from site with URL "(unknown)" (Id: '3e800bc3-296f-47f0-a04d-b1e4ae385cb8'). Adding web to the exceptions list. Exception: System.IO.FileNotFoundException: The site with the id 3e800bc3-296f-47f0-a04d-b1e4ae385cb8 could not be found.
   at Microsoft.SharePoint.SPSite..ctor(Guid id, SPFarm farm, SPUrlZone zone, SPUserToken userToken)
   at Microsoft.SharePoint.SPSite..ctor(Guid id)
   at Microsoft.SharePoint.Upgrade.SPWebTemplateSequence.ApplyGlobalTemplateToWebs(List`1 lstwebinfoToUpgrade, List`1& lstwebinfoExceptions)
[ScriptEditor] [SPWebTemplateSequence] [DEBUG] [12/8/2011 7:04:24 PM]: Template MPS#0: Exception thrown while applying the global template to the web with URL "(unknown)" (Id: '75ddba70-768c-435e-96a1-4491c61083b6') from site with URL "(unknown)" (Id: '3e800bc3-296f-47f0-a04d-b1e4ae385cb8'). Adding web to the exceptions list. Exception: System.IO.FileNotFoundException: The site with the id 3e800bc3-296f-47f0-a04d-b1e4ae385cb8 could not be found.
   at Microsoft.SharePoint.SPSite..ctor(Guid id, SPFarm farm, SPUrlZone zone, SPUserToken userToken)
   at Microsoft.SharePoint.SPSite..ctor(Guid id)
   at Microsoft.SharePoint.Upgrade.SPWebTemplateSequence.ApplyGlobalTemplateToWebs(List`1 lstwebinfoToUpgrade, List`1& lstwebinfoExceptions)
[ScriptEditor] [SPWebTemplateSequence] [DEBUG] [12/8/2011 7:04:24 PM]: Template MPS#0: Exception thrown while applying the global template to the web with URL "(unknown)" (Id: 'ebb027c8-56ec-4526-9962-514ef0b33f7a') from site with URL "(unknown)" (Id: '3e800bc3-296f-47f0-a04d-b1e4ae385cb8'). Adding web to the exceptions list. Exception: System.IO.FileNotFoundException: The site with the id 3e800bc3-296f-47f0-a04d-b1e4ae385cb8 could not be found.
   at Microsoft.SharePoint.SPSite..ctor(Guid id, SPFarm farm, SPUrlZone zone, SPUserToken userToken)
   at Microsoft.SharePoint.SPSite..ctor(Guid id)
   at Microsoft.SharePoint.Upgrade.SPWebTemplateSequence.ApplyGlobalTemplateToWebs(List`1 lstwebinfoToUpgrade, List`1& lstwebinfoExceptions)
[ScriptEditor] [SPWebTemplateSequence] [DEBUG] [12/8/2011 7:04:24 PM]: Template MPS#0: Exception thrown while applying the global template to the web with URL "(unknown)" (Id: 'bedbd386-98cd-4070-ab96-6dc5a58c2908') from site with URL "(unknown)" (Id: '3e800bc3-296f-47f0-a04d-b1e4ae385cb8'). Adding web to the exceptions list. Exception: System.IO.FileNotFoundException: The site with the id 3e800bc3-296f-47f0-a04d-b1e4ae385cb8 could not be found.
   at Microsoft.SharePoint.SPSite..ctor(Guid id, SPFarm farm, SPUrlZone zone, SPUserToken userToken)
   at Microsoft.SharePoint.SPSite..ctor(Guid id)
   at Microsoft.SharePoint.Upgrade.SPWebTemplateSequence.ApplyGlobalTemplateToWebs(List`1 lstwebinfoToUpgrade, List`1& lstwebinfoExceptions)
[ScriptEditor] [SPWebTemplateSequence] [DEBUG] [12/8/2011 7:04:24 PM]: Template MPS#0: Exception thrown while applying the global template to the web with URL "(unknown)" (Id: '22a173d5-68e3-40a4-b749-71f5c26a57d7') from site with URL "(unknown)" (Id: '3e800bc3-296f-47f0-a04d-b1e4ae385cb8'). Adding web to the exceptions list. Exception: System.IO.FileNotFoundException: The site with the id 3e800bc3-296f-47f0-a04d-b1e4ae385cb8 could not be found.
   at Microsoft.SharePoint.SPSite..ctor(Guid id, SPFarm farm, SPUrlZone zone, SPUserToken userToken)
   at Microsoft.SharePoint.SPSite..ctor(Guid id)
   at Microsoft.SharePoint.Upgrade.SPWebTemplateSequence.ApplyGlobalTemplateToWebs(List`1 lstwebinfoToUpgrade, List`1& lstwebinfoExceptions)
[ScriptEditor] [SPWebTemplateSequence] [DEBUG] [12/8/2011 7:04:24 PM]: Template MPS#0: Exception thrown while applying the global template to the web with URL "(unknown)" (Id: 'b4e93fdf-9412-44ad-9402-77f215534d88') from site with URL "(unknown)" (Id: '3e800bc3-296f-47f0-a04d-b1e4ae385cb8'). Adding web to the exceptions list. Exception: System.IO.FileNotFoundException: The site with the id 3e800bc3-296f-47f0-a04d-b1e4ae385cb8 could not be found.
   at Microsoft.SharePoint.SPSite..ctor(Guid id, SPFarm farm, SPUrlZone zone, SPUserToken userToken)
   at Microsoft.SharePoint.SPSite..ctor(Guid id)
   at Microsoft.SharePoint.Upgrade.SPWebTemplateSequence.ApplyGlobalTemplateToWebs(List`1 lstwebinfoToUpgrade, List`1& lstwebinfoExceptions)
[ScriptEditor] [SPWebTemplateSequence] [DEBUG] [12/8/2011 7:04:24 PM]: Template MPS#0: Exception thrown while applying the global template to the web with URL "(unknown)" (Id: 'be229958-2680-4d85-ba72-79f036ab075a') from site with URL "(unknown)" (Id: '3e800bc3-296f-47f0-a04d-b1e4ae385cb8'). Adding web to the exceptions list. Exception: System.IO.FileNotFoundException: The site with the id 3e800bc3-296f-47f0-a04d-b1e4ae385cb8 could not be found.
   at Microsoft.SharePoint.SPSite..ctor(Guid id, SPFarm farm, SPUrlZone zone, SPUserToken userToken)
   at Microsoft.SharePoint.SPSite..ctor(Guid id)
   at Microsoft.SharePoint.Upgrade.SPWebTemplateSequence.ApplyGlobalTemplateToWebs(List`1 lstwebinfoToUpgrade, List`1& lstwebinfoExceptions)
[ScriptEditor] [SPWebTemplateSequence] [DEBUG] [12/8/2011 7:04:24 PM]: Template MPS#0: Exception thrown while applying the global template to the web with URL "(unknown)" (Id: '79ae9a08-845b-4502-affe-a836b7783ae8') from site with URL "(unknown)" (Id: '3e800bc3-296f-47f0-a04d-b1e4ae385cb8'). Adding web to the exceptions list. Exception: System.IO.FileNotFoundException: The site with the id 3e800bc3-296f-47f0-a04d-b1e4ae385cb8 could not be found.
   at Microsoft.SharePoint.SPSite..ctor(Guid id, SPFarm farm, SPUrlZone zone, SPUserToken userToken)
   at Microsoft.SharePoint.SPSite..ctor(Guid id)
   at Microsoft.SharePoint.Upgrade.SPWebTemplateSequence.ApplyGlobalTemplateToWebs(List`1 lstwebinfoToUpgrade, List`1& lstwebinfoExceptions)
[ScriptEditor] [SPWebTemplateSequence] [DEBUG] [12/8/2011 7:04:24 PM]: Template MPS#0: Exception thrown while applying the global template to the web with URL "(unknown)" (Id: '27a97c8e-3652-4fe2-9fe2-ca8d47eca28d') from site with URL "(unknown)" (Id: '3e800bc3-296f-47f0-a04d-b1e4ae385cb8'). Adding web to the exceptions list. Exception: System.IO.FileNotFoundException: The site with the id 3e800bc3-296f-47f0-a04d-b1e4ae385cb8 could not be found.
   at Microsoft.SharePoint.SPSite..ctor(Guid id, SPFarm farm, SPUrlZone zone, SPUserToken userToken)
   at Microsoft.SharePoint.SPSite..ctor(Guid id)
   at Microsoft.SharePoint.Upgrade.SPWebTemplateSequence.ApplyGlobalTemplateToWebs(List`1 lstwebinfoToUpgrade, List`1& lstwebinfoExceptions)
[ScriptEditor] [SPWebTemplateSequence] [DEBUG] [12/8/2011 7:04:24 PM]: Template MPS#0: Exception thrown while applying the global template to the web with URL "(unknown)" (Id: '4d755906-d3ca-4c23-b505-d7f0f5ef0a2c') from site with URL "(unknown)" (Id: '3e800bc3-296f-47f0-a04d-b1e4ae385cb8'). Adding web to the exceptions list. Exception: System.IO.FileNotFoundException: The site with the id 3e800bc3-296f-47f0-a04d-b1e4ae385cb8 could not be found.
   at Microsoft.SharePoint.SPSite..ctor(Guid id, SPFarm farm, SPUrlZone zone, SPUserToken userToken)
   at Microsoft.SharePoint.SPSite..ctor(Guid id)
   at Microsoft.SharePoint.Upgrade.SPWebTemplateSequence.ApplyGlobalTemplateToWebs(List`1 lstwebinfoToUpgrade, List`1& lstwebinfoExceptions)
[ScriptEditor] [SPWebTemplateSequence] [DEBUG] [12/8/2011 7:04:24 PM]: Template MPS#0: Exception thrown while applying the global template to the web with URL "(unknown)" (Id: '8cc79a95-c567-4b8d-902e-ed944d64d84d') from site with URL "(unknown)" (Id: '3e800bc3-296f-47f0-a04d-b1e4ae385cb8'). Adding web to the exceptions list. Exception: System.IO.FileNotFoundException: The site with the id 3e800bc3-296f-47f0-a04d-b1e4ae385cb8 could not be found.
   at Microsoft.SharePoint.SPSite..ctor(Guid id, SPFarm farm, SPUrlZone zone, SPUserToken userToken)
   at Microsoft.SharePoint.SPSite..ctor(Guid id)
   at Microsoft.SharePoint.Upgrade.SPWebTemplateSequence.ApplyGlobalTemplateToWebs(List`1 lstwebinfoToUpgrade, List`1& lstwebinfoExceptions)
[ScriptEditor] [SPWebTemplateSequence] [DEBUG] [12/8/2011 7:04:24 PM]: Template MPS#0: Exception thrown while applying the global template to the web with URL "(unknown)" (Id: 'ec8f2991-c91a-41af-84be-fef8597035a2') from site with URL "(unknown)" (Id: '3e800bc3-296f-47f0-a04d-b1e4ae385cb8'). Adding web to the exceptions list. Exception: System.IO.FileNotFoundException: The site with the id 3e800bc3-296f-47f0-a04d-b1e4ae385cb8 could not be found.
   at Microsoft.SharePoint.SPSite..ctor(Guid id, SPFarm farm, SPUrlZone zone, SPUserToken userToken)
   at Microsoft.SharePoint.SPSite..ctor(Guid id)
   at Microsoft.SharePoint.Upgrade.SPWebTemplateSequence.ApplyGlobalTemplateToWebs(List`1 lstwebinfoToUpgrade, List`1& lstwebinfoExceptions)

Solution in my case:

There was an incorrect managed path in the web applications configured. The managed path was available, but set to “Wildcard inclusion” in the new farm (2010) instead of “Explicit inclusion” as in the old farm (2007).

I did remove the managed path and added it again with the correct setting. After that I had to re-attach the content database. The error was gone.

Exclude Asset Library from search results by modifying search scopes

It’s possible to exclude SharePoint Lists from search results by excluding their types in the search scope definition.

Therefore you need to define an search scope rule based on a “property”. You have to use “contentclass” and a value.

There are much lists of the possible values out in the web.

Here is mine 🙂

Value Description
STS_Web Site
STS_List Custom List
STS_ListItem Custom List item
STS_List_DocumentLibrary Document Library
STS_ListItem_DocumentLibrary Document Libary item
STS_List_Links Link List
STS_ListItem_Links Link List item
STS_List_Events Event List
STS_ListItem_Events Event List item
STS_List_Tasks Task List
STS_ListItem_Tasks Task List item
STS_List_Contacts Contact List
STS_ListItem_Contacts Contact List item
STS_List_Announcements Announcements List
STS_ListItem_Announcements Announcements List item
STS_List_DiscussionBoard Discussion Board
STS_ListItem_DiscussionBoard Discussion Board item
STS_List_GanttTasks Gantt Task List
STS_ListItem_GanttTasks Gantt Task item
STS_List_IssueTracking Issue Tracking list
STS_ListItem_IssueTracking Issue Tracking item
STS_List_Survey Survey
STS_ListItem_Survey Survey item
STS_List_PictureLibrary Picture Library
STS_ListItem_PictureLibrary Picture Library Item
STS_List_WebPageLibrary Web Page Library
STS_ListItem_WebPageLibrary Web Page Library Item
STS_List_XMLForm (InfoPath) Form Library
STS_ListItem_XMLForm (InfoPath) Form Library item
STS_List_850 Page Library
STS_ListItem_850 Page Library item
urn:content-class:SPSSearchQuery Search Query
urn:content-class:SPSListing:News News Listing
urn:content-class:SPSPeople People
urn:content-classes:SPSCategory Category
urn:content-classes:SPSListing Listing
urn:content-classes:SPSPersonListing Person Listing
urn:content-classes:SPSTextListing Text Listing
urn:content-classes:SPSSiteListing Site Listing
urn:content-classes:SPSSiteRegistry Site Registry Listing

 

You can generally exclude list items from search by using the value “STS_ListItem_PictureLibrary” for the property “contentclass”.

But how to exclude items or lists of type “Asset Library” which is also a standard list template like “Document Library”, “Picture Library”, “Calendar List”, … and “Page Library” which has as code (850) as name. (Marked red in the list above.)

I checked the 14 hive and figured out the 850 is the list template ID of “Page Library”. And the list template ID of “Asset Library” is 851.

So I used the following query in the search box: “(scope:"All Websites") (contentclass:STS_List_851)

I created a new search scope exclude rule on the site collection using “STS_List_851” in it worked! Now there are no more Asset Libary links in the search result. If you you “STS_ListItem_851” you can exclude Asset Library Litems.

(No screenshots today, sorry!)