7 Replies - 478 Views - Last Post: 05 October 2018 - 09:06 AM Rate Topic: -----

#1 aspfun   User is offline

  • D.I.C Head

Reputation: 1
  • View blog
  • Posts: 92
  • Joined: 16-January 13

Open a PDF file with security

Posted 04 October 2018 - 08:58 AM

I used code below to open high security file in folder order and require to pass one user's account and password.
But, Process.Start did have this option.
Is there another command will do this job?

Dim FILE_NAME As String = "\\myfileserver\order\20180402711797300001.pdf"

        If System.IO.File.Exists(FILE_NAME) = True Then
            Process.Start(FILE_NAME)

        Else
            MsgBox("File Does Not Exist")
        End If
:code:

This post has been edited by modi123_1: 04 October 2018 - 09:02 AM
Reason for edit:: In the future, please use the [code] tag button in the editor.


Is This A Good Question/Topic? 0
  • +

Replies To: Open a PDF file with security

#2 modi123_1   User is online

  • Suitor #2
  • member icon



Reputation: 14502
  • View blog
  • Posts: 58,138
  • Joined: 12-June 08

Re: Open a PDF file with security

Posted 04 October 2018 - 09:02 AM

Come on now five year veteran of the site.. code tags! I mentioned this once already today! :^:
Was This Post Helpful? 0
  • +
  • -

#3 Sheepings   User is offline

  • Senior Programmer
  • member icon

Reputation: 120
  • View blog
  • Posts: 852
  • Joined: 05-December 13

Re: Open a PDF file with security

Posted 04 October 2018 - 12:37 PM

StreamReader. You could do something like this to read the file, but Instead of using pdf, consider using XML to store user/pass in and I'd advocate using encryption. That in conjunction with XMLNodes, it will make it easier for you rather than working with Pdf. Of course if you opt for a changeover in file format, you will then use a XMLReader instead. For the most part, a reader will help you here with files other than PDF:
    Public Shared ReadOnly Property assembly_Directory As String
        Get
            Dim address As String = AppDomain.CurrentDomain.BaseDirectory
            Return address
        End Get
    End Property
    Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
        Dim FILE_NAME As String = "\\testtext.txt"
        Dim cPath As String = Path.Combine(assembly_Directory + FILE_NAME)
        If File.Exists(cPath) = True Then
            Using fReader As New StreamReader(cPath)
                While fReader.Read
                    If fReader.ReadLine().Contains("Yourtext") Then
                        'Do something with it
                    End If

                End While
            End Using

        Else
            MsgBox("File Does Not Exist")
        End If
    End Sub


For PDF, you can try use Imports iTextSharp.text.pdf Imports iTextSharp.text.pdf.parser
or something like this VB.Net PDF Library or this non free version

One other thing to point out, :: Dim address As String = AppDomain.CurrentDomain.BaseDirectory returns files in the executing file directory. This was only used for testing purposes. But you can manipulate it to build a function to return the path you want. :)
Was This Post Helpful? 0
  • +
  • -

#4 IronRazer   User is offline

  • Custom Control Freak
  • member icon

Reputation: 1515
  • View blog
  • Posts: 3,832
  • Joined: 01-February 13

Re: Open a PDF file with security

Posted 04 October 2018 - 02:22 PM

Just as a side note, the iTextSharp library is free to download and use but, it does have a license which does not allow you to use the iTextSharp library in a commercial application. 8)
Was This Post Helpful? 0
  • +
  • -

#5 Sheepings   User is offline

  • Senior Programmer
  • member icon

Reputation: 120
  • View blog
  • Posts: 852
  • Joined: 05-December 13

Re: Open a PDF file with security

Posted 04 October 2018 - 03:35 PM

Your side note is correct IronRazer. :^: I'm sure you're going to want to stick with working with pdf, as most people who post these types of questions have limited coding experience, and are opposed to changing code because of effort they've put into learning to do what they've already achieved. If so, you can run Install-Package iTextSharp -Version 5.5.13 in your package manager in visual studio. Or you can get it from here.
Was This Post Helpful? 0
  • +
  • -

#6 aspfun   User is offline

  • D.I.C Head

Reputation: 1
  • View blog
  • Posts: 92
  • Joined: 16-January 13

Re: Open a PDF file with security

Posted 05 October 2018 - 06:37 AM

I used code below open a PDF file but got a error said

The specified executable is not a valid application for this OS platform

But, if I open non-security folder as Process.Start(FILE_NAME) will be no problem.

How to fix it?


Dim FILE_NAME As String = "\\MYSERVER\ORDER\N1234.PDF"
Process.Start(FILE_NAME, "USERNAME", ToSecureString("MYPASSWORD"), "DOMAINNAME")
:code:

This post has been edited by modi123_1: 05 October 2018 - 06:39 AM
Reason for edit:: In the future, please use the [code] tag button in the editor.

Was This Post Helpful? 0
  • +
  • -

#7 andrewsw   User is online

  • head thrashing
  • member icon

Reputation: 6629
  • View blog
  • Posts: 27,098
  • Joined: 12-December 12

Re: Open a PDF file with security

Posted 05 October 2018 - 07:04 AM

If Process.Start directly fails then I would revert to using ProcessStartInfo to have tighter control over the process, and discover more easily where the problem might lie.

(I'll guess that with the longer form of Process.Start it is more insistent that the first argument be an executable, but just a guess.)
Was This Post Helpful? 0
  • +
  • -

#8 Sheepings   User is offline

  • Senior Programmer
  • member icon

Reputation: 120
  • View blog
  • Posts: 852
  • Joined: 05-December 13

Re: Open a PDF file with security

Posted 05 October 2018 - 09:06 AM

According to your other topic where you are using the same code, you wanted to do read the contents of PDF, are you passed that stage now?

I'm not sure why you are asking questions about Porcess.Start when its covered in full in the documentation should you take the time to read it, I'm sure you will see what you might be doing wrong.

Side note to your original problem, your using secure string wrongly. Take this example:
        Dim rawPassw As String = "mypass"
        Dim pChars As Char() = rawPassw.ToCharArray()
        Dim securePASS As New SecureString()
        For Each c As Char In pChars
            securePASS.AppendChar(c)
        Next

You don't need to cast, nor can you. Also, you should code with OptionStrict On.

What do you expect your code to do?

If you register .pdf in registry to associated application, it will open with an elected application capable of handling that file. I've asked a mod to merge your topics for you.
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1