How to add a custom website to a custom view aspx page in a list definition project

I developed a list definition project and created a custom aspx view page that will display by default in the list. Now I would like to add a custom website that will be displayed on a custom view aspx page. Any ideas on how to do this?

+3
source share
3 answers

You can use the feature receiver and control the addition of web parts during feature activation. Here are some stubs to help you get started.

In an activated method, a calling code similar to the following:

        // Add web parts to the .aspx page that was provisioned
        SPFile page = site.GetFile(<<page url>>);

        Hashtable hashWebPartsOnPage = new Hashtable();

        using (SPLimitedWebPartManager mgr = page.GetLimitedWebPartManager(PersonalizationScope.Shared))
        {
            try
            {
                // First, let clear the existing web parts off of the form
                foreach (System.Web.UI.WebControls.WebParts.WebPart webPart in mgr.WebParts)
                {
                    hashWebPartsOnPage.Add(webPart.ID, webPart);
                }

                foreach (string webPartName in hashWebPartsOnPage.Keys)
                {
                    System.Web.UI.WebControls.WebParts.WebPart webPart = hashWebPartsOnPage[webPartName] as System.Web.UI.WebControls.WebParts.WebPart;
                    mgr.DeleteWebPart(webPart);
                }

                // Add Part to the proper Zone
                MyWebPart myWebPart = new MyWebPart();
                //set web part properties
                mgr.AddWebPart(myWebPart, "FullPage", 1);
            }
            finally
            {
                mgr.Web.Dispose();
            }

        }
        page.Update();
+2
source

SharePoint 2010 - SharePoint WebPart Schema.xml ( List).

MSDN, , "<WebParts> "; - :

<View BaseViewID="7" Type="HTML" WebPartZoneID="Main" DisplayName="$Resources:CILSS_defaultView" DefaultView="TRUE" MobileView="FALSE" MobileDefaultView="FALSE" SetupPath="pages\viewpage.aspx" ImageUrl="/_layouts/images/generic.png" Url="CI_Projects.aspx">
        <Toolbar Type="Standard" />
        <XslLink Default="TRUE">main_cilss.xsl</XslLink>
        <RowLimit Paged="TRUE">30</RowLimit>
        <ViewFields>
          <FieldRef Name="Attachments"></FieldRef>
          <FieldRef Name="LinkTitle"></FieldRef>
          <FieldRef Name="CILSS_ProjectDescription"></FieldRef>
        </ViewFields>
        <Query>
          <OrderBy>
            <FieldRef Name="LinkTitle" Ascending="TRUE"></FieldRef>
          </OrderBy>
        </Query>
        <ParameterBindings>
          <ParameterBinding Name="NoAnnouncements" Location="Resource(wss,noXinviewofY_LIST)" />
          <ParameterBinding Name="NoAnnouncementsHowTo" Location="Resource(wss,noXinviewofY_DEFAULT)" />
        </ParameterBindings>
        <WebParts>
          <AllUsersWebPart WebPartZoneID="Main" WebPartOrder="2">
            <![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>Default Home Webpart</Title>
  <FrameType>None</FrameType>
  <Description>Use for formatted text, tables, and images.</Description>
  <IsIncluded>true</IsIncluded>
  <ZoneID>Left</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/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="" />
  <Content xmlns="http://schemas.microsoft.com/WebPart/v2/ContentEditor">
  <Value>&lt;div&gt;Create and view Project documents:&lt;/div&gt;
&lt;br/&gt;</Value></Content>
  <PartStorage xmlns="http://schemas.microsoft.com/WebPart/v2/ContentEditor" />
</WebPart>]]>
          </AllUsersWebPart>
        </WebParts>
      </View>

- , 'CI_Projects.aspx' WebPartZoneId BaseViewID, , .

- ​​ , . (, view.aspx, ).

+2

, , , , site.GetFile(). , , , . :

  • OOB "ViewPage.aspx" , "CustomViewPage.aspx"

  • -, .

  • "CustomViewpage.aspx" -.

  • . schema.xml "SetupPath" "CustomViewPage.aspx" . , , "CustomViewPage.aspx" , , , "customViewPage.aspx" .

1:

OOB "ViewPage.aspx" C:\Program Files\Common Files\Microsoft Shared\web server extensions\12\TEMPLATE\Pages "CustomViewPage.aspx"

2:

-, . GetViewfromUrl ( "//" ), , -. - :

SPList = SPContext.Current.List;

strViewName =

SPView view = SPContext.Current.Web.GetViewFromUrl( "//" + strViewName);

SPListItemCollection listItems = list.GetItems();

. .

.

.

.

DLL - GAC.

3:

"CustomViewPage.aspx" -. "Customviewpage.aspx" -. :

<File Url="Pages/CustomViewPage.aspx" Type="Ghostable">

  <AllUsersWebPart WebPartZoneID="Main" WebPartOrder="1">

    <![CDATA[

               <WebPart xmlns="http://schemas.microsoft.com/WebPart/v2">

                    <Assembly>CustomWebpartforView, Version=1.0.0.0, Culture=neutral, PublicKeyToken=e3483ddc8b0d437a</Assembly>

                    <TypeName> CustomWebpartforView.MyCustomview</TypeName>

                    <FrameType>None</FrameType>

                                            <IsVisible>true</IsVisible>

                    <Title>Custom Web part for View</Title>                                 

               </WebPart>

               ]]>

  </AllUsersWebPart>

</File>

, , Path

4:

-. , . , , "SetupPath" "CustomViewPage.aspx" . , , "CustomViewpage.aspx" . schema.xml :

.

"CustomViewPage.aspx" , - OOB dataformwebpart. , ( , ), "CustomViewpage.aspx" .

- CustomViewPage.aspx -. - - .

+1

Source: https://habr.com/ru/post/1705428/


All Articles