Archive

Archive for the ‘MOSS 2007’ Category

SPFeatureDependencyCollection

August 7th, 2007 No comments

You can programmatically find all activated features that are dependent on a specific feature by using the following example. In this example, feature is stopped from being deactivated because dependant features are still in active mode.

using System;
using System.Collections.Generic;
using System.Text;
using Microsoft.SharePoint;
using Microsoft.SharePoint.Administration;
using System.Collections;
using System.Diagnostics;

namespace Configuration
{
public class Configurator : SPFeatureReceiver
{
public override void FeatureInstalled(SPFeatureReceiverProperties properties) {}
public override void FeatureUninstalling(SPFeatureReceiverProperties properties) {}
public override void FeatureActivated(SPFeatureReceiverProperties properties) {}
public override void FeatureDeactivating(SPFeatureReceiverProperties properties)
{
        SPSite site = properties.Feature.Parent as SPSite;
        SPFeatureCollection spfeatCol = site.Features;
        //iterate through all the features of the current site collection
       foreach (SPFeature feature in spfeatCol)
          {

          // Get the collection of all features that are dependent on this feature
         SPFeatureDependencyCollection depCollection = feature.Definition.ActivationDependencies;
         foreach (SPFeatureDependency featureDependency in depCollection)
                {
                if (featureDependency.FeatureId.Equals(properties.Feature.DefinitionId) && feature.Definition.Status.Equals(SPObjectStatus.Online))
                        {
                         throw new Exception(“Deactivation aborted! There is at least one dependant feature in active mode.”);
                         }
                 }
           }

// Do the rest of the work here.

}
}
}

Categories: MOSS 2007 Tags:

non CLS-compliant classes in SDK, what that means?

July 30th, 2007 No comments

When you browse SharePoint SDK , you come across some classes such as ContentByQueryWebPart which is marked as non CLS-compliant classes. This class or any derived type may not be interoperable with a wide range of .Net supported programming languages.Something that you really need to consider when using this calss or driving your custom types off of it. Generally, C# complier does not check for CLS compliance of your code and you have to explicitly instruct it to do so.

This class for whatever reason is not decorated to be CLS-compliant and it should be used with extra caution in regards to interoperability.

[CLSCompliant(false)]
public class ContentByQueryWebPart : CmsDataFormWebPart
{
…..
}

Categories: MOSS 2007 Tags:

External Hard Drives and SharePoint

July 30th, 2007 No comments

I have used both types of external drives (USB2 and 1394 connections) for my SharePoint images and the USB2 drives always perform better than firewire drives
for me. 1394 drives sometimes give me headaches after restart and I basically have to unplug and plug it back in ,so keep this in mind as the first tip.

SharePoint is a resource intensive product and on the top of that a virtualized SQL server adds too much overhead so you can never expect
the same performance and transfer rate you get with IDE/SCSI.None of the existing external hard drives are meant to give you such a performance.

If you are performing backups as well then consider getting two drives, one dedicated to your sharepoint images and the other one for storing your backups.
I will never store backups side-by-side my images.A large external hard drive ( 250GB or greater) is necessary.

Remember, Most of external hard drives come pre-formatted so always check to see what file format is used at first place before you start creating your demo or non-demo images.
By creating a VHDs on FAT32 ,Virtual PC splits it to multiple files which may not be what you want so you have to take extra steps to merge them all.

At the end and for Vista Users in particular, always make sure that the external hard drive you are about to purchase has no compatibility issue with your OS.
I know some people who had problem hooking up their Western Digital 500 GB External HD and they are still stuck!

Categories: MOSS 2007 Tags:

Role-based security model in WSS 3.0 – Part1

March 12th, 2007 1 comment

Title: The Basics

 

WSS 3.0 security management is completely a role-based model. Unlike in WSS 2.0, in WSS 3.0 user permissions are never managed directly using rights (SPRights,SPRoleCollection are all deprecated in the new version). All user and group permissions are managed through roles.

 

A role in WSS 3.0 can be discussed in two parts:

 

1) Role Definition (a.k.a. Permission Level): A role definition is basically a collection of rights bound to a specific user or group. Examples of role definitions are “Full Control”, “Read”, “Contribute”, “Design”, or “Limited Access”. You can also create your own custom role definition as long as your site is using a Unique Role Definitions and not inheriting them from its parent site(site.HasUniqueRoleDefinitions==true). In most cases role definitions that come with SharePoint, OOTB , are more than enough, so the best way would be to create the permission level at the top level and not break the inheritance,  but if you ever need to create your own here is how to do it:

 

