1

I have a DataGrid that reads from a table in a DB the name and file name (full address) of certain files. What I want is when the user double clicks the file it opens the PDF reader and loads the file. How would I go about doing this?

EDIT: This is my current code:

        Dim row2 As String = DataGridView1.Rows(e.RowIndex).Cells(3).Value
    Process.Start("Acrobat.exe", row2)

VS throws the exception that file cannot be found. I checked the variable and its giving me the correct data. I also tried putting row2 between the quotation marks and no go either. It just doesn't find the file.

WORKING UPDATE: Alright it was a very simple mistake

Process.Start("AcroRd32.exe", row2)

Row2 grabs the data from a cell I have in the datagrid that has the file location.

Lord Relix
  • 922
  • 5
  • 23
  • 50
  • Just to confirm, this is a WinForm application and not ASP.NET? – Yuriy Galanter Jun 10 '13 at 18:49
  • It's really great that you would like to provide an example of your working code for the benefit of future visitors. When doing so on Stack Overflow, please include it in an answer rather than in the original question. It may be confusing to future visitors. Also, it give future visitors an opportunity to "upvote" your solution if it was helpful to them (which can help other visitors weigh the value of your solution). – JDB Jun 11 '13 at 15:51

1 Answers1

1

Process.Start("filename") will open a file using the default application on that machine.

In most cases, the above approach is correct. It is not dependent on a particular application or particular version of the application being pre-installed on the target machine. The advantage is loose coupling between your application and the PDF viewer.

If you really need to, you can use Process.Start() to launch a particular program, many of which will accept a filename as a command line parameter, like so:

Process.Start("IExplore.exe", "C:\myPath\myFile.htm")

(This example taken from the linked MSDN documentation)

You can find a list of Adobe Reader's command line arguments here:

Adobe Reader Command Line Reference

Update: The above link is old (focuses on version 7). You can find version 8 documentation here:

http://www.adobe.com/content/dam/Adobe/en/devnet/acrobat/pdfs/pdf_open_parameters.pdf

I cannot find a reference for version 9.

Community
  • 1
  • 1
JDB
  • 25,172
  • 5
  • 72
  • 123
  • Alright will give this a go. Let's see how it works out, thanks! – Lord Relix Jun 10 '13 at 18:44
  • Alright so i got the following code.... `Dim row2 As String = DataGridView1.Rows(e.RowIndex).Cells(3).Value Process.Start(row2)` since I need to first get the value of the field. Problem is it gives me a "system cannot find the file". I see that the variable holds the correct data, so I guess I'll have to play a bit with arguments? – Lord Relix Jun 10 '13 at 19:22
  • Alright solution as.... its not Acrobat.exe, its AcrRd32.exe. Its working. THANKS! – Lord Relix Jun 10 '13 at 19:34
  • 1
    @LordRelix - glad it worked for you. You may want to stick with the first suggestion: allowing the OS to select the correct application based on defaults. This will future proof your program if a new version of Reader comes out, or if the application is run on a 64-bit machine, etc. It will also allow the user to run their perferred PDF viewer. – JDB Jun 10 '13 at 20:12
  • Suggestion accepted. Initially it didn't work without it but it was my bad. Now its working. Thanks a million. – Lord Relix Jun 11 '13 at 15:29