Archive

Posts Tagged ‘List view in SharePoint 2013’

Exporting Web / App parts (Content Editor, App, and Visual Web Part).

August 21, 2013 3 comments

I would not be wrong if i call web part as vital part of SharePoint. Today we will be discussing to export and use the exported web parts in Visual Studio.

  • Web part.
  • Content Editor Web part.
  • App 2013 (List view web part).

So let’s get started, but before doing things we need to make sure following this are also properly settled.

  • Export Mode from ‘Edit Web part’ Options should have ‘Export all Data’. Through this we will be able to export the web part and that will be exported as .dwp  or .wp
  • If not set before then set ‘Export all data’ and apply/ok.

Web Part:

  • Select Edit Page option then select Edit Web part from the web part zone on which your required web part is placed.
  • Select ‘Export’ Option.
  • On selecting ‘Export’, dialogue to save the web part will open, save it to you required destination.


  • Open that file with Note Pad or Note Pad ++.
  • On opening you would have the following

    <webParts>

    <webPart xmlns=”http://schemas.microsoft.com/WebPart/v3″&gt;

    <metaData>

    <type name=”xxxxxxxxxxxxxxxxxxxxxxx, xxxxxxxxxxxxx, Version=1.0.0.0, Culture=neutral, PublicKeyToken=xxxxxxxxxxxxx” />

    <importErrorMessage>Cannot import this Web Part.</importErrorMessage>

    </metaData>

    <data>

    <properties>

    <property name=”numberOfItemsToDisplay” type=”int”>10</property>

    <property name=”ExportMode” type=”exportmode”>All</property>

    <property name=”HelpUrl” type=”string” />

    <property name=”Hidden” type=”bool”>False</property>

    <property name=”Description” type=”string”>My Visual Web Part</property>

    <property name=”CatalogIconImageUrl” type=”string” />

    <property name=”Title” type=”string”>Custom Webpart</property>

    <property name=”AllowHide” type=”bool”>True</property>

    <property name=”AllowMinimize” type=”bool”>True</property>

    <property name=”AllowZoneChange” type=”bool”>True</property>

    <property name=”TitleUrl” type=”string” />

    <property name=”ChromeType” type=”chrometype”>None</property>

    <property name=”AllowConnect” type=”bool”>True</property>

    <property name=”Width” type=”unit” />

    <property name=”Height” type=”unit” />

    <property name=”HelpMode” type=”helpmode”>Navigate</property>

    <property name=”AllowEdit” type=”bool”>True</property>

    <property name=”TitleIconImageUrl” type=”string” />

    <property name=”Direction” type=”direction”>NotSet</property>

    <property name=”SharePointWebURL” type=”string” null=”true” />

    <property name=”AllowClose” type=”bool”>True</property>

    <property name=”ChromeState” type=”chromestate”>Normal</property>

    </properties>

    </data>

    </webPart>

    </webParts>

  • Copy all from <webParts> … </webParts>, in nutshell copy all.
  • That is your required xml which is to be added in Visual studio under web part zone in

    <AllUsersWebPart
    WebPartZoneID=xc…
    WebPartOrder=1>

    <![CDATA[

    ‘Your Copied XML’
    ]]>

    </AllUsersWebPart>

    Content Editor:

Exporting web part is same for all, there are some tweaks to do in Content Editor Web part’s exported XML. So let’s jump to it. Content Editor Web part’s exported xml would look like the following

<?xml version=”1.0″ encoding=”utf-8″?>

<WebPart xmlns:xsd=”http://www.w3.org/2001/XMLSchema&#8221; xmlns:xsi=”http://www.w3.org/2001/XMLSchema-instance&#8221; xmlns=”http://schemas.microsoft.com/WebPart/v2″&gt;

<Title>Content Editor</Title>

<FrameType>None</FrameType>

<Description>Allows authors to enter rich text content.</Description>

<IsIncluded>true</IsIncluded>

<ZoneID>x917ee352abe847918eefcb35fd02bf0f</ZoneID>

<PartOrder>0</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/15/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&#8221; />


<Content xmlns=”http://schemas.microsoft.com/WebPart/v2/ContentEditor”&gt;<![CDATA[<div class=”block”>

<h3>Related Pages</h3>

<div class=”rlinks”>

<ul>

<li>

<a href=”/Pages/ABC.aspx”> ABC</a></li>

</ul>

</div>

</div>

<div class=”block”>

<h3>By Telephone </h3>

<div class=”rlinks”>

<ul>

<li>Tel : +92 336 335 334 6</li>

<li>Fax : +92 336 335 334 6</li>

</ul>

</div>

</div>

<div class=”block”>

