views:

54

answers:

3

I'm new to sharepoint. I have a C# solution, that has masterpages and user-controls to be used in a sharepoint site. I have setup my sharepoint dev VM and i can browse the default sharepoint stuff.

How do I add the master pages to Sharepoint? Where do I go from here?

A: 

Copy them to SharePoint root (For SP 2007 default location is C:\Program Files\Common Files\microsoft shared\Web Server Extensions\12\, for SP 2010 instead of "12" you have "SharePointRoot")

From there, copy your files to \TEMPLATE\LAYOUTS folder and then you can reference masterpage from your aspx pages like "/_layouts/mymasterpage.master".

UserControls goes into \TEMPLATE\CONTROLTEMPLATES

Get to know the directory structure in the 12 Hive

Exploring the 12 Hive : TEMPLATE Directory

Another way is to put your masterpage in master pages list. Use this link to access master page list and upload your masterpage: http:///_catalogs/masterpage

Janis Veinbergs
A: 

You can add master pages using the SharePoint Designer 2007.

Generally i recommend you to take a look at the answers of this question: Learning Sharepoint

You can but you really shouldn't. It _may_ be okey if you plan to add it to just one server just once. If you initially think 'No' to one or more of the scenarios you really should put the masterpage in a feature/solution.
JWL_
I agree that a feature/solution is usually the better way. But the Sharepoint Designer is a correct answer, Robert Dondo should see results quickly and i do not know anything about his scenario. I provided the link to 'Learning Sharepoint' for him as a starting point to learn more.
A: 

My suggestion would be to deploy the master pages as a feature rather than a manual process. Solutions (WSPs) and Features are the supported way to deploy content/features into sharepoint. A really great tool for sharepoint development is called WSPBuilder

A master page is deployed into sharepoint as a "module" that you will place into your elements.xml file in the feature.

Think of a solution as a .cab file with a different extension. Within that is a file called feature.xml which defines the title of your package when its deployed. Features can be activated and deactivated to deploy and undeploy your content into parts of your farm.

Here is an example of a css file deployed as a Module... Master pages would be similar however, they would deploy into the master page gallery rather than the style library. This module deploys a custom css file into the "Style Library" of a site collection. After this is deployed I used a "Feature Receiver" (event handler) to grab a reference to the SPSite object and modify its alternate stylesheet so that my override took place.

Feature.xml

<?xml version="1.0" encoding="utf-8" ?>
<Feature xmlns="http://schemas.microsoft.com/sharepoint/" 
         Id="63BB13A0-1F9C-4c3b-BE60-10E59CEE0113"
         Title="Custom CSS Feature"
         Description="Deploying a custom CSS using a feature"
         Version="1.0.0.0"
         Hidden="FALSE"
         Scope="Site"
         ReceiverAssembly="CustomCSSFeature, Version=1.0.0.0, Culture=neutral, PublicKeyToken=24f1377a8414d2ed"
         ReceiverClass="CustomCSSFeature.FeatureReceivers.CustomCSSFeatureReceiver"
         >
  <ElementManifests>
    <ElementManifest Location="elements.xml"/>
  </ElementManifests>
</Feature>

elements.xml - you'd modify this to reflect where master pages are supposed to be deployed I would think that this is the Url property. The Path="Styles" refers to the relative path within the feature itself where the style sheet resides (e.g. in your visual studio i have a sub folder called styles beneath the folder called CustomCSSFeature and that is where the style sheet exists)

    <?xml version="1.0" encoding="utf-8" ?>
<Elements xmlns="http://schemas.microsoft.com/sharepoint/"&gt;
  <Module Name="OSGStyles" Url="Style Library" Path="Styles" RootWebOnly="TRUE">
    <File Url="custom-css.css" Type="GhostableInLibrary" />
  </Module>
</Elements>

Then, in my feature receiver class I have activated/deactivated handlers which "apply" the stylesheet to the publishing web. In your case you can likely change the default master page for the website in a feature receiver as well.

public override void FeatureActivated(SPFeatureReceiverProperties properties)
    {
        SPSite site = properties.Feature.Parent as SPSite;

        using (SPWeb web = site.OpenWeb())
        {
            PublishingWeb publishingWeb = PublishingWeb.GetPublishingWeb(web);
            publishingWeb.AlternateCssUrl.SetValue(web.ServerRelativeUrl + 
                "/Style Library/custom-css.css", true);
            publishingWeb.Update();
            web.Update();
        }
    }

    public override void FeatureDeactivating(SPFeatureReceiverProperties properties)
    {
        SPSite site = properties.Feature.Parent as SPSite;

        using (SPWeb web = site.OpenWeb())
        {
            PublishingWeb publishingWeb = PublishingWeb.GetPublishingWeb(web);
            publishingWeb.AlternateCssUrl.SetValue("", true);
            publishingWeb.Update();
            web.Update();
        }
    }
Famous Nerd
thanks a lot, got me started. The solution has some user controls. The masterpages reference these controls using the absolute path.Is the deployment process the same for the controls, and, once i have deployed them, how do i reference them from the master page?
Robert Dondo
You can declare them in the master page after deploying them as content files to the 12-hive... layouts or controltemplates.e.g. <@ Register TagPrefix="ctrl" src="/_controltemplates (or _layouts)/MyFeatureName/MyControl.ascx" >In both cases you'll want to deploy the .ascx portion of your solution into a subfolder of template/layouts or better yet into a subfolder of controltemplates using the .wsp[Heather solomon](http://www.heathersolomon.com/blog/articles/servermstpageforsitecollect_feature.aspx) has a good example of master pages deployed as features.
Famous Nerd
Also, [User controls in master](http://www.learningsharepoint.com/2010/06/27/add-user-control-in-sharepoint-master-page/)
Famous Nerd