我有 Visual Studio 2010 和 SharePoint 2010。我使用 MyFirstPage.aspx 页创建了我的第一个项目。当我部署这个项目时,我有下一个错误:
项目项“布局”中文件“MyFirstPage.aspx”的部署类型“模板文件”与沙盒解决方案中的包不兼容
那么,这是如何解决的呢?
MyFirstPage.aspx 有下一个代码:
<%@ Assembly Name="$SharePoint.Project.AssemblyFullName$" %>
<%@ Import Namespace="Microsoft.SharePoint.ApplicationPages" %>
<%@ Register Tagprefix="SharePoint" Namespace="Microsoft.SharePoint.WebControls" Assembly="Microsoft.SharePoint, Version=14.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c" %>
<%@ Register Tagprefix="Utilities" Namespace="Microsoft.SharePoint.Utilities" Assembly="Microsoft.SharePoint, Version=14.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c" %>
<%@ Register Tagprefix="asp" Namespace="System.Web.UI" Assembly="System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" %>
<%@ Import Namespace="Microsoft.SharePoint" %>
<%@ Assembly Name="Microsoft.Web.CommandUI, Version=14.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c" %>
<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="MyFirstPage.aspx.cs" Inherits="SharePointProject1.Layouts.SharePointProject1.MyFirstPage" DynamicMasterPageFile="~masterurl/default.master" %>
<asp:Content ID="PageHead" ContentPlaceHolderID="PlaceHolderAdditionalPageHead" runat="server">
</asp:Content>
<asp:Content ID="Main" ContentPlaceHolderID="PlaceHolderMain" runat="server">
<h2>My Farm</h2>
<asp:TreeView ID="farmHierarchyViewer" runat="server"
ShowLines="true" EnableViewState="true">
</asp:TreeView>
</asp:Content>
<asp:Content ID="PageTitle" ContentPlaceHolderID="PlaceHolderPageTitle" runat="server">
Farm Hierarchy and Properties
</asp:Content>
<asp:Content ID="PageTitleInTitleArea" ContentPlaceHolderID="PlaceHolderPageTitleInTitleArea" runat="server" >
My Farm Hierarchy
</asp:Content>
MyFirstPage.aspx.cs:
using System;
using Microsoft.SharePoint;
using Microsoft.SharePoint.WebControls;
using System.Web.UI.WebControls;
using Microsoft.SharePoint.Administration;
namespace SharePointProject1.Layouts.SharePointProject1
{
public partial class MyFirstPage : LayoutsPageBase
{
protected void Page_Load(object sender, EventArgs e)
{
SPFarm thisFarm = SPFarm.Local;
TreeNode node;
farmHierarchyViewer.Nodes.Clear();
foreach (SPService svc in thisFarm.Services)
{
node = new TreeNode();
node.Text = "Farm Service (Type=" + svc.TypeName + "; Status="
+ svc.Status + ")";
farmHierarchyViewer.Nodes.Add(node);
TreeNode svcNode = node;
if (svc is SPWebService)
{
SPWebService webSvc = (SPWebService)svc;
foreach (SPWebApplication webApp in webSvc.WebApplications)
{
node = new TreeNode();
node.Text = webApp.DisplayName;
svcNode.ChildNodes.Add(node);
TreeNode webAppNode = node;
if (!webApp.IsAdministrationWebApplication)
{
foreach (SPSite site in webApp.Sites)
{
site.CatchAccessDeniedException = false;
try
{
node = new TreeNode();
node.Text = site.Url;
webAppNode.ChildNodes.Add(node);
TreeNode siteNode = node;
node = new TreeNode(site.RootWeb.Title, null, null,
site.RootWeb.Url +
"/_layouts/lab01/PropertyChanger.aspx?type=web&objectID="
+ site.RootWeb.ID, "_self");
siteNode.ChildNodes.Add(node);
TreeNode parentNode = node;
foreach (SPList list in site.RootWeb.Lists)
{
node = new TreeNode(list.Title, null, null,
site.RootWeb.Url +
"/_layouts/lab01/PropertyChanger.aspx?type=list&objectID="
+ list.ID, "_self");
parentNode.ChildNodes.Add(node);
}
foreach (SPWeb childWeb in site.RootWeb.Webs)
{
try
{
addWebs(childWeb, parentNode);
}
finally
{
childWeb.Dispose();
}
}
site.CatchAccessDeniedException = false;
}
finally
{
site.Dispose();
}
}
}
}
}
}
farmHierarchyViewer.ExpandAll();
}
void addWebs(SPWeb web, TreeNode parentNode)
{
TreeNode node;
node = new TreeNode(web.Title, null, null, web.Url
+ "/_layouts/lab01/PropertyChanger.aspx?type=web&objectID="
+ web.ID, "_self");
parentNode.ChildNodes.Add(node);
parentNode = node;
foreach (SPList list in web.Lists)
{
node = new TreeNode(list.Title, null, null, web.Url
+ "/_layouts/lab01/PropertyChanger.aspx?type=list&objectID="
+ list.ID, "_self");
parentNode.ChildNodes.Add(node);
}
foreach (SPWeb childWeb in web.Webs)
{
try
{
addWebs(childWeb, parentNode);
}
finally
{
childWeb.Dispose();
}
}
}
}
}