I'm using WinForm C#. How can I open a byte into a DocumentViewer? the byte[] is a .doc or .xps file..
first how to add a document viewer a winform?
I'm using WinForm C#. How can I open a byte into a DocumentViewer? the byte[] is a .doc or .xps file..
first how to add a document viewer a winform?
Know the answer? Post it — somebody with the same question will find it here.
Sign in to answer this question
It is the same account you read, post and publish with — and you will come straight back to this page.
Rahul PrasadPosted Feb 11, 2022, 9:39 AM
Hi, you could use Spire.DocViewer instead to load Word documents from stream and view it in a Windows Form application.
For more details, see this link:
https://www.e-iceblue.com/Introduce/word-viewer-net-introduce.html
Marvin ReidPosted Jan 9, 2024, 8:00 PM
You'll want to ensure the solution you use supports the file formats you plan on working with. A route you can take is by passing the byte array into a MemoryStream and loading the file using the LoadFromStream method. This will give you a LEADDocument which you can supply into the DocumentViewer.
Here is some sample code and a tutorial which you can supply this into.
https://www.leadtools.com/help/sdk/tutorials/dotnet-winforms-display-files-in-the-document-viewer.html
Tuhin PaulPosted Apr 28, 2023, 2:23 AM
Part 2:
Once you have added the DocumentViewer control to your WinForm, you can use the following code to display a .doc or .xps file from a byte array:
This code loads the document from the byte array into a MemoryStream, then creates an XpsDocument object from the stream. The XpsDocument object is then used to create a FixedDocumentSequence object, which is assigned to the DocumentViewer control's Document property. Finally, the DocumentViewer control is added to your WinForm's Controls collection.
Tuhin PaulPosted Apr 28, 2023, 2:22 AM
Even though this is a very old post, here is my approach to solve the problem.
Part 1:
To add a DocumentViewer to a WinForm, you can follow these steps:
1. Open your WinForm project in Visual Studio.
2. From the Toolbox, locate the "DocumentViewer" control under the "Reporting" section.
3. Drag and drop the DocumentViewer control onto your WinForm.
4. Resize the control to fit your needs.
Ganesan CPosted Feb 8, 2022, 6:50 AM