Solved

.Net Image/Word/PDF/MSG Viewer Component

Posted on 2013-06-24
5
404 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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

Microsoft Certification Exam 74-409

Veeam® is happy to provide the Microsoft community with a study guide prepared by MVP and MCT, Orin Thomas. This guide will take you through each of the exam objectives, helping you to prepare for and pass the examination.

Question has a verified solution.

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

Flash (http://en.wikipedia.org/wiki/Adobe_Flash) has evolved over the years to where it has become a masterful tool for displaying content screen.  It has excellent layout placement, UI precision as well as rendering capabilities. This, along with t…
The object model of .Net can be overwhelming at times – so overwhelming that quite trivial tasks often take hours of research. In this case, the task at hand was to populate the datagrid from SQL Server database in Visual Studio 2008 Windows applica…
If you’ve ever visited a web page and noticed a cool font that you really liked the look of, but couldn’t figure out which font it was so that you could use it for your own work, then this video is for you! In this Micro Tutorial, you'll learn yo…
This is my first video review of Microsoft Bookings, I will be doing a part two with a bit more information, but wanted to get this out to you folks.

634 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