Solved

.Net Image/Word/PDF/MSG Viewer Component

Posted on 2013-06-24
5
396 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

Master Your Team's Linux and Cloud Stack!

The average business loses $13.5M per year to ineffective training (per 1,000 employees). Keep ahead of the competition and combine in-person quality with online cost and flexibility by training with Linux Academy.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

It seems a simple enough task, yet I see repeated questions asking how to do it: how to pass data between two forms. In this article, I will show you the different mechanisms available for you to do just that. This article is directed towards the .N…
In my previous two articles we discussed Binary Serialization (http://www.experts-exchange.com/A_4362.html) and XML Serialization (http://www.experts-exchange.com/A_4425.html). In this article we will try to know more about SOAP (Simple Object Acces…
Windows 10 is mostly good. However the one thing that annoys me is how many clicks you have to do to dial a VPN connection. You have to go to settings from the start menu, (2 clicks), Network and Internet (1 click), Click VPN (another click) then fi…
Although Jacob Bernoulli (1654-1705) has been credited as the creator of "Binomial Distribution Table", Gottfried Leibniz (1646-1716) did his dissertation on the subject in 1666; Leibniz you may recall is the co-inventor of "Calculus" and beat Isaac…

770 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