Deploy a ASP.NET HttpHandler in SharePoint

I want to change the value of a user field in a item. Unfortunately it isn’t possible to change a User Field with JavaScript so I had to find another way. It isn’t the easiest way to implement but you’ll see it’s fexibeler to use than a JavaScript file.
You’ll need two files: CustomHandler.ashx & CustomHandler.ashx.cs
STEP 1: Add SharePoint “Layouts” mapped folder
Add in the layouts folder of your SharePoint project these two files.
image
STEP 2: CustomHandler.ashx
image
There are other ways to implement the webhandler but found that using the absolute assembly name never gave me an error.
STEP 3: CustomHandler.ashx.cs
Make sure your class inherits from IHttpHandler and implement it methods IsReusable and ProcessRequest.
image
I want to change a field of an item so I passed along some parameters in the URL.
image
Now that my fields have been updated I want to redirect ‘cause this page doesn’t contain or anything.
The redirect will give you a Redirect Error of some kind. Just catch it and continue because the redirect will still happen even with the error. Strange isn’t.
image
STEP 4: Link to .ashx
I made a custom action on the Edit Control Block of the item to link to my Custom HttpHandler.
image

Reacties

Populaire posts