Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

.Net Image/Word/PDF/MSG Viewer Component

Posted on 2013-06-24
5
Medium Priority
?
408 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 2000 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

Learn by Doing. Anytime. Anywhere.

Do you like to learn by doing?
Our labs and exercises give you the chance to do just that: Learn by performing actions on real environments.

Hands-on, scenario-based labs give you experience on real environments provided by us so you don't have to worry about breaking anything.

Question has a verified solution.

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

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…
Wouldn’t it be nice if you could test whether an element is contained in an array by using a Contains method just like the one available on List objects? Wouldn’t it be good if you could write code like this? (CODE) In .NET 3.5, this is possible…
This course is ideal for IT System Administrators working with VMware vSphere and its associated products in their company infrastructure. This course teaches you how to install and maintain this virtualization technology to store data, prevent vuln…
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.

722 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