Wednesday, May 18, 2016

How to view documents using Visual Studio

There are numerous scenarios in which you need just to display Word documents with a limited interaction from the user, like when providing a service of access to documents that don't need to be converted to another format to be accessed by the users. In cases like this, you could try the tool Spire.DocViewer for .NET (you can also other reviews I wrote for other E-Icleblue: Spire.PDF, Spire.Presentation, Spire.XLS and Spire.DataExport). This is a tool to manipulate Word documents in .NET, and it allows us to:
  • View Word Documents
  • Easily print Word documents
  • Convert document formats
Now I'll give you a quick review of this tool, based in a simple example, where I'll walk through step by step. So, let's check this E-IceBlue product.


For these two last requirements, you might want to check instructions used for similar tools from E-IceBlue. Please check the instructions to create new projects and add references here and here.


1. Add ToolStrip to the form, and inside it, add two buttons one to open a document and the other to close it. Use this button:
Add elements

to add the buttons. You should see something like this when you're done:

Let's say that the first button is to open and the second is to close the document. You can change the default image if you want.

2. Double click Form1.Designer.cs. Here, we'll add the code for a field to display the document. This is not in the toolbox because is a Spire.DocViewer element. Here's the complete code of that file:

Now, you should see this in the designer view of the form:
Form with viewer

3. Next, we have to add code to the Form1.cs file. Basically, what I do here is:
  • Add the code in the button for opening documents
  • Add the code in the button for closing documents
Following, the complete code for Form1.cs:

Save everything. Now, just click Start and you'll see you'r app working:
App Running
Now, let's get it work:
Press the first button at the left. A window will opened and you'll be able to browse a doc file. Select it and it will be displayed in the Doc Viewer area:
Select a file

Loading doc

Open document

To close the document, just click the second button.


As with other E-IceBlue products, my experience was positive, mainly because the easy usage of the product. However, I spent some time coding the Doc View in the design file because there was no element in the toolbox for this. I think it would be great if they automatically add the design element to the toolbox when the installation happens. Other than that, I enjoyed using this product. It's easy enough to learn from the demo coding files, but it would be good to have a little tutorial for the design part. You can get more information about this product in the official webpage:

Check my reviews of other E-Icleblue products:

0 comentarios:

Post a Comment