Archive

Archive for August, 2007

The latest MOSS and WSS SDK release

August 24th, 2007 No comments

There has been a major update to the MOSS and WSS Software Development Kit (SDK) which makes this release an important one.Now there are more samples and articles included and a series of new tools and features are nicely packaged up in the download files.You can install them from the following locations:

MOSS 2007 SDK 1.2:  Includes Conceptual and Class Library Reference documentation, Web Services documentation, and Developer Tools and Samples for MOSS and WSS. http://www.microsoft.com/downloads/details.aspx?FamilyId=6D94E307-67D9-41AC-B2D6-0074D6286FA9&displaylang=en
¼br> WSS 3.0 SDK 1.2:  Includes Conceptual and Class Library Reference documentation, Web Services documentation, and Developer Tools and Samples for WSS technology *only*. http://www.microsoft.com/downloads/details.aspx?familyid=05E0DD12-8394-402B-8936-A07FE8AFAFFD&displaylang=en  

As you can see in the download page there has been a ton of new features added to this release such as follow:

  1. New Start Menu shortcut : A quicker access to documentation and welcome page
  2. You now have a choice of installation location when you’re installing the SDK 
  3. Offline Experience Improvements: More Technical Articles, Visual How-to Articles, and Book Excerpts—plus the Excel Services and Excel 2007 Windows Compute Cluster Server 2003 Job Submission Developer Guide are packaged into one searchable CHM file ( Some of the elements such as WMV files and screencasts are still not available offline)
  4. New Tools and samples: There are many new tools and samples included in this release as follow:
    • Microsoft Business Data Catalog Definition Editor: I am so glad that what I was shouting here  8 months ago finally came into the consideration.Although it is not as complete as BDC Meta Man, I’m sure it is still better than nothing:)
    • WSHelloWorld Web Service
    • Excel Services User Defined Function Sample
    • WSOrders Custom Proxy Sample
    • SAP Sample
    • Sample Protocol Handler
    • Custom Content Source
    • IRM Document Protector
  5. Revised MOSS SDK conceptual topics such as :
    • How to: Create a Minimal Master Page
    • Provisioning Portal Sites
    • Portal Site Template File
    • Portal (Portal Site Template)
    • Webs (Portal Site Template)
    • Web (Portal Site Template)
  6. New MOSS SDK conceptual topics such as :
    • How to: Customize RSS for the Content Query Web Part
    • How to Create a Web Service Connection by using the Business Data Catalog Definition Editor
    • How to Create a Database Connection by using the Business Data Catalog Definition Editor

Here are the links to the online versions:

http://msdn2.microsoft.com/en-us/library/ms550992.aspx

http://msdn2.microsoft.com/en-us/library/ms441339.aspx

Categories: MOSS 2007 Tags:

Landing a site collection in its own content database

August 24th, 2007 No comments

One of the many advantages of having site collections over just sub sites is that you can create a content database for each site collection. One of the obvious advantages is when backing up or restoring different pieces of your farm that makes it easier to deal with multiple content databases rather than just a giant content database. There are many other advantages that I am not going to write about mainly because it’s been fully documented at TechNet site.

Unfortunately, there is no a straight way to tell MOSS where you want your site collections to land when you move them around or create new ones. MOSS uses a round-robin algorithm to distribute them evenly in the existing content databases. However, there is a UI trick (also used in SPS2003) which still can be used in MOSS 2007.A few days ago I was going through the same process for a client and I thought that it is not a bad idea to blog it here.

We were basically moving a site collection from DEV to QA, both environments were 32-bit, same topology and etc. In other words they were identical in many ways.

DEV :

DEV-1) Run stsadm to back up the site collection
stsadm -o backup -url http://mossdev/mysitecollecionDev  -filename c:\mysitecollecionDev.dat

DEV-2) Copy DAT file (mysitecollecionDev.dat) to QA

QA:

QA-1) Choose between QA-1-1 or QA-1-2

