Sunday, August 26, 2012

web Content Management WCM for Sharepoint 2010

Ted pattison thanks for the below steps to deploy branding :



 above sol is an Empty Sharepoint Project and the .master and .css file and .jog files were added using modules :

The idea here is to apply branding at the site collection level
 and to any site regardless of whether  its a publishing or non - publishing site thats there for us .

U can also deploy a SB sol at the farm level.

Since its a SandBox sol we have the following situation :
a sandboxed solution cannot deploy files within the SharePoint root directory or any other location on the file system of the web server. That means you cannot deploy branding files to familiar locations that are commonly used in farm

solutions, such as the IMAGES directory or the LAYOUTS directory. You must instead provision branding files, such as images and CSS files, inside the content database within the scope of the hosting site collection.
So its a matter of provisioning of the  branding

sandboxed solutions, it is important to distinguish between Features that activate at site collection scope and Featuresbthat activate at site scope. This is because a Feature that is configured to activate at site collection scope is automatically activated when the user activates the sandboxed solution that contains it. On the other hand, Features that

are configured to activate at site scope are not automatically activated. They must be manually activated by the user ornactivated by using custom code. For this reason, you should generally design a sandboxed solution with at least one

Feature configured to activate at site collection scope.
So we take the approach of creating /adding MODULE elements in the  empty SP project.

The 1st MODULE is for adding a SharePoint Master page and placing it in the /_catalogs/masterpage in MasterpageGallery

folder
So u add a sample.txt file and then copy the contents from the V4.master file and
and paste the same here .
make some twaeks .
Then make changes to the elements .xml file foir the module for the    
FileProperty(
     
      )
and Url (Url="_catalogs/masterpage" )for the the .master file that gets developed here .

<Elements xmlns="http://schemas.microsoft.com/sharepoint/">
  <Module Name="MasterPageGallery" Url="_catalogs/masterpage" >
    <File Url="MyCustomLayout.master" Type="GhostableInLibrary" >
      <Property Name="UIVersion" Value="4" />
      <Property Name="ContentTypeId" Value="0x010105" />
    </File>
  </Module>
</Elements> 
 
 
In the  

The 2nd MODULE is for adding a SharePoint Master page and placing it in the /_catalogs/MasterpageGallery folder
you do not have to modify the Elements.xml file manually in this case.

Then you add  a below shown Feature Receiver to Apply Branding Attributes :
to deploy a custom master page and a custom CSS file
You uncomment and code the
FeatureActivation
public override void FeatureActivated(
                       SPFeatureReceiverProperties properties) {
  SPSite siteCollection = properties.Feature.Parent as SPSite;
  if (siteCollection != null) {
    SPWeb topLevelSite = siteCollection.RootWeb;

    // Calculate relative path to site from Web Application root.
    string WebAppRelativePath = topLevelSite.ServerRelativeUrl;
    if (!WebAppRelativePath.EndsWith("/")) {
      WebAppRelativePath += "/";
    }

    // Enumerate through each site and apply branding.
    foreach (SPWeb site in siteCollection.AllWebs) {
      site.MasterUrl = WebAppRelativePath + 
                       "_catalogs/masterpage/Branding101.master";
      site.CustomMasterUrl = WebAppRelativePath + 
                             "_catalogs/masterpage/Branding101.master";
      site.AlternateCssUrl = WebAppRelativePath + 
                             "Style%20Library/Branding101/Styles.css";
      site.SiteLogoUrl = WebAppRelativePath + 
                         "Style%20Library/Branding101/Images/Logo.gif";
      site.UIVersion = 4;
      site.Update();
    }
  }
} 
 
 
public override void FeatureDeactivating(
                       SPFeatureReceiverProperties properties) {
  SPSite siteCollection = properties.Feature.Parent as SPSite;
  if (siteCollection != null) {
    SPWeb topLevelSite = siteCollection.RootWeb;

    // Calculate relative path of site from Web Application root.
    string WebAppRelativePath = topLevelSite.ServerRelativeUrl;
    if (!WebAppRelativePath.EndsWith("/")) {
      WebAppRelativePath += "/";
    }

    // Enumerate through each site and remove custom branding.
    foreach (SPWeb site in siteCollection.AllWebs) {
      site.MasterUrl = WebAppRelativePath + 
                       "_catalogs/masterpage/v4.master";
      site.CustomMasterUrl = WebAppRelativePath + 
                             "_catalogs/masterpage/v4.master";
      site.AlternateCssUrl = "";
      site.SiteLogoUrl = "";
      site.Update();
    }
  }
} 
 
 
The AlternateCssUrl property is used to link the pages in a site to the custom CSS file named Styles.css.

Alternative approach of linking to a custom CSS file by using the CSSRegistration control. For example, you can add the 

following CssRegistration element to the head section of a custom master page to link to a CSS file inside the Style 

Library.
XML

  name="<% $SPUrl:~sitecollection/Style Library/styles.css %>" 
  After="corev4.css"
  runat="server"
/>

One benefit of using the CssRegistration control over the AlternateCssUrl property is that it enables you to link to more 
than one CSS file. A second advantage is that you can use the CssRegistration control in individual pages for scenarios 
where you have a CSS file that is used by some, but not all, pages within a site. However, using the CssRegistration 
control also has a downside because it relies on the $SPUrl expression, which requires the hosting farm to be running 
SharePoint Server 2010

For SharePoint 2010 UIVersion = 4 


