Pages

Friday, August 1, 2014

SharePoint Ribbon Custom Action Button in Publishing Page Tab

While extending SharePoint 2010/2013 Ribbon with new functionality one of the common things you do is to check whether a command should be enabled or not. Since the checking function expects you to return a value it can get tricky if your custom checking operation is asynchronous. Find out how to asynchronously check if a Ribbon command is available.


While working on one of our SharePoint 2010 WCM products recently I had to apply this concept twice: once for checking if a button should be enabled and the other time for checking if a toggle button should be on or off. Below you will find sample code from the Page Component for both scenarios.
For the purpose of this article I have created the following custom Ribbon command:

<CustomAction Id="Mavention.SharePoint.Labs.MyCustomAction"
              Location="CommandUI.Ribbon"
              Sequence="10">
  <CommandUIExtension>
    <CommandUIDefinitions>
      <CommandUIDefinition Location="Ribbon.WikiPageTab.PubPageActions.Controls._children">
        <ToggleButton
          Id="Ribbon.WikiPageTab.PubPageActions.MaventionMyCustomAction"
          Alt="My Custom Action"
          Command="Mavention.SharePoint.Labs.MyCustomAction"
          QueryCommand="Mavention.SharePoint.Labs.MyCustomActionQuery"
          LabelText="My Custom Action"
          Sequence="40"
          TemplateAlias="o2"
          Image16by16="/_layouts/$Resources:core,Language;/images/formatmap16x16.png" Image16by16Top="-112" Image16by16Left="-16"
          ToolTipTitle="My Custom Action"
          ToolTipDescription="My Custom Action."/>
      </CommandUIDefinition>
    </CommandUIDefinitions>
  </CommandUIExtension>
</CustomAction>




STSADM command for deactivate,retract solution, delete solution, add solution, deploy feature

Please follow below steps to get context to run stsadm commands in windows command prompot,

1. Run Command Prompt as 'Administrator'
2. Type below command to go to SharePoint context to run stsadm commands.
cd C:\Program Files\Common Files\Microsoft Shared\web server extensions\15\BIN

Now you can run below commands,

STSADM Commands to retract solution
 stsadm -o deactivatefeature -id FEATUREGUID -url http:// -force
 stsadm -o deactivatefeature -id FEATUREGUID -url http:// -force
 stsadm -o execadmsvcjobs
 stsadm -o retractsolution -name WSPNAME.wsp -immediate -allcontenturls
 stsadm -o execadmsvcjobs

 STSADM Command for delete solution
stsadm -o deletesolution -name WSPNAME.wsp -override
stsadm -o execadmsvcjobs

 STSADM Command for add solution and deploy solution
stsadm -o addsolution -filename WSPNAME.wsp
stsadm -o execadmsvcjobs
stsadm -o deploysolution -name WSPNAME.wsp -url http://  -immediate -allowgacdeployment

 STSADM Command for activating feature
 stsadm -o execadmsvcjobs
 stsadm -o activatefeature -id FEATUREGUID -url http://
 stsadm -o activatefeature -id FEATUREGUID -url http://
  
 stsadm -o execadmsvcjobs
 stsadm -o activatefeature -id FEATUREGUID -url http://
 stsadm -o activatefeature -id FEATUREGUID -url http://

Tuesday, June 18, 2013

Gets a page based on the given URL in SharePoint

The following function is used for getting a sharepoint page listitem based on the given URL. It returns an SPListItem for the page if found. If it returns null is the page is not found or the user doesn't have permissions to see it.

public SPListItem GetListItem(string pageUrl, SPContext context)
{
                SPListItem page;
  try
  {
          using (SPWeb web = context.Site.OpenWeb(pageUrl, false))
          {
    page = web.GetObject(pageUrl) as SPListItem;
   }
   }
   catch (FileNotFoundException)
   {
    page = null;
   }
   catch (ArgumentException)
   {
    page = null;
   }

   return page;
  }
                catch(Exception ex)
                {}
}

In the above function the parameters are,
pageUrl - Page url to search and get the SPLisItem
context - The SPContext to use to retrieve the list item.

Hope it helps.