Wednesday, March 27, 2013

Programmatically determine if a web-scoped feature has been activated

This may be of limited use, but if you're ever looking for a way to programmatically determine if a web-scoped feature has been activated on a given SharePoint site, here is a quick method you can use to obtain that information:

private bool IsFeatureActivated(Guid siteId, Guid webId, Guid featureId)
{
    bool isFeatureActivated = false;
    using (SPSite site = new SPSite(siteId))
    {
        using (SPWeb web = site.OpenWeb(webId))
        {
            if (web.Features[featureId] != null)
            {
                isFeatureActivated = true;
            }
        }
    }
    return isFeatureActivated;
}

Monday, March 11, 2013

View the XML data behind a Search Core Results Web Part


If you wish to view the raw XML data that is associated with a Search Core Results or People Search Core Results web part, you can do so via the following steps:

  1. Open IE and navigate to the page that contains the given Core Results web part
  2. Select Site Actions -> Edit Page
  3. Click on your web part's menu and select Edit Web Part
  4. Expand Display Properties and click on the XSL Editor... button
  5. In the Text Editor window, copy the existing XSL to a temporary location since you'll probably need it again.  Here is a possible option for you:
    1. Hit Ctrl+a to highlight all of the content
    2. Hit Ctrl+c to save the content
    3. Open Notepad
    4. Hit Ctrl+v to past the content to Notepad
  6. Return to the Text Editor window, hit Ctrl+a, and hit Delete
  7. Copy and paste the following XSL code into the Text Editor window:
  8. <?xml version="1.0" encoding="UTF-8"?> <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"> <xsl:output method="xml" version="1.0" encoding="UTF-8" indent="yes"/> <xsl:template match="/"> <xmp><xsl:copy-of select="*"/></xmp> </xsl:template> </xsl:stylesheet>
  9. Click Save
  10. Click OK
  11. Return to the parent Search page and enter a valid search parameter
At this point, the page that contains the Search Core Results web part will be displayed with the XML contents available for your review.  Once your review of the data is complete, I recommend that you revisit the XLS Editor... and replace the XSL code with the code that you copied into Notepad earlier.  Unless, of course, your users like to view XML data in his/her search results which is not very likely...

Thursday, March 7, 2013

Assign a Preview image to your custom Page Layouts

There are quite a few good sites out there that provide steps for creating custom page layouts using the new SharePoint 2013 Design Manager, but none of them bring up how you would go about assigning a Preview image to your new custom Page Layouts. This is most likely due to the fact it's pretty simple to do once you know where to look for it. Anyway, these procedures assume that you've already created and deployed your new custom Page Layouts using Design Manager. Here goes...

Add the Preview Images to the Master Page Gallery
  1. Using your web browser, open up a link to your Master Page Gallery (i.e.  http://SharePointWebApp/_catalogs/masterpage/Forms/AllItems.aspx)
  2. Double-click on the en-us directory
  3. Double-click on the Preview Images directory
  4. Click on the Files tab
  5. Under the New section, click Upload Document
  6. Click Browse..., navigate to your first Preview file, and click on it
  7. Click Open
  8. Click OK
  9. For Content Type, select Master Page Preview
  10. For UI Version, place a check in the 15 checkbox



  11. Click Save
  12. Once the image is uploaded, click on the image list item and select Publish a Major Version
  13. Click OK
  14. Repeat Steps 5-13 for each Preview Image
NOTE:  If you don't publish your files as shown in Steps 12-13, your Preview images will appear as a red X when the user is looking at the locations where the Preview image is viewed


Assign the Preview Images
  1. Navigate back to the home page of the Master Page Gallery
  2. If you used the Design Manager to add your custom Page Layouts, you will click on the .html file associated with your first custom Page Layout and select Edit Properties (that is, if they are still associated with each other which is most likely the case...)
  3. Locate the Preview Image section
  4. Enter the URL of the file in the Type the Web address: textbox  (i.e. http://SharePointWebApp/_catalogs/masterpage/en-US/Preview%20Images/PreviewImageName.png)
  5. Enter a user-friendly description in the Type the description: textbox
  6. Click Save
  7. Repeat Steps 2-6 to assign the Preview images to their resepctive Page Layouts

Verify the Preview Image of a custom Page Layout
  1. Navigate to a page on your site and click Edit
  2. Click on the Page tab
  3. Under Page Actions, click Page Layout
  4. Verify that your custom Preview image has been assigned (i.e. in my example, my custom Page Layout is TestLayout1 and it's based on the Article Page content type)