QA-1-1) ARE YOU MOVING IT TO AN EXISTING WEB APPLICATION?

       1) Go to content databases in central admin
       2) Choose your web application name from the drop down box
       3) Take all existing content databases offline (status=offline).
          This doesn’t actually take the Site Collections offline, but only prevents any new SiteCollections from being created in these database and that’s exactly what we want.
       4) Go to QA-2

QA-1-2) ARE YOU MOVING IT TO A NEW WEB APPLICATION?

      1) Create a new web application
      2) Go to QA-2

QA-2)Create mysitecollecionQA as an “Explicit Inclusion”  managed path (Central Administration–> Application Management–> Managed Paths)
QA-3)Create a site collection exactly in the same level as it was in DEV. In this example it should be http://mossdev/mysitecollecionQA. Make sure that the name you choose for content database at level is the name you want to keep for ever ,because we are going to overwrite into this content database
 ¼br> QA-4) Run stsadm to restore the datafile you moved earlier

stsadm -o restore -url  http://mossdev/mysitecollecionQA -filename c:\mysitecollecionDev.dat  -overwrite

QA-5) Confirm that your new site collection is created in the only online content DB that you just created and change the status for all the other databases back to online.

Categories: MOSS 2007 Tags:

On-the-fly creation of attachments for list items

August 23rd, 2007 No comments

Here is the code to add an item to a list (task list in this example) programmatically and create and attach a file on the fly. You basically need to encode a set of characters into a sequence of bytes (byte array) and call SPAttachmentCollection.Add method to add the binary representation of your attachment to the list item.

StringBuilder sbLog = new StringBuilder();

sbLog.Append(“Accessing root web of the site collection…\n”);
SPWeb web = new SPSite(“http://moss:21165”).OpenWeb();

sbLog.Append(“Accessing Task list in the root web…\n”);
SPList taskList = web.Lists[“Tasks”];

sbLog.Append(“Adding a new task item…\n”);
SPListItem newTask = taskList.Items.Add();

sbLog.Append(“Populating the fields…\n”);
newTask[“Title”] = “Work hard ,but play harder”;
newTask[“Due Date”] = DateTime.Now;
newTask[“Priority”] = “(1) High”;

sbLog.Append(“Creating the attachment…\n”);
ASCIIEncoding encoder = new ASCIIEncoding();
byte[] bytFile = encoder.GetBytes(sbLog.ToString());
newTask.Attachments.Add(“log.txt”, bytFile);
newTask.Update();

Categories: MOSS 2007 Tags:

Adding and Removing keys from appSettings in web.config

August 12th, 2007 No comments

Today, I was struggling with adding and removing entries from web.config/appsettings in my feature receiver class. Well, it was quite easy to add , but removing was giving me a real hard time. I used my perfect indexing tool and I came across these great posts from Daniel Larson and Tony Bierman. By first look at their posts I realized that removing requires a *right* call to SPWebConfigModification constructor, otherwise it won’t ever happen. Both posts are for adding Ajax http handlers, but one can easily alter them to make the solution work for appsettings as well.

protected void ModifyWebApplication(SPWebApplication app, bool removeModification)
{

SPWebConfigModification modification = new SPWebConfigModification(“add[@key=’TotalDigits’]”, “configuration/appSettings”);
modification.Type = SPWebConfigModification.SPWebConfigModificationType.EnsureChildNode ;
modification.Value = “<add key=\”TotalDigits\” value=\”21\” />”;
modification.Sequence = 0;
if (removeModification)
app.WebConfigModifications.Remove(modification);
else
app.WebConfigModifications.Add(modification);
SPFarm.Local.Services.GetValue().ApplyWebConfigModifications();

}

As Daniel has mentioned in his comments, a real benefit of using the SPWebApplication in your code is that the changes are applied to the farm, since the SPWebApplication represents that virtual web application that lives in the farm context.Thanks Daniel and Tony!

Categories: MOSS 2007 Tags:

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: