Archive

Posts Tagged ‘Coding’

WSSv3 Using a custom topnavbar using XMLSitemap

May 19th, 2008 No comments

After provisioning the site as seen in: How to provision a site (with master page and default.aspx) in WSSv3 using a site definition I want to add a custom menu to the topnavbar. I decided to use the XmlSiteMapProvider so I can use a simple XML file to define the menu layout. When you want to use a custom XML you have to add a value to the web.config of the sharepoint site to point to the XML file, i want this menu to be added by default when a site is created so i will add it to my site provision

Step 1: Create a sitemap file and place it in TEMPLATE\Layouts\Cmenu.Sitemap, for example:







Step 2: Add the xml file as a new sitemapprovider to the web.config in a feature:
public override void FeatureActivated(SPFeatureReceiverProperties properties)
  {     SPWeb siteCollection = (SPWeb)properties.Feature.Parent;
        SPWebApplication webApp = siteCollection.Site.WebApplication;

        SPWebConfigModification modification = new SPWebConfigModification();
        modification.Path = “configuration/system.web/siteMap/providers”;
        modification.Name = “add[@name='CMenu']“;
        modification.Sequence = 0;
        modification.Owner = “FeatureReceiverSiteLayout”;
        modification.Type = SPWebConfigModification.SPWebConfigModificationType.EnsureChildNode;
        modification.Value = ““;

            webApp.WebConfigModifications.Add(modification);
     //    webApp.WebConfigModifications.Remove(modification);
        // Save web.config changes.
        webApp.Farm.Services.GetValue().ApplyWebConfigModifications();
        // Serialize the web application state and propagate changes across the farm.
        webApp.Update();
        siteCollection.Dispose();
}
Use the webApp.WebConfigModifications.Remove part to remove the item from the web.config. Take note the FeatureDeactivating will not be be called when a site is deleted, use the FeatureUninstalling when you want the the item removed from the web.config at site delete.

Step3: Change your master page with the following:

  • find the asp:ContentPlaceHolder id=”PlaceHolderHorizontalNav” tag, place the following above it: ““. This creates the link from SiteMapDataSource to your XmlSiteMapProvider.
  • Edit the datasource propertie of  asp:ContentPlaceHolder id=”PlaceHolderHorizontalNav” to: DataSourceID=”SMCMenu”

The page will now use the your XML file as navigation

Step 4: When provisioning a site using a site definition you would like the feature to autmomaticly add the changes to the web.config. To do this you have to add:

  • Find the ID of the feature in feature.xml
  • Find the node in ONET.XML
  • Place a new WebFeatures in de the WebFeatures tag under configuration “
           
  • Now the feature will be activtivated on site creation.

Keep in mind that the feature has to be deployed to the server first, again this is posible with WSPBuilder

Categories: Uncategorized Tags: ,

WSSv3, Provisioning a site (with master page and default.aspx) using a site definition

May 19th, 2008 1 comment

I have to create a site in Sharepoint (Wss) with a default pages in complete custom layout and custom menu and it has to be created as a package so the Wss site can be deployed to multiple sites.

I started by developing the master page with heather solomon’s simple masterpage as basis, Then i decided to develop a few features to deploy the master page, install the menu and provision a few standard pagelouts to the site. The master page and menu worked, but provisioning the default.aspx is not possible with features.

So I decided to make a switch to provision with a site defenition instead of features, it has some advantages over features, you can use the site definition to create a site at once instead of using the feature’s.

Step 1: Create your own Sitetemplate.

  • Go to “12\TEMPLATE\1033\XML” and copy the file WEBTEMP.XML to WEBTEMPYOURTEMPLATE.XML
  • create your own template config:


  • Mind the ID part, just use a ID that doesn’t exist in WEBTEMP.XML .
  • create a directory in “\12\TEMPLATE\SiteTemplates\YOURTEMPLATE”
  • create a directory XML in your just created sitetemplate directory
  • Copy ONET.XML from “12\TEMPLATE\SiteTemplates\sts\xml” to “\12\TEMPLATE\SiteTemplates\YOURTEMPLATE\XML”
  • Your site template will work now, nothing is changed though

Step 2: Create a master page and place it in “\12\TEMPLATE\SiteTemplates\YOURTEMPLATE\”

  • Find the node in ONET.XML
  • Place a new module in de the Modules tag under configuration “
  • under the main node find and add:

     
  • Your master page will now be provisioned
  • To use it with all your provisioned pages find the Configuration ID=”0″  again and add the tag MasterUrl, like this: “

