1

We have created a SharePoint solution with custom site definition and a simple visual Webpart using Visual Studio 2012.

The purpose of the solution would be to add the custom visual webpart to the default page of the custom site definition via ONET.xml file. Following the code snippets.

Default.aspx

<%@ Page Language="C#" MasterPageFile="~masterurl/default.master" Inherits="Microsoft.SharePoint.WebPartPages.WebPartPage,Microsoft.SharePoint,Version=14.0.0.0,Culture=neutral,PublicKeyToken=71e9bce111e9429c" %>
<%@ 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" %>
<%@ Register TagPrefix="WebPartPages" Namespace="Microsoft.SharePoint.WebPartPages" Assembly="Microsoft.SharePoint, Version=14.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c" %>
<%@ Import Namespace="Microsoft.SharePoint" %>
<%@ Import Namespace="Microsoft.SharePoint.ApplicationPages" %>
<%@ Assembly Name="Microsoft.Web.CommandUI, Version=14.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c" %>

<asp:Content ContentPlaceHolderID="PlaceHolderPageTitle" runat="server">
    <SharePoint:ProjectProperty Property="Title" runat="server" />
</asp:Content>

<asp:Content ID="Content1" ContentPlaceHolderID="PlaceHolderMain" runat="server">
    <div style="width: 100%; text-align: center;">
        <h1>Welcome to Custom Site Definition Site</h1>
        <WebPartPages:WebPartZone ID="Main" runat="server" Title="loc:Main" FrameType="None">
        </WebPartPages:WebPartZone>
    </div>
</asp:Content>

LogonInfoWebPart.ascx

<%@ Assembly Name="$SharePoint.Project.AssemblyFullName$" %>
<%@ Assembly Name="Microsoft.Web.CommandUI, Version=14.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c" %>
<%@ 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" %>
<%@ Register TagPrefix="WebPartPages" Namespace="Microsoft.SharePoint.WebPartPages" Assembly="Microsoft.SharePoint, Version=14.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c" %>
<%@ Control Language="C#" AutoEventWireup="true" CodeBehind="LogonInfoWebPart.ascx.cs" Inherits="CustomSiteDefinition.LogonInfoWebPart.LogonInfoWebPart" %>
<table border="0" style="width:100%;">
    <tr>
        <td>
            Welcome, <span runat="server" id="LogonName"></span>
        </td>
    </tr>
</table>

LogonInfoWebPart.ascx.cs

using Microsoft.SharePoint;
using System;
using System.ComponentModel;
using System.Web.UI.WebControls.WebParts;

namespace CustomSiteDefinition.LogonInfoWebPart
{
    [ToolboxItemAttribute(false)]
    public partial class LogonInfoWebPart : Microsoft.SharePoint.WebPartPages.WebPart
    {
        protected override void OnInit(EventArgs e)
        {
            base.OnInit(e);
            InitializeControl();
        }

        protected void Page_Load(object sender, EventArgs e)
        {
            string username = SPContext.Current.Web.CurrentUser.LoginName;
            if (!String.IsNullOrEmpty(username))
            {
                LogonName.InnerText = username;
            }
        }
    }
}

ONET.xml

<?xml version="1.0" encoding="utf-8"?>
<Project Title="CustomSiteDefinition" Revision="2" ListDir="" xmlns:ows="Microsoft SharePoint" xmlns="http://schemas.microsoft.com/sharepoint/">
  <NavBars>
  </NavBars>
  <Configurations>
    <Configuration ID="0" Name="CustomSiteDefinition">
      <Lists/>
      <SiteFeatures>
      </SiteFeatures>
      <WebFeatures>
      </WebFeatures>
      <Modules>
        <Module Name="DefaultBlank" />
      </Modules>
    </Configuration>
  </Configurations>
  <Modules>
    <Module Name="DefaultBlank">
      <File Url="default.aspx" Name="default.aspx" Type="Ghostable">
        <AllUsersWebPart WebPartZoneID="Main" WebPartOrder="0">
          <![CDATA[
        <?xml version="1.0" encoding="utf-8"?>
        <webParts>
        <webPart xmlns="http://schemas.microsoft.com/WebPart/v3">
          <metaData>
            <type name="CustomSiteDefinition.LogonInfoWebPart.LogonInfoWebPart, $SharePoint.Project.AssemblyFullName$" />
            <importErrorMessage>Cannot import the webpart</importErrorMessage>
          </metaData>
          <data>
            <properties>
              <property name="Title" type="string">Custom - Log info webpart</property>
              <property name="Description" type="string">Webpart would show current logged in user</property>
              <property name="ChromeType" type="chrometype">None</property>
            </properties>
          </data>
         </webPart>
        </webParts>
      ]]>
        </AllUsersWebPart>
      </File>
    </Module>
  </Modules>
</Project>

I am getting the following error while loading the default page after deployment

<table xmlns=''> was not expected.  Description: An unhandled exception occurred during the execution of the current web request. 
Please review the stack trace for more information about the error and where it originated in the code. 

Exception Details: System.InvalidOperationException: <table xmlns=''> was not expected.

Any help is much appreciated :)

Update - Issue Resolved

After so much of glitch, finally decided to delete the custom visual webpart from the solution. Recreated it and fortunately it started working with out any issues. Still not sure about the root cause :S

1

Please try to delete this line:

<?xml version="1.0" encoding="utf-8"?>

after <![CDATA[

  • Sorry, it didn't work :( – suryakiran Dec 2 '13 at 7:50
  • I think the issue is with the web part. Have removed the webpart and recreated(without any code changes) and shockingly it is working fine – suryakiran Dec 2 '13 at 10:08

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.