Results 1 to 8 of 8

Thread: file path?

  1. #1

    Thread Starter
    Member
    Join Date
    Nov 2003
    Posts
    52

    file path?

    Hi all,

    I want to be able to use a file (.gif) without knowing exactly where it's located.

    If I put the file in the same directory as my .sln file how can I access the file?

    In vb6 there is something like app.path to get the directory where project files are.

    is there a function that takes a file (for example .sln my file) and return the full path so I can use that if I put the .gif file in the same dir as my .sln file ?

    Regards

    Jonni

  2. #2
    Fanatic Member brown monkey's Avatar
    Join Date
    Jun 2004
    Location
    Cebu
    Posts
    552
    just put it in the project folder/bin/debug and access it as
    Code:
    Application.StartUpPath+@"\file.extension"

  3. #3
    Sleep mode
    Join Date
    Aug 2002
    Location
    RUH
    Posts
    8,083
    My 2cent :
    It would be a lot safer to use Combine the two paths using this method .
    PHP Code:
    using System.IO

    string path
    =Path.Combine(Application.StartupPath,"file.extension"

  4. #4
    Fanatic Member
    Join Date
    Aug 2000
    Location
    I'm right here!
    Posts
    849

    Re: file path?

    Hello,
    I'm using the VS.Net and it doesn't work...
    did the code change?

    I want to get the path of the project...
    anyone knows how?

    thanks

    Dekel C.

  5. #5
    I'm about to be a PowerPoster! Hack's Avatar
    Join Date
    Aug 2001
    Location
    Searching for mendhak
    Posts
    58,333

    Re: file path?

    Try
    Code:
    string aPath1 = Application.ExecutablePath;
        string aPath2 = Application.StartupPath;

  6. #6
    Fanatic Member
    Join Date
    Aug 2000
    Location
    I'm right here!
    Posts
    849

    Re: file path?

    why can't it recognise the "Application.ExecutablePath" and
    "Application.StartupPath" functions?

    or am I doing something wrong?

    I have a dll that I'm building, and I want to save some preferences in a txt
    file in the same folder...

    Dekel C.

  7. #7
    Sleep mode
    Join Date
    Aug 2002
    Location
    RUH
    Posts
    8,083

    Re: file path?

    Application Class comes under this namespace "System.Windows.Forms".

  8. #8
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    111,221

    Re: file path?

    If you've created a Class Library project, as it would seem you have, then you will need to add a reference to the System.Windows.Forms assembly, which contains the System.Windows.Forms namespace. If you want to create a DLL with WinForms functionality you can create a Windows Control Library project from the start, which already has that reference.
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

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