SharePoint 2013 WCM Advanced Cookbook
上QQ阅读APP看书,第一时间看更新

Changing the site logo

The logo is the image displayed, usually in the upper-left corner, on each page in a SharePoint site. Clicking on the logo returns the user to the root home page of the SharePoint site, as shown in the following screenshot:

Changing the site logo

Getting ready

To complete this recipe you will need an image uploaded or available to upload to the SharePoint site.

How to do it...

Follow these steps to change the site logo:

  1. Navigate to the site in your preferred web browser.
  2. Select Site settings from the Settings menu.
  3. Select Title, description, and logo from the Look and Feel section.
    How to do it...
  4. Under Insert Logo, select the logo by clicking on FROM COMPUTER to upload a new image or by clicking on FROM SHAREPOINT to use an image already existing in the SharePoint site.
  5. Add a simple and short description for the logo in the Enter a description textbox as shown in the following screenshot:
    How to do it...
  6. Click on OK to save the changes. The logo should appear as shown in the following screenshot:
    How to do it...

How it works...

The site relative URL for the logo image is assigned to the SiteLogoUrl property of the SPWeb object representing the site, and the logo description is set to the SiteLogoDescription property. The SPWeb object is then saved to the SharePoint database. The logo description will be used as the alternative text for the logo that will be displayed when hovering over the image with a mouse, as well as used by non-standard browsers such as screen readers.

There's more...

The site logo and description may also be applied with PowerShell or code using the server-side object model.

Changing the site logo using PowerShell

Follow these steps to change the site logo using PowerShell:

  1. Get the SharePoint site using the Get-SPWeb Cmdlet:
    $web = Get-SPWeb http://sharepoint/site
    
  2. Set the SiteLogoUrl property to specify the URL of the image logo and the SiteLogoDescription property to specify the alternative text for the logo:
    $web.SiteLogoUrl = "/SiteAssets/logo.png"
    $web.SiteLogoDescription = "My PowerShell Site"
    

    Note

    Setting the SiteLogoUrl property assumes that the referenced image has already been uploaded to the site.

  3. Use the Update method to apply the changes:
    $web.Update()
    
  4. Use the Dispose method to discard the SPWeb object:
    $web.Dispose()
    

Changing the site logo with code using the server-side object model

Follow these steps to change the site logo with code using the server-side object model:

  1. Open the site collection containing the site in a using statement:
    using (var site = new SPSite("http://sharepoint/site"))
  2. Open the site in a using statement:
    using (var web = site.OpenWeb())
  3. Set the SiteLogoUrl property to specify the URL of the image logo and the SiteLogoDescription property to specify the alternative text for the logo:
    web.SiteLogoUrl = "/SiteAssets/logo.png";
    
    web.SiteLogoDescription = "My PowerShell Site";
  4. Use the Update method to apply the changes:
    web.Update();