Solved

.Net Image/Word/PDF/MSG Viewer Component

Posted on 2013-06-24
5
392 Views
Last Modified: 2013-07-10
Hi,
We are developing a Client Server application in Visual Studio 2012. We have a requirement where we need to display a file within a container in one of the screens. The file could be a jpg, bmp, png, word, excel, pdf or outlook msg file. Can any one suggest a component available for this requirement. The user should be able to only view- not edit
0
Comment
Question by:GEMINI-INDIA
  • 2
5 Comments
 
LVL 42

Accepted Solution

by:
sedgwick earned 500 total points
ID: 39274021
jpg, bmp, png can be viewed in .net PictureBox control (supports bitmap, metafile, icon, JPEG, GIF, or PNG)
to display pdf, use the web browser control, simply call webbrowser.Navigate("file.pdf")
to display word/excel, use the web browser control as well, but u need to convert to html first:

for msword:
Microsoft.Office.Interop.Word.Application word = new Microsoft.Office.Interop.Word.Application();
            Microsoft.Office.Interop.Word.Document wordDoc = new Microsoft.Office.Interop.Word.Document();
            Object oMissing = System.Reflection.Missing.Value;
            wordDoc = word.Documents.Add(ref oMissing, ref oMissing, ref oMissing, ref oMissing);
            word.Visible = false;
            Object filepath = @"C:\temp\1.docx";
            Object confirmconversion = System.Reflection.Missing.Value;
            Object readOnly = false;
            Object saveto = @"C:\temp\1.html";
            Object oallowsubstitution = System.Reflection.Missing.Value;

            wordDoc = word.Documents.Open(ref filepath, ref confirmconversion, ref readOnly, ref oMissing,
                                          ref oMissing, ref oMissing, ref oMissing, ref oMissing,
                                          ref oMissing, ref oMissing, ref oMissing, ref oMissing,
                                          ref oMissing, ref oMissing, ref oMissing);
            object fileFormat = WdSaveFormat.wdFormatHTML;
            wordDoc.SaveAs(ref saveto, ref fileFormat, ref oMissing, ref oMissing, ref oMissing,
                           ref oMissing, ref oMissing, ref oMissing, ref oMissing, ref oMissing,
                           ref oMissing, ref oMissing, ref oMissing, ref oallowsubstitution, ref oMissing,
                           ref oMissing);
            webBrowser1.Navigate(saveto.ToString());

Open in new window


//excel (csv/xls)
            string path = @"C:\temp\1.xls";
            Microsoft.Office.Interop.Excel.Application excelApllication = null;
            Workbook excelWorkBook = null;
            Worksheet excelWorkSheet = null;

            excelApllication = new Microsoft.Office.Interop.Excel.Application();
            excelApllication.AutomationSecurity = Microsoft.Office.Core.MsoAutomationSecurity.msoAutomationSecurityForceDisable;
            excelWorkBook = excelApllication.Workbooks.Open(path);
            excelWorkSheet = (Worksheet)excelWorkBook.Worksheets.get_Item(1);

            excelWorkSheet.SaveAs(path.Replace("xls", "html"), XlFileFormat.xlHtml);
            excelWorkBook.Close();
            excelApllication.Quit();

            Marshal.FinalReleaseComObject(excelWorkSheet);
            Marshal.FinalReleaseComObject(excelWorkBook);
            Marshal.FinalReleaseComObject(excelApllication);
            excelApllication = null;
            excelWorkSheet = null;
            
            webBrowser1.Navigate(path.Replace("xls", "html"));

Open in new window

0
 

Author Comment

by:GEMINI-INDIA
ID: 39313362
That was a mistake- Please award A
0
 
LVL 42

Expert Comment

by:sedgwick
ID: 39313386
thank you.
0

Featured Post

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

Suggested Solutions

In my previous article (http://www.experts-exchange.com/Programming/Languages/.NET/.NET_Framework_3.x/A_4362-Serialization-in-NET-1.html) we saw the basics of serialization and how types/objects can be serialized to Binary format. In this blog we wi…
More often than not, we developers are confronted with a need: a need to make some kind of magic happen via code. Whether it is for a client, for the boss, or for our own personal projects, the need must be satisfied. Most of the time, the Framework…
It is a freely distributed piece of software for such tasks as photo retouching, image composition and image authoring. It works on many operating systems, in many languages.
This video discusses moving either the default database or any database to a new volume.

746 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now