Friday, July 15, 2016

Add XsltListViewWebPart Programatically - ShrePoint 2013 Webpart.


XsltListViewWebPart  with ViewFields




Aspx:
   
<WebPartPages:XsltListViewWebPart ID="XsltListViewWebPart2" runat="server"  IsIncluded="True" GhostedXslLink="main.xsl" FrameType="None" NoDefaultStyle="TRUE" ViewFlag="8" Title="" PageType="PAGE_NORMALVIEW"  Default="FALSE"  viewcontenttypeid="0x"  __AllowXSLTEditing="true" WebPart="true" Height="" Width="">
   <XmlDefinition>
              <View Name="{B833EECF-2D73-4CB5-BC35-5415558F0E64}" MobileView="TRUE" Type="HTML" DisplayName="All Documents"  Level="1" BaseViewID="1" ContentTypeID="0x" ImageUrl="/_layouts/15/images/dlicon.png?rev=23">
                     <Query/>
                     <ViewFields>
                           <FieldRef Name="DocIcon"/>
                           <FieldRef Name="LinkFilename"/>
                           <FieldRef Name="Editor"/>
                <FieldRef Name="FileSizeDisplay"/>                                             
                     </ViewFields>
                     <RowLimit Paged="TRUE">9</RowLimit>
                     <Aggregations Value="Off"/>
                     <JSLink>clienttemplates.js</JSLink>
                     <XslLink Default="TRUE">main.xsl</XslLink>
                     <Toolbar Type="Standard"/>
              </View>
       </XmlDefinition>
<parameterbindings>
              <ParameterBinding Name="dvt_sortdir" Location="Postback;Connection"/>
              <ParameterBinding Name="dvt_sortfield" Location="Postback;Connection"/>
              <ParameterBinding Name="dvt_startposition" Location="Postback" DefaultValue=""/>
              <ParameterBinding Name="dvt_firstrow" Location="Postback;Connection"/>
              <ParameterBinding Name="OpenMenuKeyAccessible" Location="Resource(wss,OpenMenuKeyAccessible)" />
              <ParameterBinding Name="open_menu" Location="Resource(wss,open_menu)" />
              <ParameterBinding Name="select_deselect_all" Location="Resource(wss,select_deselect_all)" />
              <ParameterBinding Name="idPresEnabled" Location="Resource(wss,idPresEnabled)" />
              <ParameterBinding Name="NoAnnouncements" Location="Resource(wss,noXinviewofY_LIST)" />
              <ParameterBinding Name="NoAnnouncementsHowTo" Location="Resource(core,noXinviewofY_DEFAULT)" />
              <ParameterBinding Name="AddNewAnnouncement" Location="Resource(wss,addnewitem)" />
              <ParameterBinding Name="MoreAnnouncements" Location="Resource(wss,moreItemsParen)" />
       </parameterbindings>
</WebPartPages:XsltListViewWebPart>

Code Behind:
XsltListViewWebPart2.ListId = Splist.ID;










XsltListViewWebPart  with add Document URL





Aspx:
<div id="dvShowWebpart" runat="server"></div>
Code Behind:

  XsltListViewWebPart2.ListId = list.ID; // list===>SPList                      
                        SPView listDefalutView = list.DefaultView;
                        listDefalutView.RowLimit = 10;

                        XsltListViewWebPart XsltListViewWebPart1 = new XsltListViewWebPart();
                        XsltListViewWebPart1.ID = "RKUListView";
                        XsltListViewWebPart1.Title = list.Title;
                        XsltListViewWebPart1.ChromeType = PartChromeType.TitleAndBorder;
                        XsltListViewWebPart1.AllowEdit = true;
                        XsltListViewWebPart1.AllowConnect = true;
                        XsltListViewWebPart1.ListName = list.ID.ToString("B").ToUpper();
                        XsltListViewWebPart1.ViewGuid = listDefalutView.ID.ToString("B").ToUpper();

                        PropertyInfo nodeProp = listDefalutView.GetType().GetProperty("Node", BindingFlags.NonPublic | BindingFlags.Instance);
                        XmlNode node = nodeProp.GetValue(listDefalutView, null) as XmlNode;
                        XmlNode toolbarNode = node.SelectSingleNode("Toolbar");


                        if (toolbarNode != null)
                        {
                            if (!toolbarNode.Attributes["Type"].Value.Equals("Freeform"))
                            {
                                toolbarNode.Attributes["Type"].Value = "Freeform";
                            }
                        }
                        listDefalutView.Update();
                        dvShowWebpart.Controls.Add(XsltListViewWebPart1);
                        web.AllowUnsafeUpdates = false;
                    