<h3>

<a href=”#”>By Email </a></h3>

<div class=”rlinks”>

<ul>

<li>

<a href=”#”> ABC @ ABC.com</a></li>

</ul>

</div>

</div> ]]></Content>

<PartStorage xmlns=”http://schemas.microsoft.com/WebPart/v2/ContentEditor&#8221; />

</WebPart>

  • Everything added in content editor would come under <Content> tag.
  • You will notice there is already <![CDATA[ tag into it, Change this Tad to <Value> and its closing ]]> to </Value> too.
  • Moreover Copy all the text between <![CDATA[ and its closing ]]> highlighted.
  • Content editor web part needs encoded HTML so we need to encode it. This can be encoded from HTML Encode.
  • Paste all the encoded HTML between <Value> encoded HTML </Value>.
  • The final exported web part XML should look like

     

    <? xml version=”1.0″ encoding=”utf-8″?>

    <WebPart xmlns:xsd=”http://www.w3.org/2001/XMLSchema&#8221; xmlns:xsi=”http://www.w3.org/2001/XMLSchema-instance&#8221; xmlns=”http://schemas.microsoft.com/WebPart/v2″&gt;

    <Title>Content Editor</Title>

    <FrameType>None</FrameType>

    <Description>Allows authors to enter rich text content.</Description>

    <IsIncluded>true</IsIncluded>

    <ZoneID>x917ee352abe847918eefcb35fd02bf0f</ZoneID>

    <PartOrder>0</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/15/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&#8221; />


    <Content xmlns=”http://schemas.microsoft.com/WebPart/v2/ContentEditor”&gt;<Value>&lt;div class=&quot;block&quot;&gt;

    &lt;h3&gt;Related Pages&lt;/h3&gt;

    &lt;div class=&quot;rlinks&quot;&gt;

    &lt;ul&gt;

    &lt;li&gt;

    &lt;a href=&quot;/Pages/ABC.aspx&quot;&gt; ABC&lt;/a&gt;&lt;/li&gt;

    &lt;/ul&gt;

    &lt;/div&gt;

    &lt;/div&gt;

    &lt;div class=&quot;block&quot;&gt;

    &lt;h3&gt;By Telephone &lt;/h3&gt;

    &lt;div class=&quot;rlinks&quot;&gt;

    &lt;ul&gt;

    &lt;li&gt;Tel : +92 336 335 334 6&lt;/li&gt;

    &lt;li&gt;Fax : +92 336 335 334 6&lt;/li&gt;

    &lt;/ul&gt;

    &lt;/div&gt;

    &lt;/div&gt;

    &lt;div class=&quot;block&quot;&gt;

    &lt;h3&gt;

    &lt;a href=&quot;#&quot;&gt;By Email &lt;/a&gt;&lt;/h3&gt;

    &lt;div class=&quot;rlinks&quot;&gt;

    &lt;ul&gt;

    &lt;li&gt;

    &lt;a href=&quot;#&quot;&gt; ABC @ ABC.com&lt;/a&gt;&lt;/li&gt;

    &lt;/ul&gt;

    &lt;/div&gt;

    &lt;/div&gt;

    </Value></Content>

    <PartStorage xmlns=”http://schemas.microsoft.com/WebPart/v2/ContentEditor&#8221; />

    </WebPart>

  • Paste the tweaked web part XML

    <AllUsersWebPart
    WebPartZoneID=xc…
    WebPartOrder=1>

    <![CDATA[

    ‘Your tweaked XML’
    ]]>

    </AllUsersWebPart>

     

App / List View:    

