Posts

Showing posts from February, 2008

Commands to Deactivate, Uninstall, Install and Activate Features in SharePoint (MOSS)

I created a batch file that every time I have to update my particular feature, it eases the job. One can create such file to speed up the development process: My Installfeature.bat contents look like this: set folderpath = "C:\Program Files\Common Files\Microsoft Shared\web server extensions\12\" %folderpath%BIN\stsadm -o deactivatefeature -name MyProject -url http://test.mysharepintsite.com %folderpath%BIN\stsadm -o uninstallfeature -name MyProject %folderpath%BIN\stsadm -o installfeature -name MyProject %folderpath%BIN\stsadm -o activatefeature -name MyProject -url http://test.mysharepintsite.com iisapp.vbs /a "DefaultAppPool" /r

SharePoint (MOSS) Event Handlers using Content Type Deployed as Features

In my post earlier, I wrote how to create event handlers which get associated with all the lists/document libraries of specific types. You can change the elements.xml file as follows to create and register event handlers against it. Later you can associate the content type with any document library for example, to associate the event handler only to that particular library. Elements.xml file contents would look like this: <Elements xmlns="http://schemas.microsoft.com/sharepoint/"> <ContentType ID="0x010100B6507616196543198ED529CE8720311F" Name="MyContentType" Group="MyGroupForContentType" Description="Event handler enabled content type." Version="0"> <XmlDocuments> <XmlDocument NamespaceURI="http://schemas.microsoft.com/sharepoint/events"> <spe:Receivers xmlns:spe="http://schemas.microsoft.com/sharepoint/events"> <Receiver> <Name

Postbuild technique to perform various operations including adding assembly in Global Assembly Cache

Using the command line options for "Post-Build" events you can execute any type of DOS commands which could perform different operations. Create/Open a project in Microsoft Visual Studio. Add a new file "PostBuild.bat". Add following commands in it In Project Properties, go to Build Events. In "Post-build Event Command Line" add following command to execute your file which is: "$(ProjectDir)"postbuild.bat Postbuild.bat contents can be: rem -- set environment specific variables set projPath=C:\MyProject set pdbFilePath=d:\MyProject\bin\debug\Edwards.Moss.Web.Common.pdb set appPoolName="DefaultAppPool"   rem -- copy assembly and debug database "C:\Program Files\Microsoft Visual Studio 8\SDK\v2.0\Bin\gacutil.exe" /i %projPath%\bin\Debug\MyProject.dll /f copy %projPath%\bin\Debug\MyProject.pdb "C:\WINDOWS\assembly\GAC_MSIL\MyProject\1.0.0.0__g530125dghad5ac3\MyProject.pdb" iisapp.vbs /a %appPoolName% /r

Adding Event Handlers for all Lists in SharePoint Using Features in WSS 3.0

To add event handler to all document libraries in the site: Create a Class Library project "EventHandlerProject" in Microsoft Visual Studio 2005. Add a class named "EventHandler". Inherit this class from "SPItemEventReceiver". Override the ItemDeleting method as follows: public override void ItemDeleting(SPItemEventProperties properties) { base.ItemDeleting(properties); properties.Cancel = true; properties.ErrorMessage = "It should work now. its already too late"; } Compile the above project and add the assembly in cache. Create an elements.xml file and put the fillowing xml in it. <elements xmlns="http://schemas.microsoft.com/sharepoint/"> <receivers listtemplateid="101"> <receiver> <name>ItemDeleting</name> <type>ItemDeleting</type> <sequencenumber>400</sequencenumber> <assembly>EventHandlerProject, Version=1.0.0.0, Culture=neutral, PublicKeyToken=a1901tr121134ect&l

Writing and Using HttpModule

You can create and use HttpModule in both existing and new projects. Here I am going to create it in new project. Open VS2005 and create a class library project. Add a new class called MyModule. Add following code in it. namespace MyNamespace { public class MyModule : IHttpModule { public MyModule() { } /// /// Required by the interface IHttpModule /// public void Dispose() { } /// /// Required by the interface IHttpModule /// I also wire up the Begin Request event. /// public void Init(System.Web.HttpApplication Appl) { Appl.PreRequestHandlerExecute += new EventHandler(OnPreRequestHandlerExecute); Appl.BeginRequest += new System.EventHandler(OnBeginRequest); } public void OnPreRequestHandlerExecute(object sender, EventArgs e) { HttpApplication app = (HttpApplication)sender; app.Response.Write("Instances of underlying objects have also been created."); //can do your operations here. } public void OnBeginRequest(object sender, EventArgs e) { HttpApplication app = (HttpApplicat