views:

63

answers:

3

I want to create simple file viewer. What control should i use to view office documents (word,excel) in my application.

+2  A: 

How to use the WebBrowser control to open Office documents in Visual C# 2005 or in Visual C# .NET

If you are using newer version of Office, you can work with documents via OpenXML SDK. There are some OOXML-based libraries with the higher level of abstraction like DocX or OpenXML Document Viewer. But you'll have to implement the viewer control yourself.

Artem K.
this is not working in VS 2008, any other solution ?
Deni Mf
+1  A: 

Older versions of Office used to support OLE Embedding, allow you to display their content in a web browser of the DsoFramer control. Those days are over, DsoFramer is no longer available and Office version ~2007 opens documents in their own program. You cannot make this work anymore.

Hans Passant
A: 

What worked for us was to download the document to the local workstation. Store it somewhere in the users personal folders path. Display using the software installed on the system.

Get the personal folder path using this:

Environment.GetFolderPath(Environment.SpecialFolder.Personal)

Download the desired file to that path.
Then shell out to the file using something like this:

if (File.Exists(fullLocalDocumentPath) == true)
{
    System.Diagnostics.Process proc = new System.Diagnostics.Process();
    proc.EnableRaisingEvents = false;
    proc.StartInfo.FileName = fullLocalDocumentPath;
    proc.Start();
}

This will use the OS configured program (based on file extension) to open the file and display it. This is not a perfect solution, but it does work for us and might fit your needs.

The caveats are:
  Will only display files with extensions that are mapped to applications.
  Opens a copy of application to display file.
  You should provide some mechanizm to clear out downloads files from the personal
folder.

File extensions that will often 'just work' using this technique:
    *.doc, *.docx, *.xls, .xlsx (docx and xlsx are Office 2007 and up)
    
.pdf (everyone has this installed, right?)
    .xps (will work if .NET installed, if running .NET program this won't be an issue)
    
.txt
Might work:
    *.pptx (requires power point)
Only work if you have specialty software installed:
  Visio files, Autocad, etc...

This can work even if the user does not have Office installed. The user simply needs to install the free reader applications from MS.

Jim Reineri
i need it embedded in the application, this will not work with my solution
Deni Mf