In SharePoint 2013 you won’t find List view web part, as lists are given a new name and that is App. So how to add an app part and how to export it.

  • For that we will be using SharePoint
    Designer as there is no option to export App
    J.
  • Open SharePoint designer.
  • Navigate to your site on which you need to add a web part, moreover site should have that list too for which we are going to export the web part.
  • App an aspx page in that site from SharePoint designer.
  • Edit that added page in advance mode.
  • Add web part zone as shown below


 

  • Then into added web part zone.
    • Select Data View from the ribbon and select your list , Mine is LegalDocuments


 

  • After List been added to you zone. Click Web part from ribbon on top of the page and select ‘To File’.


  • You will be prompted to save the web part at your desired location and name.
  • Save it and open the saved file with Note Pad or Note Pad ++.
  • It will look like the following

    <?xml version=”1.0″ encoding=”utf-8″ ?>

    <webParts>

        <webPart xmlns=”http://schemas.microsoft.com/WebPart/v3″&gt;

            <metaData>

                <type name=”Microsoft.SharePoint.WebPartPages.XsltListViewWebPart, Microsoft.SharePoint, Version=15.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c” />

                <importErrorMessage>Cannot import this Web Part.</importErrorMessage>

            </metaData>

            <data>

                <properties>

                    …

                    <property name=”ListName” type=”string”>LegalDocuments<property>

                    <property name=”ListDisplayName” type=”string” null=”true” />

                    <property name=”AllowZoneChange” type=”bool”>True</property>

                    <property name=”ChromeState” type=”chromestate”>Normal</property>

                    <property name=”DisableSaveAsNewViewButton” type=”bool”>False</property>

                    <property name=”ViewFlag” type=”string” />

                    <property name=”DataSourceID” type=”string” />

                    <property name=”ExportMode”

                    <property name=”Title” type=”string” />

                    <property name=”PageType” type=”Microsoft.SharePoint.PAGETYPE, Microsoft.SharePoint, Version=15.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c”>PAGE_NORMALVIEW</property>

                    <property name=”DataSourcesString” type=”string” />

                    <property name=”AllowClose” type=”bool”>True</property>

                    <property name=”InplaceSearchEnabled” type=”bool”>True</property>

                    <property name=”WebId” type=”System.Guid, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089″>b369b8ef-fb3b-4a8e-ba1e-ae04fd57441c</property>

                    <property name=”Height” type=”string” />

                    <property name=”GhostedXslLink” type=”string”>main.xsl</property>

                    <property name=”DisableViewSelectorMenu” type=”bool”>False</property>

                    <property name=”DisplayName” type=”string”>LegalDocuments</property>

                    <property name=”IsClientRender” type=”bool”>False</property>

                    <property name=”XmlDefinition” type=”string”>

        &lt;View Name=”{807234E4-D763-435E-A84A-A5E20727A5FA}” MobileView=”TRUE” Type=”HTML” DisplayName=”All Documents” Url=”/LegalDocuments/Forms/AllItems.aspx” Level=”1″ BaseViewID=”1″ ContentTypeID=”0x” ImageUrl=”/_layouts/15/images/dlicon.png?rev=23″&gt;

            &lt;Query/&gt;

            &lt;ViewFields&gt;

                &lt;FieldRef Name=”DocIcon”/&gt;

                &lt;FieldRef Name=”LinkFilename”/&gt;

                &lt;FieldRef Name=”Modified”/&gt;

                &lt;FieldRef Name=”Editor”/&gt;

                &lt;FieldRef Name=”_ModerationStatus”/&gt;

            &lt;/ViewFields&gt;

            &lt;RowLimit Paged=”TRUE”&gt;30&lt;/RowLimit&gt;

            &lt;JSLink&gt;clienttemplates.js&lt;/JSLink&gt;

            &lt;XslLink Default=”TRUE”&gt;main.xsl&lt;/XslLink&gt;

            &lt;Toolbar Type=”Standard”/&gt;

        &lt;/View&gt;

    </property>…

        &lt;ParameterBinding Name=”NoAnnouncements” Location=”Resource(wss,noXinviewofY_LIST)” /&gt;

        &lt;ParameterBinding Name=”NoAnnouncementsHowTo” Location=”Resource(core,noXinviewofY_DEFAULT)” /&gt;

        &lt;ParameterBinding Name=”AddNewAnnouncement” Location=”Resource(wss,addnewitem)” /&gt;

        &lt;ParameterBinding Name=”MoreAnnouncements” Location=”Resource(wss,moreItemsParen)” /&gt;

    </property>

                    <property name=”DataSourceMode” type=”Microsoft.SharePoint.WebControls.SPDataSourceMode, Microsoft.SharePoint, Version=15.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c”>List</property>

                    <property name=”AutoRefreshInterval” type=”int”>60</property>

                    <property name=”AsyncRefresh” type=”bool”>False</property>

                    <property name=”HelpUrl” type=”string” />

                    <property name=”MissingAssembly” type=”string”>Cannot import this Web Part.</property>

                    <property name=”XslLink” type=”string” null=”true” />

                    <property name=”SelectParameters” type=”string” />

                </properties>

            </data>

        </webPart>

    </webParts>

  • Important things to tweak in App / List view are highlighted.
  • Make sure List name is proper.
  • Make sure URL of view is proper.
  • Final thing to do is , This will be added under <View ….</View>
    instead of <AllUsersWebPart … so delete AllUsersWebPart

    Tag and place View tag.

     

    <View
    List=LegalDocuments
    BaseViewID=1
    WebPartZoneID=xb…………
    WebPartOrder=1 >

    <![CDATA[

    ‘Copy Tweaked XML here’
    ]]>

    </View>

    Happy CodingJ.