|
-
May 22nd, 2012, 02:54 PM
#1
Thread Starter
Hyperactive Member
Read/open PDF file on remote server
Can someone please guide me how to read/open a pdf file from web site existing on remote file share?
If you can provide with sample code that would be great!
Thanks
-
May 22nd, 2012, 03:44 PM
#2
Thread Starter
Hyperactive Member
Re: Read/open PDF file on remote server
This code is letting me read the properties but does not open the file-
fullFileName is UNC path like
\\servername\path\file.pdf
Code:
Dim fs As New System.IO.FileStream(fullFileName, System.IO.FileMode.Open, System.IO.FileAccess.Read)
Any suggestions?
-
May 22nd, 2012, 03:53 PM
#3
Thread Starter
Hyperactive Member
Re: Read/open PDF file on remote server
Code:
Dim Path = "\\server\myshare\File.pdf"
System.Diagnostics.Process.Start(Path)
is only working when I run the website locally and access file on remote file share. However, if I publish the website the it gives error-
The system cannot find the file specified
Any thoughts?
-
May 22nd, 2012, 07:07 PM
#4
Re: Read/open PDF file on remote server
You cannot run the files of a client machine.
ἄνδρα μοι ἔννεπε, μοῦσα, πολύτροπον, ὃς μάλα πολλὰ
πλάγχθη, ἐπεὶ Τροίης ἱερὸν πτολίεθρον ἔπερσεν·
-
May 23rd, 2012, 03:47 AM
#5
Re: Read/open PDF file on remote server
Ssingh. The problem is that this code
Code:
System.Diagnostics.Process.Start(Path)
is running on the server. This is why it works locally as your dev machine IS the server.
Once you have deployed that command is running on the server, not the client you are trying to view it on.
-
May 23rd, 2012, 08:27 AM
#6
Thread Starter
Hyperactive Member
[Resolved]: Read/open PDF file on remote server
Finally I got the code that works so thought of sharing with the group!
strUNCPath for example "\\server\volume\directory\fileName.pdf"
Code:
Protected Sub ReadFile(ByVal strOperation As String, ByVal strUNCPath As String)
Select Case strOperation.ToString
Case "Select"
Try
Dim FileName As String = strUNCPath
Dim i As Int32 = 0
impersonateUser.impersonateUser("username", "Doamin", "password")
If strUNCPath.Contains("\") Then
Dim x() = strUNCPath.Split("\")
If Not IsNothing(x) Then
If Not IsNothing(x.GetUpperBound(0)) Then
i = x.GetUpperBound(0)
FileName = x(i).ToString
End If
End If
End If
Dim data As Byte()
data = My.Computer.FileSystem.ReadAllBytes(strUNCPath)
Response.ClearContent()
Response.ContentType = "application/octet-stream"
Response.AppendHeader("Content-Disposition", "attachment; filename=" & FileName)
Response.TransmitFile(strUNCPath)
Response.End()
Catch ex As Exception
End Try
Case "Delete"
Try
My.Computer.FileSystem.DeleteFile(strUNCPath)
Catch ex As Exception
End Try
End Select
End Sub
Thanks for your help!
Last edited by ssingh; May 23rd, 2012 at 08:50 AM.
-
Jul 20th, 2012, 02:52 AM
#7
New Member
Re: Read/open PDF file on remote server
ssingh,
could you please tell me the code for impersonation used in this?
-
Jul 23rd, 2012, 01:13 AM
#8
Re: Read/open PDF file on remote server
Suhas,
Welcome to the forums!!
Have a look at this thread:
http://www.vbforums.com/showthread.php?t=684652
Hope that helps!
Gary
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|