Showing posts with label SiteDefinition. Show all posts
Showing posts with label SiteDefinition. Show all posts

Monday, June 11, 2012

Adding XsltListViewWebPart to sitedefinitions

If you want to add XsltListViewWebPart with custom xslt to site definition:
  1. Create a web part and do all configuration in existing site. Then export the web part this web part need some modifications to add to site definition.
  2. Exported Web Part contains ListGuid Which is difference from site to other. Remove ListGuid. Add one from these properties  ListName, ListUrl, or ListDisplayName
    One of the List* properties (ListName, ListUrl, or ListDisplayName) must be present and must specify a reference to a valid list. If more than one property is present, the order of evaluation is ListName, then ListUrl, and then ListDisplayName.
 

Friday, June 1, 2012

Cannot Convert Type Microsoft.SharePoint.WebControls.CSSRegistration to System.Web.UI.IAttributeAccessor – Beware of this in custom master page for custom publishing site definition

When you create site definition or custom master page as feature you may face error like:

Cannot Convert Type Microsoft.SharePoint.WebControls.CSSRegistration to System.Web.UI.IAttributeAccessor – Beware of this in custom master page for custom publishing site definition.
Reason:
When you export master page through SharePoint designer or WebDAV, It will add designer attributes (__designer) which will cause these problem.
<SharePoint:FieldValue FieldName="Title" runat="server" __designer:Preview="XXXXX" __designer:Values="XXXXX"/>

Also when open custom physical master page in SharePoint designer it adds __designer:Preview and __designer:Values attributes to my FieldValue and Literal controls, and if I don't remove them before check in ASP.NET complains.

 Also It may occur when you use html tags as below:

<a href="<%$SPUrl:~sitecollection/Pages/YourLink.aspx%>" >View All</a>

check url:
http://vyeung.wordpress.com/2011/06/01/sharepoint-designer-2010-addinggenerating-__designer-preview-tags-a-fix-to-solve-this-issue/


Solutions:
  1. Copy content instead of export from SPD.
  2. Double Check file and make sure you removed these attributes (__designer) 
  3. Look at the page directives in the top of the file, and ensure that a tilde and forward slash are present in the path(s):
    <%@ Register TagPrefix="wssuc" TagName="Welcome" src="~/_controltemplates/Welcome.ascx" %>

Use Content Query WebPart with site definition

When you want to create site using custom site definition and want to use Content Query WebPart, Export definition of your web part from existing site. You will find list is defined by Id called ListGuid. But the ListGuid is never the same when you create a new List. You need to do the the following steps before adding exported web part to your onet.xml:
  1. Remove ListGuid
    <Property name="ListGuid" type="string"></Property>
  2.  Add ListName and WebUrl (if they are not exist)
    <Property name=”ListName” type=”string”>Posts</Property>
    <Property name=”WebUrl” type=”string”>~site/</Property>
Note:
  1. ~site represent current site. you can use ~sitecollection to represent current site collection.
  2. ~site/ I added slash because if we are in root WebUrl will be blank and CQWP will not be rendered.

Tuesday, April 24, 2012

Content Editor web part in onet.xml

When tried to add a content editor web part to site definition. It works with me for simple content but when try to add tagged content like HTML it failed. After some Investigation I found solution by putting content into value tag <Value> instead of putting it direct into content property like this example:



<AllUsersWebPart WebPartZoneID="SurveyBtn" WebPartOrder="5">
        <![CDATA[
        <WebPart xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns="http://schemas.microsoft.com/WebPart/v2">
            <Title>Content Editor</Title>
            <FrameType>None</FrameType>
            <Description>Use for formatted text, tables, and images.</Description>
            <IsIncluded>true</IsIncluded>
            <ZoneID>WebPartZoneMiddleR</ZoneID>
            <PartOrder>5</PartOrder>
            <FrameState>Normal</FrameState>
            <Height />
            <Width />
            <AllowRemove>true</AllowRemove>
            <AllowZoneChange>true</AllowZoneChange>
            <AllowMinimize>true</AllowMinimize>
            <AllowConnect>true</AllowConnect>
            <AllowEdit>true</AllowEdit>
            <AllowHide>true</AllowHide>
            <IsVisible>true</IsVisible>
            <DetailLink />
            <HelpLink />
            <HelpMode>Modeless</HelpMode>
            <Dir>Default</Dir>
            <PartImageSmall />
            <MissingAssembly>Cannot import this Web Part.</MissingAssembly>
            <PartImageLarge>/_layouts/images/mscontl.gif</PartImageLarge>
            <IsIncludedFilter />
            <Assembly>Microsoft.SharePoint, Version=12.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c</Assembly>
            <TypeName>Microsoft.SharePoint.WebPartPages.ContentEditorWebPart</TypeName>
            <ContentLink xmlns="http://schemas.microsoft.com/WebPart/v2/ContentEditor" />
            <Content xmlns="http://schemas.microsoft.com/WebPart/v2/ContentEditor">
              <Value>
               &lt;div class=&quot;SurveyLocation&quot;&gt;&lt;a href=&quot;../Surveys&quot;&gt;&lt;img src=&quot;/_LAYOUTS/PMO.Departments/images/icn_survey.jpg&quot; alt=&quot;&quot;/&gt;&lt;/a&gt;&lt;/div&gt;
              </Value>
            </Content>
            <PartStorage xmlns="http://schemas.microsoft.com/WebPart/v2/ContentEditor" />
          </WebPart>
]]>
      </AllUsersWebPart>