Writing HttpHandler for SharePoint

I am assuming that you already have WSS/MOSS installed on your system and you are using Visual Studio 2008.

1. Download and install VSeWSS (Visual Studio Extensions for WSS)
http://www.microsoft.com/downloads/en/details.aspx?FamilyID=B2C0B628-5CAB-48C1-8CAE-C34C1CCBDC0A&displaylang=en

2. Create new project and select SharePoint group on the left. Then select Empty from the templates (make sure SharePoint group of template is selected). Name the project "MyTest". (that means, this is also going be your assembly name). Select "Partial Trust" when it asks.

3. Add new class, say "MyNewHandler".

4. Inherit the new class from "System.Web.IHttpHandler".

5. Right click on the "System.Web.IHttpHandler" and click "Implement".

6. Modify your code to look like the following:

public bool IsReusable
{
get { return false; }
}

public void ProcessRequest(HttpContext context)
{
context.Response.Write("test pdf");    
}

7. Right click your project and select "Deploy". (If you have trouble deploying it, see following post:

http://tahiridrees.blogspot.com/2010/12/vsewss-http-request-is-unauthorized.html)


(If it gives error "VSeWSS Service Error: No SharePoint Site exists at the specified URL" then in VS, go to Project Properties and select "Debug" tab and enter your sharepoint site URL where it should deploy)


NOTE: The Deploy will copy your dll in the bin folder of the sharepoint application.

8. Now open your sharepoint site's Web.Config file. Your site would be in the "C:\Inetpub\wwwroot\wss\VirtualDirectories" folder and Web.Config should be within it. Open it in Visual Studio.

9. Look for <httpHandlers> section and add your handler in there like this:

<add verb="*" path="*.ext" type="MyTest.MyNewHandler, MyTest"/>

10. Access your sharepoint site and write "http://yourspsite/testingextension.ext"

Note that the "ext" is the extension you entered while registering the handler in the sharepoint web app in step 9.

Comments

Popular posts from this blog

Unable to delete Shared Services Provider in SharePoint (MOSS)

The server was unable to process the request due to an internal error. For more information about the error, either turn on IncludeExceptionDetailInFaults (either from ServiceBehaviorAttribute or from the configuration behavior) on the server in order to send the exception information back to the client, or turn on tracing as per the Microsoft .NET Framework 3.0 SDK documentation and inspect the server trace logs.

Cannot add a SimpleContent column to a table containing element columns or nested relations