Once the above is don we  have  to think of applying this branding to any new site that gets created 
from this site collection
We solve this by Adding an Event Receiver .
SharePoint Server 2007, you would have to use Feature stapling. However, SharePoint 2010 adds support for a new event 
named WebProvisioned, which makes the job much easier.

Select an Event Receiver of type Web Events. At the bottom of the dialog box, under Handle the following events, select 
the A site was provisioned option.
file, which contains the Receivers element that is required to register this event handler in the current site 
collection. The benefit of adding this event is that it occurs each time a new child site is created. This makes it 
fairly easy to write the code that copies the relevant SPWeb properties from the top-level site to the new child site. 

The following shows the code that is required.
 
using System;
using Microsoft.SharePoint;

namespace Branding101.ChildSiteInit {

  public class ChildSiteInit : SPWebEventReceiver {
    public override void WebProvisioned(
                           SPWebEventProperties properties) {
      SPWeb childSite = properties.Web;
      SPWeb topSite = childSite.Site.RootWeb;
      childSite.MasterUrl = topSite.MasterUrl;
      childSite.CustomMasterUrl = topSite.CustomMasterUrl;
      childSite.AlternateCssUrl = topSite.AlternateCssUrl;
      childSite.SiteLogoUrl = topSite.SiteLogoUrl;
      childSite.Update();
    }
  }
}
 
SharePoint Designer does not let you directly edit the templates for master pages, such as Banding101.master, 
or the templates for CSS files, such as styles.css. Instead, when you are working in SharePoint Designer 2010 you are 
making customization changes to provisioned instances that are stored inside the content database. However, this does not 
pose much of a problem because you just have to know how to copy and paste from SharePoint Designer 2010 into Visual 
Studio 2010.
 


=======================================
i didn't know much about WCM till i was asked to create a publishing site and then I had to open the same from the SPD. Once i go and try to open the Master pages for that site  I see that I can edit the master page and  .

Randy Drisgill and Scott hillier article


v good :
add/move/delete  web parts from SP site Master page

http://sharepoint.microsoft.com/blog/Pages/BlogPost.aspx?PageType=4&ListId={72C1C85B-1D2D-4A4A-90DE-CA74A7808184}&pID=794

http://sharepoint-insight.blogspot.in/2008/09/sharepoint-using-splimitedwebpartmanage.html

in mysite host we have the mysite.master which can be used.
startermasterpages.codeplex.com u can download the master pages.

Global navigation at the top that can be designed at the top.
From the SP designer we can get the list of  the master pages that are there for
the site that we have opened the designer for .
Among them there will be the v4.master.
There u will find a lot of 

using the  s4_die css class
so u can bunch all of these place holders in one place.
So in the mymaster.master page u will have bunched them togthere and
the main thing  is

these are the tags that  are more important and usefull to us.                                                                            
Among the folders that are there is the StylesLibrary folder.
All the css and the .ico,.js files that will be required by our branding should be placed
in this folder .
 
To get the relative location of .css files in the master page  or other resources we can use the
SPUrl:~sitecollection/style library/site1/mysite.css

You can right click on the master page that u are developing and apply the same to
custom  and site pages.
Site pages : Site settings/central admin etc.
custom pages can be the search/profile pages etc. that u are changing.

Delegate Control : Enables u to put a control in a site. However that control can be overridden
by a feature.So in our case we can inject a control using the delegates.You can code a  feature that will override the targeted delegate control with the custom control.

 Example we can change the default search with a a different search. Hence here u can use the
delegate

 we get the question to change the navigation at the top or bottom.


This the GlobalNavigationLink and that's what is played around  here.

We have to load a custom control instead of the ootb control.Hence comes in the Feature that requires deployement .
in the `14/template/control template/myTopNav.ascx
The feature is in the 14/template/features/CustomMysiteNav folder/feature.xml,elements.xml

The feature file has the normal things like title/scope/ etc. and the elementmanifest points to the
element.xml.

In the element.xml file
Sequence=10
ControlSrc = "~/Conrol ../template/myTopNav.ascx "

In the above line of code  the sequence given is supposed to be higher than that of the
OOOOTB  control asscoaiated with the globalnavigation id.
If you goto the v4.master you will find a delegate control having the same Control id="GobalNavigation"
and that what gets overridden here.

So the 2nd part of the presentation is all about the  packaging the branding into a feature.
Then stapling the feature into we Provisioning in this case  the provisioning of the Personal site
SPSPERS#0 template.

feature site template associations (also known as “feature stapling”), master pages, is the method.

Now we create a  Feature and that will,be used for activating the master pages /styles etc.
The Feature activated method is overridden  and there we can write the code for the setting the
MasterURL and Custom mAsterurl
WITH THE master pages file  that is placed at a certain location in the _catalog folder.
the style sheets are placed at the /Style Library /Folder. the css,logo files are placed using a
feature out there .

ADDING/deleting/moving web parts in a MySite
--------------------------------------------
tricky because there is a timing issue involved .
Because when u are moving /changing the master pages u have to make sure that the page exists before the page runs.
So u have use a server control that does  a postback when the page loads and hence it is made  sure that the page exists.Make sure that the code runs only after the page loads
tinyurl.com/MysiteDeploy

Lots of complexity here for WebParts are displayed to the user depending on the user profile that is plugged in here for that user.

 Mysite is the backbone of the social content of the SharePoint.