Step 3: Create site layout pages to provision and place them in “\12\TEMPLATE\SiteTemplates\YOURTEMPLATE\”

  • Find the node in ONET.XML
  • Place a new module in de the Modules tag under configuration “
  • under the main node find and add:

         
         
           
                                 http://schemas.microsoft.com/WebPart/v2″>
                            Microsoft.SharePoint, Version=12.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c
                            Microsoft.SharePoint.WebPartPages.ContentEditorWebPart
                            None
                                  None
                           
                      

                       ]]>
           

         
  • You now will have 2 pages under http://yoursite/Sitepages based upon you own site layout pages defined in the Url propertie. This code will add a content editor webpart to your pages.

Step 4: Provision the new Default.aspx based on your own page layout

  • Find the node in ONET.XML
  • Place a new module in de the Modules tag under configuration “
  • under the main node find and add:

         
           
                                 http://schemas.microsoft.com/WebPart/v2″>
                            Microsoft.SharePoint, Version=12.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c
                           Microsoft.SharePoint.WebPartPages.ContentEditorWebPart
                            None
                                  None
                           
                      

                       ]]>
           

        
Categories: Uncategorized Tags: ,

Custom Master Pages and Site Definitions in WSSv3

May 15th, 2008 No comments
After playing with features to provision a site to SharePoint i came across a few problems (like provisioning default.aspx) and a few problems which are solvable with features but feel like a hack. I decided to look at “site definitions” and it works like a charm. So i would recommend using a site definition when you are creating a site from scratch. The definition is focused in one big XML file (ONET.XML).
 
These blog posts helped me create my site definition:
 
 
You can drop the created definition into a Visual studio solution and create a SharePoint WSP file to install at the server. You can use wspbuilder to create a WSP from from a solution.
 
Categories: Uncategorized Tags: ,

WSS v3 Master Page Selector Feature

April 29th, 2008 No comments
Those involved with SharePoint 2007 have no doubt by now noticed that MOSS 2007 allows you to select a master page via the browser while standard WSS v3 installations do not.
 
Not to worry though, an feature which gives you the ability to change the master page in WSS v3 is available. 
 
 
Categories: Uncategorized Tags: ,

LINQ to extract object permission from SSAS

April 21st, 2008 No comments
Another great example of LINQ to help us in day to day problems, Marco Russo made a LINQ script to extract object permission from SSAS into XML by using LINQ and XML Literals in Visual Basic.
 
 

Back to work, a silverlight holiday photo slide show

April 21st, 2008 No comments
After a 3 week holiday to Mexico, Guatamala, Honduras and Belize it’s back to work, with tons of blog posts and mails to read.
 
To show my photos in a nice resolution i decided to make  a holiday photo slide show in Silverlight based on Slide.Show from codeplex.
 
See the result here (comments in dutch):
Categories: Uncategorized Tags: ,

Static Classes in Javascript

March 26th, 2008 No comments
With the rise of AJAX and Google Api’s javascript is hot again, with the new scriptmanager of ASP.NET it is very easy to integrate javascript with server side code.
 
Today I encountered a Static Function in javascript, my collegues and i were unsure how to use this. It is pretty easy once you know it. The code is as below:
 
/**
 * Static class for handling test creation.
 * @class
 */                    
function testClass()
{
}
 
/*Static function*/
testClass.getInfo= function (){
  return 1;
}
 
You can call it in code:
var value = testClass.getInfo();
 
 
Categories: Uncategorized Tags: ,

How to pass initialization params to a Silverlight 2 app

March 17th, 2008 No comments
Last week i tried to pass some parameters to my Silverlight app when embedding it to my page. After some extended searching last week and not finding it i decided to try again today, i found it at a MS  blog:
 
In short:
Declare the initParams param on the Silverlight plug-in and pass in a comma-delimited set of key-value pair tokens. For e.g. “key1=value1,key2=value2,key3=value3″.
 
Use the function Application_Startup in App.xaml.cs to call:
string key1= e.InitParams["key1"];
string key2= e.InitParams["key2"];
 
You see, pretty easy, now pass these parameters along to the Page constructor so you can use it in the page.
 
Categories: Uncategorized Tags: ,