SharePoint Feature and Solution Example

Feature.xml

<?xml version="1.0" encoding="utf-8"?>
<Feature xmlns="http://schemas.microsoft.com/sharepoint/"
    Description="Adds a link to Site Actions"
    Hidden="FALSE"
    Id="1234364565758769879" /* GUID */
    ImageUrl=""
    Scope="Site" /* Farm, WebApplication, Site(Site Collection), Web */
    Title="Central Admin Link">
    <ElementManifests>
       <ElementManifest Location="Elements.xml" />
    </ElementManifests>
</Feature>

Element.xml

<?xml version="1.0" encoding="utf-8"?>
<Elements xmls="http://schemas.microsoft.com/sharepoint/">
     <CustomAction Id=""  /* GUID */
         Description="Open Central Admin"
         Location="Microsoft.SharePoint.StandardMenu"
         GroupId="SiteActions"
         ImageUrl=""
         Sequence="50"
         Title="Central Admin Link">
        <UrlAction Url="http://centraladmin:25550" />
     </CustomAction>
</Elements>

Install Feature Command:
stsadm -o installfeature -name <feature folder>

Deploy Solution Command:
stsadm -o AddSolution -filename <.wsp file>
stsadm -o DeploySolution -filename <.wsp file>

Add new site pages by feature

ReceiverAssembly 
ReceiverClass 
/* Module is element you would use to deploy anything into the content database in this feature */ <Elements> 
    <Module Path="OriginalFolder" Url="NewFolder"> 
       <File Path="Original.aspx" Url="NewPage1.aspx" NavBarPage ......
          <NavBarPage ID="" Name="" Position="" /> 
       </File> 
       <File Path="Original.aspx" Url="NewPage2.aspx" /> /* Copy to a new page name */ 
       /* Add web part to page by Feature */        
       <AllUsersWebPart WebPartZoneId="Left" WebPartOrder="0"> 
          <![CDATA[ 
              <WebPart xmlns="http://schemas.microsoft.com/WebPart/v2" 
                   xmlns:cewp="http://schemas.microsoft.com/WebPart/v2/ContentEditor"> 
                   <Assembly>Microsoft.SharePonint, Version=12.0.0.0, Culture=neutral, PublicKey.... 
                   <TypeName>Microsoft.SharePont.WebPartPages.ContentEditorWebPart</TypeName> 
                   <Title>WebPart in the left zone</Title> 
                   <FrameType>TitleBarOnly</FrameType> 
                   <cewp:Content> Webpart added using CAML </cewp:Content> 
             </WebPart>  
          ]]> 
       </AllUsersWebPart> 
    </Module> 
</Elements> 

/* Add web part to page by C# */
/* This feature is deployed to Web (site) level. */
SPWeb web = properties.Feature.Parent as SPWeb; 
if(web!=null) 
{ 
SPFile page = web.GetFile("MyPages/WPPage.aspx"); 
SPLimitedWebPartManager mgr = page.GetLimitedWebPartManager(PersonalizationScope.Shared); 
ContentEditorWebPart ceWP = new ContentEditorWebPart(); 
ceWP.Title = "WebPart in right zone"; 
XmlDocument doc = new XmlDocument(); 
XmlElement ceWPContent = doc.CreateElement("Content"); 
ceWPContent.InnerText = "WebPart added using c#"; 
ceWP.Content = ceWPContent; mgr.AddWebPart(ceWP, "Right", 0); 
}
Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s