Launching file with associated application exentension

I self taught myself VB.NET a couple of months ago so I'm still pretty new at this.  I was looking at  a way to launch/open a pdf file.  I was looking at the FileStream functions but it seemed more appropriate for reading in text when all I need was to actually open a file with the right application based on the file extension.  So I came across System.Diagnostics.Process and it worked perfectly.  Until I moved the application up to a web server that is.  I guess the new process is actually being run on the server rather than on the client side.  Is there a way to do something similar on the client?
Dim myProcess As System.Diagnostics.Process = New System.Diagnostics.Process()
Dim location As String

location = "W:\SomeFileShare\Stuff.pdf"

Try
      myProcess.StartInfo.FileName = location 
      myProcess.StartInfo.WindowStyle = System.Diagnostics.ProcessWindowStyle.Normal
      myProcess.Start()

Catch ex As Exception
      lblError.Visible = True
      lblError.Text = "File Not Found - Please make sure you have entered the correct information."
End Try

Open in new window

LVL 3
radpatAsked:
Who is Participating?
 
Jorge PaulinoIT Pro/DeveloperCommented:
Some different examples:

http://www.beansoftware.com/ASP.NET-Tutorials/PDF-View-Custom-Control.aspx
http://support.microsoft.com/kb/307603/EN-US/

but this will work for a full page:

Response.Redirect("path/file.pdf")
0
 
Jorge PaulinoIT Pro/DeveloperCommented:
You can open the file like you open a page, and that will open the pdf
0
 
radpatAuthor Commented:
Well I have some success but there are issues.  I tried using Redirect but that didn't work.  Using the following worked:
Response.ContentType = "Application/pdf"
Response.WriteFile(FilePath)
Response.End()

It opened the file in the browser which is nice but...
It doesn't seem to throw an error when the file is not found which bypasses my 'Try' block.  It also opens it in the same browser window.
0
Keep up with what's happening at Experts Exchange!

Sign up to receive Decoded, a new monthly digest with product updates, feature release info, continuing education opportunities, and more.

 
Jorge PaulinoIT Pro/DeveloperCommented:
You can check if the file exists before try to open it, using IO.File.Exists(your_file_path)
0
 
radpatAuthor Commented:
I might have spoken too soon.  Much like my previous code it can't find the file on the client side once I loaded it to the server.
0
 
radpatAuthor Commented:
I should have been more specific.  The pdf files are located on a network shared drive accessible to all so the path would be valid from my machine or otherwise.  By default it appears that the server is attempting to locate the file but since the server has no such drive it can't find the file.  Can the path be specified to look at the client files?  Or will it always attempt to grab them from the server?
0
 
radpatAuthor Commented:
Maybe the best method would be the specify the entire network path so the server could reach the files but which account would be used?  I need to make sure only users who already have access to that drive can open the files.
0
 
Jorge PaulinoIT Pro/DeveloperCommented:
Don't you have a path that you use for open the pdf files? You just need to use that path to check if the file exists.
0
 
radpatAuthor Commented:
jpaulino, you misunderstand.  At first I didn't realize that it would look to the server for the path so I easily resolved that by using using the full UNC path and I did use your File.Exists example which works just fine...on my local pc that is.  However, it helped me identify an issue that the network account being used once I loaded the application to the server could not see those files.  Simply because it didn't have proper permissions.  My issue right now is that the folder is restricted by permissions so I need to find a way to pass the logged on users credentials for accessing the shared drive.  I tried using the impersonate element in the web.config file but that had no success.
0
 
Jorge PaulinoIT Pro/DeveloperCommented:
Well I not a pro on that area (security) but I think you will need to require a login for that
0
 
radpatAuthor Commented:
I figured out the security issue.  I needed to add the server where the file share was located to the delegation tab of the hosting web server.  Then impersonation worked.
0
 
radpatAuthor Commented:
It was a multi part problem.  Was able to find a resolution to my final problem before someone could respond.
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.