Wednesday, April 23, 2014

BaseViewID in Sharepoint List View Element

Hey,

I have created a SharePoint List named "Tasks" using CAML approach - For the same I had created a dummy Tasks List and took the Schema of the list using SharePoint Manager tools.

Note that within my dummy Tasks List, I had created 2 customs views however when I looked carefully at the Schema the BaseViewID was always 1 tho it was a custom view.

I deployed my List and I wanted to show the View on my Default page using ListViewWebPart but when I was mapping my BaseViewID it was not showing the right View.

It took me hours to figure out that SharePoint was referring to the Tasks Schema within the below path - why ? may be because my list name was Tasks... My customer wanted to use the same name and I had to find out some solutions...
C:\Program Files\Common Files\Microsoft Shared\Web Server Extensions\14\TEMPLATE\FEATURES\TasksList\Tasks
On my custom view I gave a different unique ID mentioned by Brian Bedard but it didn't work...

Finally, I decided to re-create the List Instance with the same name "Tasks" but this time using the assistant of Visual Studio which provide a nice interface to create Views and there it worked - It created the custom views with different BaseViewID.

Here is the Elements.xml of the Page (Module) if it can help anyone

<?xml version="1.0" encoding="utf-8"?>
<Elements xmlns="http://schemas.microsoft.com/sharepoint/">
  <Module Name="PageModule" Url="$Resources:cmscore,List_Pages_UrlName;">
    <File Url="defaultLeaf.aspx" Type="GhostableInLibrary" Path="PageModule\defaultLeaf.aspx" IgnoreIfAlreadyExists="TRUE" >
      <Property Name="Title" Value="Home" />
      <Property Name="IncludeInGlobalNavigation" Value="FALSE" />
      <Property Name="ContentType" Value="Welcome Page" />
      <Property Name="PublishingPageLayout" Value="~SiteCollection/_catalogs/masterpage/Leaf.Layout.aspx, Leaf Web Part Page" />
      <AllUsersWebPart WebPartZoneID="Header" WebPartOrder="0">
        <![CDATA[
           <?xml version="1.0" encoding="utf-8"?>
            <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>Welcome</Title>
              <FrameType>None</FrameType>
              <Description>Welcome</Description>
              <IsIncluded>true</IsIncluded>
              <ZoneID>Left</ZoneID>
              <PartOrder>1</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>An error has occured - Please contact your system administrator.</MissingAssembly>
              <PartImageLarge>/_layouts/images/mscontl.gif</PartImageLarge>
              <IsIncludedFilter />
              <Assembly>Microsoft.SharePoint, Version=15.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">
                <h2>Welcome to your Site Template</h2>
              </Content>
              <PartStorage xmlns="http://schemas.microsoft.com/WebPart/v2/ContentEditor" />
              </WebPart>
              ]]>
      </AllUsersWebPart>
      <View List="Lists/News" DisplayName="" Url="" DefaultView="FALSE" BaseViewID="0" Type="HTML" WebPartOrder="1" WebPartZoneID="Header" ContentTypeID="0x">
        <![CDATA[<webParts>
  <webPart xmlns="http://schemas.microsoft.com/WebPart/v3">
    <metaData>
      <type name="Microsoft.SharePoint.WebPartPages.XsltListViewWebPart, Microsoft.SharePoint, Version=14.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c" />
      <importErrorMessage>Cannot import this Web Part.</importErrorMessage>
    </metaData>
    <data>
      <properties>
        <property name="InitialAsyncDataFetch" type="bool">False</property>
        <property name="ChromeType" type="chrometype">Default</property>
        <property name="Title" type="string" />
        <property name="Height" type="string" />
        <property name="CacheXslStorage" type="bool">True</property>
        <property name="ListDisplayName" type="string" null="true" />
        <property name="AllowZoneChange" type="bool">True</property>
        <property name="AllowEdit" type="bool">True</property>
        <property name="XmlDefinitionLink" type="string" />
        <property name="DataFields" type="string" />
        <property name="Hidden" type="bool">False</property>
        <property name="ListName" type="string">{$ListId:Lists/Announcements;}</property>
        <property name="NoDefaultStyle" type="string" />
        <property name="AutoRefresh" type="bool">False</property>
        <property name="ViewFlag" type="string">8388621</property>
        <property name="Direction" type="direction">NotSet</property>
        <property name="AutoRefreshInterval" type="int">60</property>
        <property name="AllowConnect" type="bool">True</property>
        <property name="Description" type="string" />
        <property name="AllowClose" type="bool">True</property>
        <property name="ShowWithSampleData" type="bool">False</property>
        <property name="ParameterBindings" type="string">  &lt;ParameterBinding Name="dvt_sortdir" Location="Postback;Connection"/&gt;
            &lt;ParameterBinding Name="dvt_sortfield" Location="Postback;Connection"/&gt;
            &lt;ParameterBinding Name="dvt_startposition" Location="Postback" DefaultValue=""/&gt;
            &lt;ParameterBinding Name="dvt_firstrow" Location="Postback;Connection"/&gt;
            &lt;ParameterBinding Name="OpenMenuKeyAccessible" Location="Resource(wss,OpenMenuKeyAccessible)" /&gt;
       &lt;ParameterBinding Name="open_menu" Location="Resource(wss,open_menu)" /&gt;
            &lt;ParameterBinding Name="select_deselect_all" Location="Resource(wss,select_deselect_all)" /&gt;
            &lt;ParameterBinding Name="idPresEnabled" Location="Resource(wss,idPresEnabled)" /&gt;&lt;ParameterBinding Name="NoAnnouncements" Location="Resource(wss,NoAnnouncements)" /&gt;&lt;ParameterBinding Name="NoAnnouncementsHowTo" Location="Resource(wss,NoAnnouncementsHowTo)" /&gt;&lt;ParameterBinding Name="AddNewAnnouncement" Location="Resource(wss,idHomePageNewAnnounce)" /&gt;&lt;ParameterBinding Name="MoreAnnouncements" Location="Resource(wss,MoreAnnouncements)" /&gt;&lt;ParameterBinding Name="ByText" Location="Resource(wss,2000)" /&gt;</property>
        <property name="Xsl" type="string" null="true" />
        <property name="CacheXslTimeOut" type="int">86400</property>
        <property name="WebId" type="System.Guid, mscorlib, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">00000000-0000-0000-0000-000000000000</property>
        <property name="ListUrl" type="string" null="true" />
        <property name="DataSourceID" type="string" />
        <property name="FireInitialRow" type="bool">True</property>
        <property name="ManualRefresh" type="bool">False</property>
        <property name="ViewFlags" type="Microsoft.SharePoint.SPViewFlags, Microsoft.SharePoint, Version=14.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c">Html, TabularView, Hidden, Mobile</property>
        <property name="ChromeState" type="chromestate">Normal</property>
        <property name="AllowHide" type="bool">True</property>
        <property name="PageSize" type="int">-1</property>
        <property name="SampleData" type="string" null="true" />
        <property name="BaseXsltHashKey" type="string" null="true" />
        <property name="AsyncRefresh" type="bool">False</property>
        <property name="HelpMode" type="helpmode">Modeless</property>
        <property name="ListId" type="System.Guid, mscorlib, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">$ListId:Lists/Announcements;</property>
        <property name="DataSourceMode" type="Microsoft.SharePoint.WebControls.SPDataSourceMode, Microsoft.SharePoint, Version=14.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c">List</property>
        <property name="AllowMinimize" type="bool">True</property>
        <property name="TitleUrl" type="string">/sites/TeamSite/Lists/Announcements</property>
        <property name="CatalogIconImageUrl" type="string" />
        <property name="DataSourcesString" type="string" />
        <property name="GhostedXslLink" type="string">main.xsl</property>
        <property name="PageType" type="Microsoft.SharePoint.PAGETYPE, Microsoft.SharePoint, Version=14.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c">PAGE_NORMALVIEW</property>
        <property name="DisplayName" type="string" />
        <property name="UseSQLDataSourcePaging" type="bool">True</property>
        <property name="Width" type="string" />
        <property name="ExportMode" type="exportmode">All</property>
        <property name="XslLink" type="string" null="true" />
        <property name="ViewContentTypeId" type="string" />
        <property name="HelpUrl" type="string" />
        <property name="XmlDefinition" type="string">&lt;View Name="{A7CDF12B-A952-4931-8E82-3A7B3170D5ED}" MobileView="TRUE" Type="HTML" Hidden="TRUE" DisplayName="" Url="/sites/TeamSite/default.aspx" Level="1" BaseViewID="0" ContentTypeID="0x"&gt;&lt;Query&gt;&lt;Where&gt;&lt;Or&gt;&lt;IsNull&gt;&lt;FieldRef Name="Expires"/&gt;&lt;/IsNull&gt;&lt;Geq&gt;&lt;FieldRef Name="Expires"/&gt;&lt;Value Type="DateTime"&gt;&lt;Today/&gt;&lt;/Value&gt;&lt;/Geq&gt;&lt;/Or&gt;&lt;/Where&gt;&lt;OrderBy&gt;&lt;FieldRef Name="Modified" Ascending="FALSE"/&gt;&lt;/OrderBy&gt;&lt;/Query&gt;&lt;ViewFields&gt;&lt;FieldRef Name="LinkTitleNoMenu" Explicit="TRUE"/&gt;&lt;FieldRef Name="Body" Explicit="TRUE"/&gt;&lt;FieldRef Name="Author" Explicit="TRUE"/&gt;&lt;FieldRef Name="Modified" Explicit="TRUE"/&gt;&lt;FieldRef Name="Attachments" Explicit="TRUE"/&gt;&lt;/ViewFields&gt;&lt;RowLimit&gt;5&lt;/RowLimit&gt;&lt;Toolbar Type="Freeform"/&gt;&lt;/View&gt;</property>
        <property name="Default" type="string" />
        <property name="TitleIconImageUrl" type="string" />
        <property name="MissingAssembly" type="string">Cannot import this Web Part.</property>
        <property name="SelectParameters" type="string" />
      </properties>
    </data>
  </webPart>
</webParts>]]>
      </View>
      <View List="Lists/Tasks" DisplayName="My Active Task" Name="My Active Task"  WebPartZoneID="Header"  BaseViewID="9" Type="HTML" WebPartOrder="2">
        <![CDATA[
             <WebPart xmlns="http://schemas.microsoft.com/WebPart/v2">
                  <Assembly>Microsoft.SharePoint, Version=12.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c</Assembly>
                  <TypeName>Microsoft.SharePoint.WebPartPages.ListViewWebPart</TypeName>
                  <Title>My Active Task</Title>
             </WebPart>
      ]]>
      </View>
     
     
      <AllUsersWebPart WebPartZoneID="Right" WebPartOrder="1">
        <![CDATA[
        <WebPart xmlns="http://schemas.microsoft.com/WebPart/v2">
          <Assembly>Microsoft.SharePoint, Version=11.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c</Assembly>
          <TypeName>Microsoft.SharePoint.WebPartPages.MembersWebPart</TypeName>
          <Title>Site Manager</Title>
          <Description>Use the Members Web Part to see a list of the site members and their online status.</Description>
          <FrameType>Standard</FrameType>
          <IsVisible>true</IsVisible>
        </WebPart>
      ]]>
      </AllUsersWebPart>
      <AllUsersWebPart WebPartZoneID="Right" WebPartOrder="2">
        <![CDATA[
        <WebPart xmlns="http://schemas.microsoft.com/WebPart/v2">
          <Assembly>Microsoft.SharePoint, Version=11.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c</Assembly>
          <TypeName>Microsoft.SharePoint.WebPartPages.MembersWebPart</TypeName>
          <Title>Site Members</Title>
          <Description>Use the Members Web Part to see a list of the site members and their online status.</Description>
          <FrameType>Standard</FrameType>
          <IsVisible>true</IsVisible>
        </WebPart>
      ]]>
      </AllUsersWebPart>
    </File>
  </Module>
