Monthly Archives: January 2012

BTW: A little trick for development in Visual Studio 2010 – Start PowerShell scripts that need to run in an x64 context by double click from Solution Explorer

For development and some related tasks I use PowerShell, of course. – I store the PowerShell scripts in my projects as part of them. They are part of the source code and they are saved in the source control.

If I need to run such a script I start it directly from Solution Explorer in VS2010.

Therefore I’ve set the default “open with…” to “powershell.exe”

image

image

image

If you have done this you can run every “.ps1” script file by double click in Solution Explorer!!

BUT… VS2010 itself is 32bit! – If you start an architecture independend process like “poweshell.exe” from within VS2010 it runs in 32bit environment! But sometimes you need to run a 64 version of PowerShell, e.g. for some SharePoint tasks that need an 64 bit environment.

Therefore I’ve created a little App “StartPS64”:

1. In VS2010 create a new Project of type “Console Application”

2. Open the project’s properties, select the “Build” tab and change “Platform target” to x64.

SNAGHTML57d9e4d

3. Edit “program.cs” and insert this code:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Diagnostics;

namespace StartPS64
{
    class Program
    {
        static void Main(string[] args)
        {
            string fullname = System.IO.Path.GetFullPath(args[0]);
            if( !System.IO.File.Exists(fullname) )
            {
                Console.WriteLine("Script does not exist!");
                Console.ReadKey();
                return;
            }

            Process.Start(@"c:windowssystem32windowspowershellv1.0powershell.exe", fullname);
        }
    }
}

4. Compile it.

5. Specify the build “startps64.exe” as new “default application” for “.ps1” files in VS2010 as described above.

6. Now every “.ps1” file started from the Solution Explorer will run in an 64 bit environment and can execute SharePoint cmdlets!

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.