开发者

I've got a sharepoint solution, what next

开发者 https://www.devze.com 2023-01-07 03:05 出处:网络
I\'m new to sharepoint. I have a C# solution, that has masterpages and user-controls to be used in a sharepoint site. I hav开发者_JAVA技巧e setup my sharepoint dev VM and i can browse the default shar

I'm new to sharepoint. I have a C# solution, that has masterpages and user-controls to be used in a sharepoint site. I hav开发者_JAVA技巧e 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?


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/">
  <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();
        }
    }


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


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

0

精彩评论

暂无评论...
验证码 换一张
取 消