Monday, April 18, 2011

PDF support in SharePoint 2010

SharePoint 2010 does not offer much support for PDF’s out of the box, but you can quickly get this in a few short steps.

Fist there is the missing icon issue. If you upload a PDF to a document library you just get this:

 image

To add support for the PDF icon simply download it from here and place it in your Images directory on the each SharePoint server in your environment. (C:\Program Files\Common Files\Microsoft Shared\Web Server Extensions\14\TEMPLATE\IMAGES)

Once you have the image in place update the DOCICON.xml file here: (C:\Program Files\Common Files\Microsoft Shared\Web Server Extensions\14\TEMPLATE\XML) with the file type and image to use. (<Mapping Key="pdf" Value="pdficon_small.gif" />)

image

After the next IISReset you should have icons for your pdf files.

The second issue with PDF’s out of the box is searching for them. The Search service application does not have PDF as a file type to look for so you will need to add it. To accomplish this open central administration and click on “Manage Service Applications”. Now click “File Types” on the left menu pane.

image

Click “New File Type” and add PDF to the list.

image

Run a full crawl and you should now get PDF’s in your search results.

To enable the PDF iFilter see my previous post here.

Thursday, March 3, 2011

Silverlight SharePoint Web Part using the HTML Bridge

I recently ran across an issue with the HTML Bridge and conflicting behavior between IE and Firefox.

HTML Bridge info: http://msdn.microsoft.com/en-us/library/cc645076(v=VS.95).aspx

I had the following code in Silverlight to set a JavaScript variable to a Silverlight web part instance on a SharePoint page. By creating this variable I was able to call and pass in parameters into the Silverlight control from the JavaScript running on the page.

private static void InitializeReceiverJsVariable()
{
    string pluginId = HtmlPage.Plugin.Id;

    if (string.IsNullOrEmpty(pluginId))
        throw new Exception("No Silverlight Plugin found!  Ensure the Silverlight plugin has an ID!");

    string jsCode = string.Format("var {0} = document.getElementById('{1}').content.{0};", JS_VARIABLE_NAME, pluginId);

    HtmlPage.Window.Eval(jsCode);
}

Note: any Silverlight methods that you want call from JavaScript will need to have the [ScriptableMember] property on them. Alternatively you could create a class to house all your Scriptable methods and add the [ScriptableType] property to the whole class.

After compiling and deploying the web part to SharePoint, testing the JavaScript proved to be a success. Internet Explorer was allowing for communication between the Silverlight web part and the document library. Firefox was not allowing this. After several tests and some trial and error it turned out to be an issue with declaring the JavaScript variable from Silverlight. The solution was to declare the JavaScript variable on the page and just set the value from Silverlight instead of creating the variable too.

JavaScript addition:

var slWebPart = null;

Silverlight change:

private static void InitializeReceiverJsVariable()
{
    string pluginId = HtmlPage.Plugin.Id;

    if (string.IsNullOrEmpty(pluginId))
        throw new Exception("No Silverlight Plugin found!  Ensure the Silverlight plugin has an ID!");

    string jsCode = string.Format("{0} = document.getElementById('{1}').content.{0};", JS_VARIABLE_NAME, pluginId);

    HtmlPage.Window.Eval(jsCode);
}

After the change to the web part it worked in IE, Firefox, and Chrome. I still have not figured the exact issue or why you can’t declare the variable using the HTML Bridge, but the work around solved the problem. If you have come across this or know the technical reason, comments are always welcome.

Friday, February 11, 2011

Rectifying a missing namespace for MSBuild

Today I was working on adding some additional projects to a build and was getting the error:

Error CS0234: The type or namespace name 'Linq' does not exist in the namespace 'System' (are you missing an assembly reference?)

Wait, what, this builds fine in visual studio…

System.Linq is part of System.Core. I did not have this directly referenced in visual studio but it built none the less.

image

I started to look at other projects in the build that used Linq but did not have any build issues and realized that they had System.Core referenced directly. So naturally I tried to go ahead and add System.Core to the project that was failing. Then I got this:

image

System.Core is automatically added by the build system. Well apparently not, so I had to add it manually. I opened the project file for my C# project in notepad and added the following to overwrite this error and get System.Core added.

image

After adding System.Core I was able to re-run the build and everything worked fine. As my co-worker Ralph would say, “it has been rectified”. hence the title of this blog post.

The cause of this issue is a project that is originally created as a .NET 4.0 project and then changed to a .NET 3.5 project. When Visual studio makes the alteration to the project file it does not handle adding System.Core into the project.

Friday, January 21, 2011

Find in files with preview pane

A little over a year ago we moved from Visual Source Safe to Team Foundation Server. Over all I was very happy with TFS and all the new features. There was one feature that I greatly missed from VSS and that was the ability to search within all projects for some specific text. There was occasionally a time where I would come across something that I had done before and wanted to reference it before writing it again. This can easy be accomplished in windows using search. To enable searching on your project workspace you must first add it to the list of places that the window search indexes.

