Subscribe to my blog – Feedburner

30 01 2009

I’m now signed up for feedburner so you can subscribe to my blog feeds – http://feeds2.feedburner.com/AlexsSharepointBlog.

I’m going to add a widget to the page that you can click too…

🙂

Advertisements




Easiest way to install a WSP

30 01 2009

I thought I should post a link to Spencer Harbar’s brilliant registry hack to allow you to right click any .wsp to add the solution to SharePoint – no more command line stsadm required!

Copy the registry text contained on his blog post here into a .REG file and execute – http://www.harbar.net/archive/2007/04/25/Rightclick-a-.WSP-to-Add-Solution.aspx 

You can now just right click the .wsp and your away, personally I think this is one of the easiest methods and saves a lot of time.

🙂





SharePoint ULS Logs – ‘Tracing Service Lost Trace Events’

30 01 2009

It turns out the above error has been affecting a few people after upgrading to SP1 of MOSS/WSS, it can be fixed by restarting a few of the SharePoint/WSS services (see below) however the problem does come back after a while which can be irritating if you need to see the logs for a specific period.

I cannot see anywhere that this bug/issue has been reported to Microsoft so I’ll probably register it on the connect site if I can, I will post back here with the link – if you have the same problem could you put a comment on the connect site too please then we can get this issue noticed at MS.

EDIT: I have raised the issue as feedback on the MS Connect site, see here – https://connect.microsoft.com/feedback/ViewFeedback.aspx?FeedbackID=408671&SiteID=428 please leave a comment if you have the same problem.

To fix the error and start the logging again, simply restart the ‘Windows SharePoint Services Tracing’ service. Once this has been restarted you will notice the logs start again! 🙂

Maybe I will write a script to detect when it stops logging and restart the service…ill keep you all posted!

Cheers





Removing Event Handlers in the Feature Deactivated

30 01 2009

If you use a featurereciever to install your event handler when you activate or install your feature then you can also uninstall/remove the event handler from the list/lists when the feature is either uninstalled or deactivated.

The code for removing the event handler is slightly more complex than adding the event handler and involves looping through the event receivers on the list and removing the one that matches the assembly name which you pass in.

Code:

//Open the parent site and web

            using (SPSite site = (SPSite)properties.Feature.Parent)
            {
                using (SPWeb web = site.OpenWeb())
                {
                    //Grab the required lists

                    SPList TheList = web.Lists[“Shared Documents”];

                    //Declare the full assembly name

                    String AssemblyName = “SharedDocumentsHandler, Version=1.0.0.0, Culture=neutral, PublicKeyToken=928f76143tc8cbd2”;

                    //Create a new integer

                    int i;

                    //Use the above integer to loop through the event recievers on the first list and delete the above assembly

                    for (i = 0; i < TheList.EventReceivers.Count; i++)
                    {
                        if (TheList.EventReceivers[i].Assembly.Equals(AssemblyName))

                            TheList.EventReceivers[i].Delete();

                    }

                    //Update the list

                    TheList.Update();

//Update the SharePoint web

                    web.Update();

}

}

You can do the above for the FeatureDeactivating or FeatureUninstalling methods :-).





Prerequisites for a WSS 3.0 Installation

27 01 2009

I’m rebuilding a server and reinstalling WSS this morning, so I thought I post up a list of prerequisites required for a WSS installation. This should be a pretty helpful reference/checklist for a first time WSS install:

1.Windows Server 2003/Server 2008 OS Installed

2.IIS with ASP.NET support installed through Add/Remove Windows Components

3.Net Framework 2.0 (http://www.microsoft.com/downloads/details.aspx?familyid=0856eacb-4362-4b0d-8edd-aab15c5e04f5&displaylang=en)

4.Net Framework 3.0 containing Windows Workflow Foundation (http://www.microsoft.com/downloads/details.aspx?familyid=10cc340b-f857-4a14-83f5-25634c3bf043&displaylang=en)

5.ASP.NET v2.0 should be set to ‘Allow’ in the list of IIS web server extensions

6.SQL Server 2005 installed and configured (If you do not wish to use SQL Express which comes with the WSS install by default)

And your ready to go! 🙂





Exporting/Importing SharePoint/WSS Subsites

27 01 2009

I needed to export a subsite this morning from a WSS Site Collection and import it to another Site Collection on another server. After a bit of rooting around, I found the stsadm commands to do just that.

If you wish to export a subsite or site collection (this will save a bak file containing the exported contents):

stsadm –o export –url http://server1:1000/subsite –filename c:\Subsite.bak

To import this exported site into another site collection/subsite, use the following command:

stsadm –o import –url http://server2:1001/subsite –filename c:\Subsaite.bak

In addition to the above you can add the following switches:

-includeusersecurity (ensures all the columns e.g. Modified by are maintained

-versions 4 (ensures all versions of list items/documents are exported

Note:

Make sure that the site you wish to import to shares the same template. E.g. if you are exporting a team site, you must import to another team site. If you try to import a site to a non matching template then you will get an error:

“The exported site is based on the template STS#1 but the destination site is based on the template STS#0”





No RunWithElevatedPriviliges in Event Handlers

23 01 2009

I’ve just been working on a simple event handler to restrict users from deleting documents unless they are in a particular SharePoint group. This required me to access the SPWeb.Users function to iterate through the users.

If the user was not an administrator on the SharePoint site the code bombed out as the user doesn’t have permission to access the list of users on the site, this is happening because an event handler runs under the user who is performing the operation.

I decided to use the RunWithElevatedPriviliges to impersonate the Application Pool but this didn’t work either and as it turns out you cannot use ‘RunWithElevatedPriviliges’ in SharePoint event handlers!

In Trailblazer’s blog post –

http://blogs.msdn.com/varun_malhotra/archive/2008/07/21/why-does-runwithelevatedpriviliges-not-work-in-event-handlers.aspx

he describes how you cannot use this method of impersonation nor the standard Windows.Impersonate() function in event handlers. The only workaround is to use Explicit Impersonation.

Explicit impersonation means creating an SPUser object for the administrator, getting the SPToken of the user and then using this token to open the SPSite.

See the code example below:

SPUser user = web.AllUsers["kci\\sp_prodapppool"];

SPUserToken token = user.UserToken;

SPSite kciSite = new SPSite(site.Url, token);

SPWeb kciWeb = kciSite.OpenWeb();

Have fun coding! 🙂