Results 1 to 8 of 8

Thread: [RESOLVED] Exception Error when referencing a file

  1. #1

    Thread Starter
    Member
    Join Date
    Oct 2014
    Posts
    37

    Resolved [RESOLVED] Exception Error when referencing a file

    Hey to All on the Forum,

    Just finished another VB project. Now I am moving on to something that will really challenge my skillset. I'm trying to encrypt and decrypt files. I have imported didisoft library for OpenPGP and now am getting a basic error when I'm referencing a file. Thought I would take the opportunity to ask how to do what I really want.

    I get the following error:

    System.IO.DirectoryNotFoundException was unhandled
    HResult=-2147024893
    Message=Could not find a part of the path 'C:\VB\Projects\Labs\Quiz2\CryptoKingdom\CryptoKingdom\bin\Debug\DataFiles\cryptomessage.txt'.

    Obviously, the file is not there I am referencing; the code is right here:

    Code:
    pgp.EncryptFilePBE(New FileInfo("DataFiles\cryptomessage.txt"), _
                                "password", _
                                New FileInfo("DataFiles\OUTPUT.pgp"), _
                                asciiArmor)
    I have another button on my form that I am pulling notepad up with. I prompt the user to create a file and save it. What I really want to do in my code is allow them to browse and choose the file they just created and have the method applied to that file. Can you help me or point me in the right direction?

    Thanks folks,

    sackerman.

  2. #2
    Fanatic Member Toph's Avatar
    Join Date
    Oct 2014
    Posts
    655

    Re: Exception Error when referencing a file

    System.IO.DirectoryNotFoundException means it was looking for a valid directory and it wasn't found.

    'C:\VB\Projects\Labs\Quiz2\CryptoKingdom\CryptoKingdom\bin\Debug\DataFiles\cryptomessage.txt'.
    isnt a directory. it points to a file, the file crptomessage.

    'C:\VB\Projects\Labs\Quiz2\CryptoKingdom\CryptoKingdom\bin\Debug\DataFiles\
    is an example of a valid folder.

  3. #3
    Smooth Moperator techgnome's Avatar
    Join Date
    May 2002
    Posts
    34,538

    Re: Exception Error when referencing a file

    Well, in this case, all it means is that some part of this directory structure:
    C:\VB\Projects\Labs\Quiz2\CryptoKingdom\CryptoKingdom\bin\Debug\DataFiles\
    wasn't found...it could mean that DataFiles doesn't exist in the bin\Debug folder, or some other part of it is off.

    Obviously, the file is not there I am referencing
    So then why reference it, if it doesn't exist?

    -tg
    * I don't respond to private (PM) requests for help. It's not conducive to the general learning of others.*
    * I also don't respond to friend requests. Save a few bits and don't bother. I'll just end up rejecting anyways.*
    * How to get EFFECTIVE help: The Hitchhiker's Guide to Getting Help at VBF - Removing eels from your hovercraft *
    * How to Use Parameters * Create Disconnected ADO Recordset Clones * Set your VB6 ActiveX Compatibility * Get rid of those pesky VB Line Numbers * I swear I saved my data, where'd it run off to??? *

  4. #4

    Thread Starter
    Member
    Join Date
    Oct 2014
    Posts
    37

    Re: Exception Error when referencing a file

    Quote Originally Posted by techgnome View Post
    Well, in this case, all it means is that some part of this directory structure:
    C:\VB\Projects\Labs\Quiz2\CryptoKingdom\CryptoKingdom\bin\Debug\DataFiles\
    wasn't found...it could mean that DataFiles doesn't exist in the bin\Debug folder, or some other part of it is off.


    So then why reference it, if it doesn't exist?

    -tg
    Right, so I changed that to be a different file so I don't get that error. However, I really want them to able to browse and choose the file they want, but that has to execute at this point in the code. I'll show you the code here.

    Code:
    Dim pgp As New PGPLib()
            ' specify should the output be ASCII or binary
            Dim asciiArmor As Boolean = True
    
            pgp.EncryptFilePBE(New FileInfo("c:\CryptoMessages\cryptomessage.txt"), _
            "password", _
                                New FileInfo("c:\CryptoMessages\OUTPUT.pgp"), _
                                asciiArmor)
    I'm not sure if it makes sense because I'm using didisoft .NET library for OpenPGP. It makes this stuff fairly easy, I'm just not sure how to put in the stuff I want. I'm very new.

    All the above code executes with a click event from a button on my form. I can get it to work and encrypt the file. What I want, though, is where the code gets the file c:\cryptomessages\cryptomessage.txt, to instead prompt the user and allow them to browse for their file. The library will then encrypt that file; or, like it does now, will just encrypt that file to cryptomessage.pgp. I want to user to browse and select the file instead, then execute the code to encrypt it. I think I can move the file at that point where I want it.

    Does that make sense?

    -sackerman
    Last edited by sackerman; Nov 30th, 2014 at 01:16 PM.

  5. #5
    Bad man! ident's Avatar
    Join Date
    Mar 2009
    Location
    Cambridge
    Posts
    5,398

    Re: Exception Error when referencing a file

    you dont understand simple messages directory not found?

  6. #6

    Thread Starter
    Member
    Join Date
    Oct 2014
    Posts
    37

    Re: Exception Error when referencing a file

    Yes, I understand that message. Like I said, I fixed that by creating a directory and a file that do exist. I want to allow the user to browse and choose the file they want, and then encrypt it. I don't know how to do that. Although I'm trying to find out how; I'm looking for answers outside of here as well, and maybe I can just insert browsing for a file code into that section of my code. That's what I'm thinking. We'll see how it works.

    -sackerman

  7. #7
    Fanatic Member Toph's Avatar
    Join Date
    Oct 2014
    Posts
    655

    Re: Exception Error when referencing a file

    Use an OpenFileDialog.

    Google it and learn how to use it.

  8. #8

    Thread Starter
    Member
    Join Date
    Oct 2014
    Posts
    37

    Re: Exception Error when referencing a file

    I am thanks.

Tags for this Thread

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