Thursday, September 3, 2009

PDF Icon not showing UP in MOSS

Purpose

Out of the box SharePoint will index many types of content. This includes a lot of popular file formats (.ppt, .docx, .doc, .xlsx, .xls, etc...). A list of these file types can be found here. You'll notice that a pretty popular file type (.pdf) is NOT in this list. For the SharePoint search to be able to index .pdfs you need to install a PDF IFilter (Index Filter) that will help the indexing service process PDF files and when building a search index. There are a couple PDF IFilters available from a series of different vendors, but the most popular is probably the one from Adobe. You can download the Adobe PDF IFilter here.

Walkthrough

Stop the IIS Admin Service: Start->Run->Services.msc->Locate the IIS Admin Service and stop it.Download the Adobe PDF IFilter and install it on your indexing server.Install this GIF () or any icon of your choosing to "C:\Program Files\Common Files\Microsoft Shared\web server extensions\12\TEMPLATE\IMAGES"Edit the DocIcon.xml file at "C:\Program Files\Common Files\Microsoft Shared\Web server extensions\12\Template\Xml\DOCICON.XML" and add the following text under the tag.

Recycle the application pool of the Shared Service Provider OR do an IISRESET if you're lazy.Open the SSP Admin site (Central Administration->SharedServices1). Click on Search Settings->File Types->New File Type) and add a pdf file type.

Perform a full crawl on content sources. Search Settings->Content Sources and Crawl Schedules, click on the Content Source you want to perform a full crawl on. Check the Start Full Crawl check box at the bottom and then click OK. Wait for the crawl to finish.You're done! PDF content should start showing up in searches now!

Troubleshooting

There's been a couple of machines I've done this one where I've had to manually register the PDF IFilter dll (regsvr32 "C:\Program Files\Adobe\PDF IFilter 6.0\PDFFILT.dll") and then recycle the SSP site before the icon would show up. Usually in these cases I also had to do another full crawl after manually registering the PDFFILT.dll. It's probably a good idea to define a new content source with a small set of content (a couple of small pdfs in a document library).

How to Write Custom Webparts in Sharepoint 2007

In this blogpost, we will see how to write the simplest possible Sharepoint 2007 WebPart and deploy it. Just for fun, we will inherit from the sharepoint webpart instead of the asp.net webpart.
Begin by creating a class library project, add references to System.Web, Microsoft.Sharepoint.dll (again only because this blogpost talks about Sharepoint Webpart).
Then add a class as below, which as you can tell is a hella simple WebPart.


using System;
using System.Collections.Generic;
using System.Text;
using System.Xml.Serialization;
using System.Web;
using System.Web.Security;
using System.Security;
using System.Security.Permissions;

using Microsoft.SharePoint;
using Microsoft.SharePoint.Security;
using Microsoft.SharePoint.WebPartPages;

namespace Sahil.Sharepoint.WebPartPages
{
[System.Xml.Serialization.XmlRoot(Namespace =
"http://blah.winsmarts.com/demospace")] public class CustomWebPart : WebPart
{
private string toDisplayText = "Default Text";
[WebPartStorage(Storage.Shared), System.Xml.Serialization.XmlElement(Namespace =
"http://blah.winsmarts.com/demospace")] public string ToDisplayText { get { return toDisplayText; } set { toDisplayText = value; } }
protected override void RenderWebPart(System.Web.UI.HtmlTextWriter writer)
{
writer.Write(toDisplayText) ;
base.Render(writer);
}
}
}
Great !! Now, strongly name it, Build the dll, and use sn-t or reflector to find the public key token.
Then follow the following steps -
1. Locate the Sharepoint WebSite you wish to deploy this webpart in. This can be done via the IIS Manager under administrative tools. The default ones would be virtual directories that look like GUIDs under C:\INETPUB\WWROOT\WSS\<>. In my case (yours may be different) the dir was - C:\Inetpub\wwwroot\wss\VirtualDirectories\7ee252c4-9e98-4258-a6ae-77e16a287bea\bin
2. Drop the dll in the bin directory in the virtual dir. Important: By dropping the webpart in the bin directory, you are effectively giving it partial trust. If you were writing a plain vanilla ASP.NET 2.0 WebPart, you would need to decorate the Webpart with the AllowPartialTrustedCallersAttribute @ the assembly level. You could also create a new trust policy for your WebPart (recommended), or raise the trust level in the web.config file (default is WSS_Minimal), or you could just drop the Webpart in the GAC; which again requires strong naming.
3. Under the same virtual directory, find the web.config, and add the following to the SafeControls section -

4. Then browse to the WebSite, and go to Site Actions -> Site Settings -> Modify All Site Settings. Under that, click on "Web Parts" under Galleries.
5. Click on "New" in the toolbar, and find the Sahil.Sharepoint.WebPartPages.CustomWebPart as shown below -
6. Check the checkbox, go to the top, click on "Populate Gallery".
That's it. Your WebPart is now ready to eat !! :)
How to use it?
Go to the site of your choice, Edit Page, Click on Add a WebPart, you should see it in the list that pops up.