Results 1 to 8 of 8

Thread: Read/open PDF file on remote server

  1. #1

    Thread Starter
    Hyperactive Member
    Join Date
    Jan 2002
    Posts
    320

    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

  2. #2

    Thread Starter
    Hyperactive Member
    Join Date
    Jan 2002
    Posts
    320

    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?

  3. #3

    Thread Starter
    Hyperactive Member
    Join Date
    Jan 2002
    Posts
    320

    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?

  4. #4
    King of sapila
    Join Date
    Oct 2006
    Location
    Greece
    Posts
    6,763

    Re: Read/open PDF file on remote server

    You cannot run the files of a client machine.
    ἄνδρα μοι ἔννεπε, μοῦσα, πολύτροπον, ὃς μάλα πολλὰ
    πλάγχθη, ἐπεὶ Τροίης ἱερὸν πτολίεθρον ἔπερσεν·

  5. #5
    Frenzied Member Fishcake's Avatar
    Join Date
    Feb 2001
    Location
    Derby, UK
    Posts
    1,092

    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.

  6. #6

    Thread Starter
    Hyperactive Member
    Join Date
    Jan 2002
    Posts
    320

    [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.

  7. #7
    New Member
    Join Date
    Jul 2012
    Posts
    1

    Re: Read/open PDF file on remote server

    ssingh,

    could you please tell me the code for impersonation used in this?

  8. #8
    PowerPoster gep13's Avatar
    Join Date
    Nov 2004
    Location
    The Granite City
    Posts
    21,963

    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
  •  



Click Here to Expand Forum to Full Width