[Last Call] Learn about multicloud storage options and how to improve your company's cloud strategy. Register Now

x
?
Solved

SharePoint and httpHandler for specific file extension

Posted on 2010-11-22
1
Medium Priority
?
1,323 Views
Last Modified: 2012-05-10
Hi
I would like to add to SharePoint a httpHandler for specific file extension.
For example for the file extension ".pdf", in case pdf document was opened from my SharePoint site, I would like to show "Hello PDF" in the browser, otherwise (for other documents) I would like to have the regular behavior.
I need help to understand how to implement that.
anyone ?
Thanks...
0
Comment
Question by:netformx
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
1 Comment
 
LVL 1

Accepted Solution

by:
kahkshan earned 2000 total points
ID: 34308670
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");    
}

Open in new window


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.

Hope that helps...
0

Featured Post

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

For SharePoint sites, particularly public-facing ones, there are times when adding JavaScript, Meta Tags, CSS Styles or other content to the page <head> section is more practical than modifying master pages.  For instance, you could add the jQuery l…
A while back, I ran into a situation where I was trying to use the calculated columns feature in SharePoint 2013 to do some simple math using values in two lists. Between certain data types not being accessible, and also with trying to make a one to…
In this video you will find out how to export Office 365 mailboxes using the built in eDiscovery tool. Bear in mind that although this method might be useful in some cases, using PST files as Office 365 backup is troublesome in a long run (more on t…
Are you ready to place your question in front of subject-matter experts for more timely responses? With the release of Priority Question, Premium Members, Team Accounts and Qualified Experts can now identify the emergent level of their issue, signal…

650 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question