Today I got the question from a collegue if it was possible to instantiate a class, based on a result from a computation, without making use of an if-then-else, case or any other (logical) construction.
We found the answer in using reflection and attributes.
first of all, we created a class "ClassType":
After that, we created some classes, with each its own attribute:
after that, the attributes of a class in a certain assembly can be read (a little bit of pseudo code ;)
donderdag 17 april 2008
dinsdag 1 april 2008
Import user accounts
As you were able to read in my post before, I had a problem with disabled users. I decided that i didnt want any disabled users in my shared service provider, but how could i manage that? Luckily, there is a Microsoft KB article which helped me with not importing disabled accounts. By making smart use of the ADSearch, only enabled accounts are retrieved:
Adding users to a site
Today I was busy on migrating some data using the Tzunami tool, until I got the following error:
SPS2003HandlerException: Principal 'xxx\xxx' cannot be resolved. I was sure about it that the user existed in the SSP and but to be sure, I checked it a second time. And yes: it existed. So i tried to add that user manually to a site, but the user couldnt be added. I stumbled on that problem for about an hour, until i accidentally checked something in the AD:

Account disabled... SIGH!
SPS2003HandlerException: Principal 'xxx\xxx' cannot be resolved. I was sure about it that the user existed in the SSP and but to be sure, I checked it a second time. And yes: it existed. So i tried to add that user manually to a site, but the user couldnt be added. I stumbled on that problem for about an hour, until i accidentally checked something in the AD:
Account disabled... SIGH!
vrijdag 28 maart 2008
iterating through user profiles
Today i was busy on migrating some userprofiles and for some reason i had to iterate through the existing userprofiles in the MOSS 2007 environment.
I got a nice, lovely errormessage saying that I wasn't allowed to enumerate through all userprofiles, because i didnt have the rights to "Manage user profiles".
Dave Hunter's Blog (http://www.davehunter.co.uk/Blog/default.aspx) provided me the solution:
iterate through a set number!
I got a nice, lovely errormessage saying that I wasn't allowed to enumerate through all userprofiles, because i didnt have the rights to "Manage user profiles".
Dave Hunter's Blog (http://www.davehunter.co.uk/Blog/default.aspx) provided me the solution:
iterate through a set number!
woensdag 19 maart 2008
Feature stapling - custom code OnSiteCreation
I wanted to enable some features upon a siteCollection creation, but i couldnt find an eventhandler which I could use to run some code in to activate those features. I found out that sharepoint is missing a OnSiteCreation event :(. After some search on the web, I found out some possibilities:
1) alter the SiteTemplates
This was no option for me: too much work for a lazy person like me
2) feature stapling
This was a technique I never heard of: A new, farm wide feature is created, with a
reference to a stapling.xml. That file is filled with:
* elements
* FeatureSiteTemplateAssociation Id: the feature that needs to be installed
* TemplateName
This way, features can be activated to some siteDefinitions (for example STS#1, BLANKINTERNET#0) or to the GLOBAL definition!
When making a custom feature with a OnFeatureActivated method, and that feature is deployed to GLOBAL, code can be executed ON SITE CREATION!
NOTE: the STS#1 (blank page) has a setting "AllowGlobalFeatureAssociations" set to false. This way, the STS#1 sitedefinition needs to be added to, when you want to execute custom code to be executed when any site is created.
1) alter the SiteTemplates
This was no option for me: too much work for a lazy person like me
2) feature stapling
This was a technique I never heard of: A new, farm wide feature is created, with a
reference to a stapling.xml. That file is filled with:
* elements
* FeatureSiteTemplateAssociation Id: the feature that needs to be installed
* TemplateName
This way, features can be activated to some siteDefinitions (for example STS#1, BLANKINTERNET#0) or to the GLOBAL definition!
When making a custom feature with a OnFeatureActivated method, and that feature is deployed to GLOBAL, code can be executed ON SITE CREATION!
NOTE: the STS#1 (blank page) has a setting "AllowGlobalFeatureAssociations" set to false. This way, the STS#1 sitedefinition needs to be added to, when you want to execute custom code to be executed when any site is created.
Migration - QuickLaunch
It has been a long time ago since i made my last post, but that's because of my current project, there's a lot of pressure on it at the moment.
At the moment i am busy on migrating a SP2003 environment to a SP2007. Due to the customers wishes, this is a very time consuming project. I decided to write a nice tool to help me migrate all the webparts, it's data and the navigation, since we used Tzunami for the content migration. It helped me in some way, but i can say: it isnt worth it's money. 12000 Euro for a product that has a lot of bugs and misses a lot of functionality.
well, let me go further on the main subject ;) I was asked if it was possible to maintain all links in the quicklaunch and in the same order. At first, it didnt look too good for me: The object model of sharepoint 2003 didnt allow me to gather information about the quicklaunch menu.
So I decided to write a query to get the navigation information out of the database and stored into an xml file:
In SP2003, the order of Documents, PictureLibrary, Lists are in an order that is always the samen (when nog changed). In SP2007, the order depends on the order of creating doclibs and lists.
For example, when a list is created first and after that, a doclib is created, the menu "List" will be displayed above "Document Library" (or whatever its name is ;))
This problem is tackled with the following code:
- make all lists and doclibs invisible in the quicklaunchmenu:
afther that,
use this function to add items:
use the following function to add the items to the quicklaunch: they are added to the right subMenu
And use this function to put the subMenu items in the right order:
At the moment i am busy on migrating a SP2003 environment to a SP2007. Due to the customers wishes, this is a very time consuming project. I decided to write a nice tool to help me migrate all the webparts, it's data and the navigation, since we used Tzunami for the content migration. It helped me in some way, but i can say: it isnt worth it's money. 12000 Euro for a product that has a lot of bugs and misses a lot of functionality.
well, let me go further on the main subject ;) I was asked if it was possible to maintain all links in the quicklaunch and in the same order. At first, it didnt look too good for me: The object model of sharepoint 2003 didnt allow me to gather information about the quicklaunch menu.
So I decided to write a query to get the navigation information out of the database and stored into an xml file:
In SP2003, the order of Documents, PictureLibrary, Lists are in an order that is always the samen (when nog changed). In SP2007, the order depends on the order of creating doclibs and lists.
For example, when a list is created first and after that, a doclib is created, the menu "List" will be displayed above "Document Library" (or whatever its name is ;))
This problem is tackled with the following code:
- make all lists and doclibs invisible in the quicklaunchmenu:
afther that,
use this function to add items:
use the following function to add the items to the quicklaunch: they are added to the right subMenu
And use this function to put the subMenu items in the right order:
dinsdag 29 januari 2008
generic feature to install a custom masterpage
During my current job i needed to create a few new visual designs and install them as a masterpage. I searched the internet and found a custom masterpage changer, and used it. But it didnt fullfill my needs. WHen using this solution, i needed to have 7 assemblies for 7 masterpages. I changed the code and the feature.xml a bit to make it more generic. The code isn't too neat, it's more of quickly hacked ;)
How to use it?
Create a new dir with the name of your feature. Put an elements.xml, feature.xml and a dir with the name of your masterpage([name]). put the NewDesign.master, and custom css files (and maybe some other files) into that directory.
FeatureName
|- [Name]
|- Feature.xml
|- Elements.xml
put the ChangeMaster assembly into the GAC.
feature.xml:
<?xml version="1.0" encoding="utf-8" ?>
<Feature xmlns="http://schemas.microsoft.com/sharepoint/"
Id="90969656-A1C9-4f40-A95F-A3BDDF5723BF"
Title="Use Custom Master File"
Scope="Web"
ReceiverAssembly="CustomMaster, Version=1.0.0.0,
Culture=neutral, PublicKeyToken=b2f164534d725b81"
ReceiverClass ="CustomMaster.ChangeMaster"
>
<ElementManifests>
<ElementManifest Location="Elements.xml"/>
</ElementManifests>
<Properties>
<Property Key="VisualDesignName" Value="[Name]" />
</Properties>
</Feature>
elements.xml:
<?xml version="1.0" encoding="utf-8" ?>
<Elements xmlns="http://schemas.microsoft.com/sharepoint/">
<Module Name="AddMasters" Url="_catalogs/MasterPage" >
<File Url="[NAME]/NewDesign.master" Type="GhostableInLibrary"
IgnoreIfAlreadyExists="True"/>
<File Url="[NAME]/custom.master" Type="GhostableInLibrary"
IgnoreIfAlreadyExists="True"/>
<File Url="[NAME]/custom.css" Type="GhostableInLibrary"
IgnoreIfAlreadyExists="True"/>
<File Url="[NAME]/custom_tables.css" Type="GhostableInLibrary"
IgnoreIfAlreadyExists="True"/>
</Module>
</Elements>
using System;
using System.Collections.Generic;
using System.Text;
using Microsoft.SharePoint;
namespace CustomMaster
{
public class ChangeMaster : Microsoft.SharePoint.SPFeatureReceiver
{
public override void FeatureInstalled
(SPFeatureReceiverProperties properties)
{
}
public override void FeatureUninstalling
(SPFeatureReceiverProperties properties)
{
}
public override void FeatureActivated
(SPFeatureReceiverProperties properties)
{
string strKey = "VisualDesignName";
string name = properties.Definition.Properties[strKey].Value;
SPWeb CurrentWeb = properties.Feature.Parent as SPWeb;
string filler = "/";
if (CurrentWeb.ServerRelativeUrl == "/")
{
filler = "";
}
CurrentWeb.MasterUrl = CurrentWeb.ServerRelativeUrl + filler + "_catalogs/masterpage/" + name + "/NewDesign.master";
CurrentWeb.CustomMasterUrl = CurrentWeb.ServerRelativeUrl + filler + "_catalogs/masterpage/" +name + "/custom.master";
CurrentWeb.Update();
}
public override void FeatureDeactivating
(SPFeatureReceiverProperties properties)
{
SPWeb CurrentWeb = properties.Feature.Parent as SPWeb;
string filler = "/";
if (CurrentWeb.ServerRelativeUrl == "/")
{
filler = "";
}
CurrentWeb.MasterUrl = CurrentWeb.ServerRelativeUrl + filler + "_catalogs/masterpage/default.master";
CurrentWeb.CustomMasterUrl = CurrentWeb.ServerRelativeUrl + filler + "_catalogs/masterpage/default.master";
CurrentWeb.Update();
}
}
}
How to use it?
Create a new dir with the name of your feature. Put an elements.xml, feature.xml and a dir with the name of your masterpage([name]). put the NewDesign.master, and custom css files (and maybe some other files) into that directory.
FeatureName
|- [Name]
|- Feature.xml
|- Elements.xml
put the ChangeMaster assembly into the GAC.
feature.xml:
<?xml version="1.0" encoding="utf-8" ?>
<Feature xmlns="http://schemas.microsoft.com/sharepoint/"
Id="90969656-A1C9-4f40-A95F-A3BDDF5723BF"
Title="Use Custom Master File"
Scope="Web"
ReceiverAssembly="CustomMaster, Version=1.0.0.0,
Culture=neutral, PublicKeyToken=b2f164534d725b81"
ReceiverClass ="CustomMaster.ChangeMaster"
>
<ElementManifests>
<ElementManifest Location="Elements.xml"/>
</ElementManifests>
<Properties>
<Property Key="VisualDesignName" Value="[Name]" />
</Properties>
</Feature>
elements.xml:
<?xml version="1.0" encoding="utf-8" ?>
<Elements xmlns="http://schemas.microsoft.com/sharepoint/">
<Module Name="AddMasters" Url="_catalogs/MasterPage" >
<File Url="[NAME]/NewDesign.master" Type="GhostableInLibrary"
IgnoreIfAlreadyExists="True"/>
<File Url="[NAME]/custom.master" Type="GhostableInLibrary"
IgnoreIfAlreadyExists="True"/>
<File Url="[NAME]/custom.css" Type="GhostableInLibrary"
IgnoreIfAlreadyExists="True"/>
<File Url="[NAME]/custom_tables.css" Type="GhostableInLibrary"
IgnoreIfAlreadyExists="True"/>
</Module>
</Elements>
using System;
using System.Collections.Generic;
using System.Text;
using Microsoft.SharePoint;
namespace CustomMaster
{
public class ChangeMaster : Microsoft.SharePoint.SPFeatureReceiver
{
public override void FeatureInstalled
(SPFeatureReceiverProperties properties)
{
}
public override void FeatureUninstalling
(SPFeatureReceiverProperties properties)
{
}
public override void FeatureActivated
(SPFeatureReceiverProperties properties)
{
string strKey = "VisualDesignName";
string name = properties.Definition.Properties[strKey].Value;
SPWeb CurrentWeb = properties.Feature.Parent as SPWeb;
string filler = "/";
if (CurrentWeb.ServerRelativeUrl == "/")
{
filler = "";
}
CurrentWeb.MasterUrl = CurrentWeb.ServerRelativeUrl + filler + "_catalogs/masterpage/" + name + "/NewDesign.master";
CurrentWeb.CustomMasterUrl = CurrentWeb.ServerRelativeUrl + filler + "_catalogs/masterpage/" +name + "/custom.master";
CurrentWeb.Update();
}
public override void FeatureDeactivating
(SPFeatureReceiverProperties properties)
{
SPWeb CurrentWeb = properties.Feature.Parent as SPWeb;
string filler = "/";
if (CurrentWeb.ServerRelativeUrl == "/")
{
filler = "";
}
CurrentWeb.MasterUrl = CurrentWeb.ServerRelativeUrl + filler + "_catalogs/masterpage/default.master";
CurrentWeb.CustomMasterUrl = CurrentWeb.ServerRelativeUrl + filler + "_catalogs/masterpage/default.master";
CurrentWeb.Update();
}
}
}
Abonneren op:
Posts (Atom)