开发者

Document Viewer C# control

I want to create simple file viewer. What control s开发者_开发问答hould i use to view office documents (word,excel) in my application.


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.


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: But I'm doing this by DsoFramer component. The component works fine for both Word 2007 and Word 2010. There are plenty of features exists using this way. Cheers.


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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