SPWeb site = SPContext.Current.Site.AllWebs[“Site_Name/Subsite_Name”];
if (!site.HasUniqueRoleDefinitions)
{
site.RoleDefinitions.BreakInheritance(true, true); // in order to define custom role definition site must have unique role definitions
}
SPRoleDefinition roleDefinition = new SPRoleDefinition();
roleDefinition.Name = “My Custom Role Def”;
roleDefinition.Description = “A role definition with all rights except ManagePermissions”;
roleDefinition.BasePermissions = SPBasePermissions.FullMask ^ SPBasePermissions.ManagePermissions;
site.RoleDefinitions.Add(roleDefinition);

 

There are couple of things to remember:

 

 

  1. Since a role definition is scoped to the web site (SPWeb) , it has the same meaning everywhere within the Web site, but their meanings can be different from one site to another site within the same site collection and that’s the beauty of this flexible model!
  2. Breaking role definition inheritance also breaks role assignment inheritance, which results in unique permissions.
  3. The entire role definition collection is read-only for a Web site that inherits role definitions. Any attempt to add or modify the role definitions fails unless the HasUniqueRoleDefinitions property contains true, which can only be changed by calling the role inheritance methods.
  4. SPRoleDefinitionCollection represents all the permission levels exist in a site:

 

SPRoleDefinitionCollection roleDefinitions = newweb.RoleDefinitions;

 

2) Role Assignment: The role assignment is the only way to relate a role definition to  the users and groups in WSS 3.0. If you don’t need to come up with your own custom role definition , SPRoleAssignment Class is where you spend most of your time when working with roles in WSS 3.0.

 

SPWeb site = SPContext.Current.Site.AllWebs[“Site_Name/Subsite_Name”];
if (!site.HasUniqueRoleAssignments)
{
site.BreakRoleInheritance(false);
}
SPRoleDefinitionCollection roleDefinitions = site.RoleDefinitions;
SPRoleAssignmentCollection roleAssignments = site.RoleAssignments;
SPRoleAssignment roleAssignment = new SPRoleAssignment(“mydomain\rezaa”,”reza@mydomain,com”,”Reza Alirezaei”,”here is the note”);
SPRoleDefinitionBindingCollection roleDefBindings = roleAssignment.RoleDefinitionBindings;
roleDefBindings.Add(roleDefinitions[“Role_Definition_Name_For Example: Full Control”]);
roleAssignments.Add(roleAssignment);

 

There are couple of things to remember:

 

 

  1. site.BreakRoleInheritance(false); only breaks RoleAssignments and has nothing to do with permission levels (Role definitions)
  2. SPRoleAssignment has another constructor which accepts an object of type SPPricipal. It comes in handy if you want to assign a SPGroup instead of a user to a role defintion. Remeber that SPGroup is derived from SPPrincipal  and can be implicitly casted to this type:

 

SPRoleAssignment roleAssignment = new SPRoleAssignment(site.AssociatedMemberGroup); //AssociatedMemberGroup returns an object of type SPGroup

 

2.  SPRoleAssignmentCollection represents all the relationships between users and groups and role definitions.

 

SPRoleAssignmentCollection roleAssignments = newweb.RoleAssignments;

 

In next part (Part 2), I am going to show you how to programmatically create subsites with unique role assignments


Categories: MOSS 2007 Tags:

Central Administration – 2 important tips:

March 2nd, 2007 No comments

Application Pool Isolation: If the same account is used in the application pool for one of your web applications and central administration, this means that your farm configuration (config DB) is editable by all users and trusted code that is registered in sites in the web application. If you can trust your developers, this is not going to be a problem, otherwise this can lead to malicious code injection and loss of your config DB in a worst case scenario.

 

 

Highly Available Central Administration Capability: If you have Only one instance of the SharePoint 3.0 Central Administration in your farm installation, you better make sure that you can administer the farm in case of a failure of a server hosting SharePoint 3.0 Central Administration. Best practices recommend that you should have SharePoint 3.0 Central Administration installed on at least two servers in your farm.

 


Categories: MOSS 2007 Tags: