Solved

.Net Image/Word/PDF/MSG Viewer Component

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

DevOps Toolchain Recommendations

Read this Gartner Research Note and discover how your IT organization can automate and optimize DevOps processes using a toolchain architecture.

Question has a verified solution.

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

Suggested Solutions

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…
Recently while returning home from work my wife (another .NET developer) was murmuring something. On further poking she said that she has been assigned a task where she has to serialize and deserialize objects and she is afraid of serialization. Wha…
With Secure Portal Encryption, the recipient is sent a link to their email address directing them to the email laundry delivery page. From there, the recipient will be required to enter a user name and password to enter the page. Once the recipient …

735 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