Open Control Panel and click on Indexing Options.

image

Click on Modify and select the folders that you want indexed.

image

You will also need to click on advanced and select the “Index Properties and File Contents” option.

image

*Changing this option will reset the index and you will lose the ability to search items until they are re-indexed.

Now when performing a search all my project files are included.

image

Windows 7 does not have the ability to show a preview of C-Sharp files by default.

image

Adding this functionality is easy using the Managed Preview Handler Framework. Stephen Toub has a great walk through on this here. There is a CodePlex project that wraps his work along with a few others into an easy installer here. After either registering your own handlers or installing the CodePlex project you can use the windows preview pane to see the files from your search results.

image

Monday, September 27, 2010

The little things will get you.

I was recently writing a windows forms application that would run on a SharePoint server and run a set of actions if a solution was deployed. I used the standard approach of getting the solution by its ID from the solutions in the farm.

image

When I hit the SPFarm object the Local property was null.

image

How could SPFarm.Local be null?

The project had been given x86 by default when creating it in Visual Studio, and 32-bit application can’t call the SharePoint 2010 64bit Object Model.

image

Quick change to the Platform target and its good to go.

image

image

If your finding this post and changing your platform does not fix your issue, make sure you look at your permission too. You need to have permission to access the farm.

Wednesday, September 22, 2010

Fast Search Server iFilters for Tiffs and PDFs

Yesterday I wrote about setting up the Tiff iFilter on SharePoint Server 2010. Today I tried to apply this same approach to my 2010 FAST Search Server but hit a few bumps along the way. Several Bing searches lead me to someone talking about how both Tiff and PDF should work out of the box. I uploaded several document of both types, re-crawled and never got back any full text search results. I enabled the advanced filter pack, but still no luck. I did eventually get it working though and here is how I did it.

First I added the feature mentioned in the previous post for the Windows Tiff iFilter on the Fast Server.

image

Now that the feature is installed it will need to be registered. To register a iFilter for Fast server go to the formatdetector directory and edit the user_converter-rules.xml file.

image

I followed this article by Microsoft to register the tiff iFilter as a custom iFilter. I used this list by w3schools to get the mimetype reference needed to build my xml configuration.

image

After making your changes to the file make sure you keep a backup. If you ever install a Fast\SharePoint update or Service pack this file will be overwritten. This file is not backed up via the normal Fast\SharePoint backup procedures.

If you only care about Tiffs then you can run this power shell command (psctrl reset) on the Fast server and then re-crawl to get your full text search results.

image

To add PDF support download the latest PDF iFilter from adobe. At the time of this article it was this. Install the PDF iFilter on the Fast Server. Run the power shell command show above and then re-crawl all your content.

Now all PDF and Tiff documents should return full text search results.

image

Tuesday, September 21, 2010

Setup the TIFF iFilter for SharePoint 2010

If your running SharePoint 2010 on Windows Server R2 or Windows 7 the Tiff iFilter is a great add on that will OCR all your scanned Tiff files. The feature is turned off by default due to the additional load it can put on processing, but its easy to enable and greatly benefits searching.

The first step to enable the iFilter is adding the feature to the server. This is done through Server Manger. Click on Features in the tree and then Add Features on the right.

image

Check the box next to Windows Tiff IFilter.

image

Click next to confirm your selection then install the feature.

Now the the feature is installed it needs to be enabled and configured. Click on the start button and type gpedit.msc into the search window to launch the local group policy editor.

image

Under Computer Configuration select Administration Templates, then select the OCR folder.

image

This is were you will configure OCR for Tiffs.

image

The first option is to force OCR for all pages in a tiff. The TIFF iFilter attempts to optimize performance by skipping blank pages or pages that have non-textual content such as pictures. In my scenario almost every tiff was an invoice so I enabled this to ensure that no pages were missed during the OCR process.

image

The next setting is for the OCR language that you wish to check for. By default this will be the server system language, however if you have several different languages that you are expecting you can enable them here as long as they are part of the same code page. For example you could check for English, Dutch, French, and Italian since they all belong to the Western European code page. If you wanted to look for Japanese and English though you would have to use some other means of OCR since the Tiff iFilter does not support using more than one code page. Since I was only using English Tiff I left this setting as “Not Configured”.

image

If you have already installed SharePoint prior to these steps you will need to restart the associated SharePoint services. I was using a stand alone development environment so I was able to just reboot my server.

Now that you have the Tiff iFilter installed a full crawl will need to be run to OCR the documents. To run a full crawl open up central administration and click on manage service application.

image

Click on Search Service Application.

image

Under crawling click content sources.

image

Start a full crawl.

image

Once the crawl has finished go to your document library and search for some text that should be in one of your tiffs to see if everything worked.

image

Results!

image

Getting full text search results from the OCR data collected by the Tiff iFilter is easy, free, and a greatly improves searching in SharePoint 2010.