=======================================

SharePoint Page:

<WebPartPages:XsltListViewWebPart runat="server" IsIncluded="True" GhostedXslLink="main.xsl" FrameType="None" NoDefaultStyle="TRUE" ViewFlag="8" Title="Demo" PageType="PAGE_NORMALVIEW" ListName="{48435060-BE29-4493-941D-DB83412A03E7}" Default="FALSE" DisplayName="Demo" __markuptype="vsattributemarkup" __WebPartId="{05E9C5F8-C1EA-4FCA-8CD7-DD73F577B3C0}" id="g_05e9c5f8_c1ea_4fca_8cd7_dd73f577b3c0" viewcontenttypeid="0x" __designer:customxsl="fldtypes_Ratings.xsl">
<XmlDefinition>
       <View Name="{1B56C7C6-3EDC-4AB1-8609-D020CF7B7CA5}" MobileView="TRUE" Type="HTML" DisplayName="All Documents" Url="/DTRDemo/Forms/AllItems.aspx" Level="1" BaseViewID="1" ContentTypeID="0x" ImageUrl="/_layouts/15/images/dlicon.png?rev=23">
              <Query/>
              <ViewFields>
                     <FieldRef Name="DocIcon"/>
                     <FieldRef Name="LinkFilename"/>
                     <FieldRef Name="Modified"/>
                     <FieldRef Name="Editor"/>
                     <FieldRef Name="Category"/>
                     <FieldRef Name="ID"/>
                     <FieldRef Name="FileSizeDisplay"/>
              </ViewFields>
              <RowLimit Paged="TRUE">30</RowLimit>
              <Aggregations Value="Off"/>
              <JSLink>clienttemplates.js</JSLink>
              <XslLink Default="TRUE">main.xsl</XslLink>
              <Toolbar Type="Standard"/>
       </View>
</XmlDefinition>
<parameterbindings>
       <ParameterBinding Name="dvt_sortdir" Location="Postback;Connection"/>
       <ParameterBinding Name="dvt_sortfield" Location="Postback;Connection"/>
       <ParameterBinding Name="dvt_startposition" Location="Postback" DefaultValue=""/>
       <ParameterBinding Name="dvt_firstrow" Location="Postback;Connection"/>
       <ParameterBinding Name="OpenMenuKeyAccessible" Location="Resource(wss,OpenMenuKeyAccessible)" />
       <ParameterBinding Name="open_menu" Location="Resource(wss,open_menu)" />
       <ParameterBinding Name="select_deselect_all" Location="Resource(wss,select_deselect_all)" />
       <ParameterBinding Name="idPresEnabled" Location="Resource(wss,idPresEnabled)" />
       <ParameterBinding Name="NoAnnouncements" Location="Resource(wss,noXinviewofY_LIST)" />
       <ParameterBinding Name="NoAnnouncementsHowTo" Location="Resource(core,noXinviewofY_DEFAULT)" />
       <ParameterBinding Name="AddNewAnnouncement" Location="Resource(wss,addnewitem)" />
       <ParameterBinding Name="MoreAnnouncements" Location="Resource(wss,moreItemsParen)" />

</parameterbindings></WebPartPages:XsltListViewWebPart>







No comments:

Post a Comment