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?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Jorge PaulinoIT Pro/DeveloperCommented:
You can open the file like you open a page, and that will open the pdf
0
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

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
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
Become a CompTIA Certified Healthcare IT Tech

This course will help prep you to earn the CompTIA Healthcare IT Technician certification showing that you have the knowledge and skills needed to succeed in installing, managing, and troubleshooting IT systems in medical and clinical settings.

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
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Visual Basic.NET

From novice to tech pro — start learning today.