</Elements>
    

Deploy Metadata Navigation through CAML - NO CODE Approach

Hey,

The requirements was to create a new List Instance using CAML approach with some Metadata Navigation Settings pre-configured into it as in my list I have used a Managed Metadata Field.

This turned out to be harder than I thought !!!

After Googling I came to the post by Corey Roth which help understand the concept of MetadataNavigationSettings used as a CAML.

Now, where to find the Value of  client_MOSS_MetadataNavigationSettings  Property, I tried to rebuild the CAML manually using the common sense and doing some trial and error with the MetadataField FieldID GUID however it wasn't working...

Thereafter, I decided to get the value programmatically - for that I created a dummy Document Library and I got the XML Value of the client_MOSS_MetadataNavigationSettings using the below code and VOILA - I got the value.
SPDocumentLibrary lib = (SPDocumentLibrary)site.OpenWeb().Lists["SharedDocuments"];var res = lib.RootFolder.Properties["client_MOSS_MetadataNavigationSettings"];
Once I got the value, I converted the XML tag into HTML - These 3 symbols only:
" by &quot;
< by &lt;
> by &gt;
Finally, my Elements.xml looks like:
<?xml version="1.0" encoding="utf-8"?>
<Elements xmlns="http://schemas.microsoft.com/sharepoint/">
  <ListInstance FeatureId="{00bfea71-e717-4e80-aa17-d0c71b360101}" TemplateType="101" Title="MyDocuments" Description="" Url="MyDocuments" CustomSchema="Files\MyDocuments\Schema.xml" HyperlinkBaseUrl="http://zin506/sites/TeamSite" RootWebOnly="FALSE" xmlns="http://schemas.microsoft.com/sharepoint/"  OnQuickLaunch="TRUE" />
  <PropertyBag Url="MyDocuments" ParentType="Folder" RootWebOnly="FALSE" xmlns="http://schemas.microsoft.com/sharepoint/">
    <Property Name="client_MOSS_MetadataNavigationSettings" Type="string"
              Value="&lt;MetadataNavigationSettings SchemaVersion=&quot;1&quot; IsEnabled=&quot;True&quot; AutoIndex=&quot;True&quot;&gt;
  &lt;NavigationHierarchies&gt;
    &lt;FolderHierarchy HideFoldersNode=&quot;True&quot; /&gt;
    &lt;MetadataField FieldID=&quot;7ced7787-dcf6-4748-a23e-f0248f89db58&quot;
                   FieldType=&quot;TaxonomyFieldType&quot;
                   CachedName=&quot;Category&quot;
                   CachedDisplayName=&quot;Category&quot; /&gt;
  &lt;/NavigationHierarchies&gt;
  &lt;KeyFilters /&gt;
&lt;/MetadataNavigationSettings&gt;" />
  </PropertyBag>
</Elements>

Enjoy! 

Tuesday, April 22, 2014

Provisioning Managed Metadata (Taxonomy) Fields through CAML in SharePoint 2010

Hey guys,

The requirement was to provision a List trough CAML with some metadata columns associated to a specific Managed Metadata Service.

Things was the customer wanted to use the features as a template so NO CODE approach has been decided.

This tasks give me a tough time as there was no help available in the net as in all the blogs written for creating a Managed Metadata field were associating the fields using a Feature Receiver - that means using code.

What I did is that within a Team Site, I created a dummy list where I created the required fields and associate them to the specific Managed Metadata Service.

Once done, I saved the Site as a Template and downloaded the Wsp solution from the Solution Gallery.

Now using Visual Studio 2012 (thanks to VS2012), while creating a project it gives an option to create a solution from a Wsp Solution so here we go !!!

There after the project loaded successfully, I looked into the dummy list and copied the schema associated into it and pasted into my custom list schema and VOILA ! The list was provisioned with the managed metadata field associated to the MMS.

note that in case if you don't have Visual Studio 2012, you can still rename the wsp solution into a .CAB file and look for the schema of the dummy list but without intellisense...