radpat
asked on
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
You can open the file like you open a page, and that will open the pdf
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
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(FilePat h)
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.
Response.ContentType = "Application/pdf"
Response.WriteFile(FilePat
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.
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
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.
ASKER
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?
ASKER
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.
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.
ASKER
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.
Well I not a pro on that area (security) but I think you will need to require a login for that
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
It was a multi part problem. Was able to find a resolution to my final problem before someone could respond.