Monday, July 21, 2008

Word Document Preview

I occupied myself with building a quite simple Word document preview functionality in SharePoint. In some situations it might be handy to take a peek in the content of a Word document (read: DOCX document) before opening, editing, ... In most cases, styles and images used in the document doesn't matter - we just want to recognize our previously written document by reading some text content.

Solution

To accomplish this functionality I made use of Eugene Pankov's DocxToText class available at codeproject (modified it a bit) and used the open-source ZIP library SharpZipLib. Maybe I'll take the time to rewrite this functionality with the System.IO.Packaging namespace in the near future.

Attention

I know, the solution isn't 100% complete and not tested extensively. The errorhandling isn't optimal and the functionality is limited yet (sort documents by name, paging is enabled, display x content blocks) ... but feel free to modify to your needs. Download the solution.

Screenshots

Custom Action on every document library

CustomAction

Custom application page

wordprev1

Content appears when you hover over the document name (standard 5 alineas)

wordprev2

When 5 alineas isn't enough ... change the textbox value

wordprev3

12 comments:

Tom said...

How do you mean, you still use .NET 2.0. I see you are using MOSS 2007 and MOSS 2007 requires .NET 3.0. System.IO.Packaging is part of .NET 3.0 already. :-)

komakino said...

You're completely right! My fault.
Thank you to post me up.

Tom said...

No problem, man. Glad to be of service! :-) Some cool extensions would be:
- creating a list column with the preview. This way you could read previews right in the list itself.
- extending previews to pptx and xlsx

Great job already!

Sekhar said...

Hi Tom,

Thanks for the nice tool.I can not get it to working.

I have a document library which has 2 .doc documents and 2 .docx documents. I dont have 2007 installed on the machine.

I can see the menu Document Previewer in the document library but when I click it I can see a small text box and Submit button and nothing else.I can't see the documents at all on the Document Previewer page.

Please help, what to do.

Regards

Chandra

Sekhar said...

Hi I can see the documents now after lot of debugging but when I hover over the documents I can't see the preview of the document selected. Please let me know, whats wrong.

Thanks

Chandra

Sekhar said...

Your help is very much appreciated as I need to get this working.

komakino said...

Chandra,

Be aware that the tool only works with .docx documents.

Also makes sure that the preview information is already available in the modified datatable. Debug the whole thing to verify.

Let me know your progress...
Sven

Sekhar said...

Hi,

Thanks for your reply. Now I can see the documents. But when I hover over the documents, I can't see the text.

I think the problem is in the .css file because if I modify the styles I can see the text but not when hovering but that text apears always. Can you please let me know, how to show the text when I hover the link as hovering over the link is not working.

komakino said...

If you are working with IE7 - I'm pretty sure the CSS is not the problem.

Anonymous said...

Hi,

The Download link is dead. Can you update it for me please?

komakino said...

I'll post a link as soon as possible I hope I can find the solution package yet. ;)

Kasper Lambert said...

I can see the records now after lot of debugging but when I float over the records I can't see the review of the papers chosen. Please let me know, what is incorrect.