Buenas . Ayer hablando como mi compañero Carlos Labrador, sobre Branding en SharePoint y Office 365, recordé una serie de artículos que vi en una pagina muy buena de Microsoft llamada Patterns and practices que os recomiendo a todos . http://dev.office.com/patterns-and-practices

 

Hay una serie de artículos sobre Branding que me los baje y los iré poniendo poco a poco .

Cambiar las propiedades CSS URL & URL Logo del Sitio en un web Object

Resumen

Este escenario muestra cómo cargar CSS e imagen de sitio a un host web y cómo configurarlos utilizando CSOM. Se trata de nuevas funcionalidades que se liberaron justo hace un año tanto en Onpremise como en Online para utilizar CSOM.

Guía Video


                                                                         

Aplica a

  • Office 365 Multi Tenant (MT)

Prerequisitos

N/A

Solution

Solution Author(s)
Branding.AlternateCSSAndSiteLogo Vesa Juvonen (Microsoft)

Version history

Version Date Comments
1.0 June 30th 2014 Initial release

Disclaimer

THIS CODE IS PROVIDED AS IS WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESS OR IMPLIED, INCLUDING ANY IMPLIED WARRANTIES OF FITNESS FOR A PARTICULAR PURPOSE, MERCHANTABILITY, OR NON-INFRINGEMENT.


SCENARIO: INJECT CUSTOM CSS FROM APP TO HOST WEB

Una vez que la modificación se ha inyectado, podemos ver el host web ha tenido una alineación centralizada y hemos vuelto a poner la barra de acciones de la pagina utilizando sólo CSS a una ubicación diferente. Esto demuestra la capacidad de realizar posibles cambios estructurales en la renderización sin la necesidad de utilizar la página maestra personalizada. Las páginas maestras personalizadas deben evitarse para asegurar que cualquier actualización o mejoras agregadas out of the box de las páginas maestras son automáticamente usadas en los sitios. Mediante la combinación de esta propiedad CSS se alternan con un motor de tematización, tendrá mucho más futuro enfoque más amigable en las personalizaciones

 

UPLOADING ASSETS TO THE HOST WEB

Los archivos CSS y los archivos de imágenes se cargan usando FileCreationInformation objet. En este caso les estamos agregando a la biblioteca de activos del sitio, pero se pueden subir a cualquier sitio del host web o incluso podriamos estar hacer referencia utilizando URLs absolutas.

// Instance to site assets
List assetLibrary = web.Lists.GetByTitle("Site Assets");
web.Context.Load(assetLibrary, l => l.RootFolder);

// Get the path to the file which we are about to deploy
string cssFile = System.Web.Hosting.HostingEnvironment.MapPath(
string.Format("~/{0}", "resources/contoso.css"));

// Use CSOM to uplaod the file in
FileCreationInformation newFile = new FileCreationInformation();
newFile.Content = System.IO.File.ReadAllBytes(cssFile);
newFile.Url = "contoso.css";
newFile.Overwrite = true;
Microsoft.SharePoint.Client.File uploadFile = assetLibrary.RootFolder.Files.Add(newFile);
web.Context.Load(uploadFile);
web.Context.ExecuteQuery();

// Get the path to the file which we are about to deploy
string logoFile = System.Web.Hosting.HostingEnvironment.MapPath(
string.Format("~/{0}", "resources/99x.png"));

// Use CSOM to uplaod the file in
newFile = new FileCreationInformation();
newFile.Content = System.IO.File.ReadAllBytes(logoFile);
newFile.Url = "99x.png";
newFile.Overwrite = true;
uploadFile = assetLibrary.RootFolder.Files.Add(newFile);
web.Context.Load(uploadFile);
web.Context.ExecuteQuery();

 

CONTROLANDO LAS PROPIEDADES HOST WEB

Añadiendo las propiedades es bastante fácil y sencillo. Ambas propiedades también admiten direcciones absolutas.

// Set the properties accordingly
// Notice that these are new properties in 2014 April CU of 15 hive CSOM and July release of MSO CSOM
web.AlternateCssUrl = web.ServerRelativeUrl + "/SiteAssets/contoso.css";
web.SiteLogoUrl = web.ServerRelativeUrl + "/SiteAssets/99x.png";
web.Update();
web.Context.ExecuteQuery();

ELIMINANDO LAS CUSTOMIZACIONES DESDE FROM HOST WEB

Eliminar las personalizaciones es tan fácil como configurar las propiedades a empty strings

Web web = clientContext.Web;
// Clear the properties accordingly
// Notice that these are new properties in 2014 April CU of 15 hive CSOM and July release of MSO CSOM
web.AlternateCssUrl = "";
web.SiteLogoUrl = "";
web.Update();
web.Context.ExecuteQuery();