1

I am using the Microsoft API Code Pack and have a handler using the following code

    string filename = "C:\\Hello.pdf";

    ShellFile shellFile = ShellFile.FromFilePath(filename);
    Bitmap bitmap = shellFile.Thumbnail.ExtraLargeBitmap;

    context.Response.ContentType = "image/jpeg";
    bitmap.Save(context.Response.OutputStream, ImageFormat.Jpeg);

This works fine to produce a "preview" style thumbnail for pdf documents, but when I try it with Word or Excel I get the generic thumbnail for the filetype instead of a mini image of the document (which is what I'm looking for).

Anyone have ideas on this? Can it be done using this API?

Eden
  • 523
  • 1
  • 7
  • 21
  • This link should help you! http://stackoverflow.com/questions/1439719/c-get-thumbnail-from-file-via-windows-api – Anirudha Aug 02 '11 at 21:14
  • I did see that one. In fact I think I got the link to the Windows API Code Pack from one of the answers, but I can't make it do what I really want it to do. I didn't explore the Sharepoint answer option because I didn't understand it and because we are not using the Sharepoint product in this project so I didn't think it would apply. – Eden Aug 02 '11 at 21:18
  • 1
    Not all Office documents are saved with thumbnail images. – David Heffernan Aug 02 '11 at 21:20
  • Does a preview (http://msdn.microsoft.com/en-us/magazine/cc163487.aspx) fit your requirement? Or you want to write a thumbnail provider? – Sheng Jiang 蒋晟 Aug 02 '11 at 22:25
  • Thanks, but it needs to be a thumbnail. The client wants these as links to open documents that have been uploaded to our database. – Eden Aug 02 '11 at 23:43

1 Answers1

2

As David said, not all Office documents are saved with a thumbnail. It's a property on the document itself. In Office 2010 you can see the checkbox on the Save As dialog box. In older versions of Office you can find it in the document properties.

Once the Office document is saved with a thumbnail, the code you have will work.

Adam Boddington
  • 6,750
  • 2
  • 21
  • 12