Sunday, July 26, 2009

What code is used to open a file (pdf., doc., .pps, etc.) in Visual Basic 2005 Express?

How can I use button 1, for example, to view a PDF file about SR?"


Private Sub Button1_Click (Byval...)Handles Button1.Click


System.IO.File.Open(File path)


"


or whatt? Even if true, how to write the file path? I write:


"C://Documents and Settings/..." and it tells me "System.IO.File.Open" can't take this number off arguments?

What code is used to open a file (pdf., doc., .pps, etc.) in Visual Basic 2005 Express?
A file path is not written:





C://Documents and Settings/myDoc.pdf





Instead, it should be written:





C:\Documents and Settings\myDoc.pdf


_________________





What file types can the System.IO.File object open?


Are you quite sure that it can open a .pdf file?


_________________





The quick and easy way to open a .pdf file is to use the web browser control . This assumes that both IE and the Acrobat Reader are installed on the target system. Just use the Navigate method of the control with the PDF filename as the parameter and you're there.





Note that you may have to add the web browser control to your project, by accessing the COM Components tab on the toolbox. (SEE below.)


____________-





Here is another way to read pdfs.





Right click on any of the tabs in your toolbox, and click choose items. (Just make sure you have a version of Adobe Reader installed before starting.) When the dialog box pops up click the 'Com Components' tab. Next, pick the 'Adobe PDF Reader' COM component. Click OK, and you should now see an 'Adobe PDF Reader' control in your toolbox. Click this, and drag it to your VB form.(you may need to resize it, usually appears very small).





Now in order to read any pdf, you need only alter the 'src' property of the control—either in code or in the designer. When you run the program you should be able to view the pdf doc in the VB form. You should have access to most of the options you get in Adobe Reader.





Here is how you would alter the 'src' property in code:





Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load


AdobeReader.src = "C:\mydoc.pdf"


End Sub





___________

balsam

No comments:

Post a Comment