CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 6 of 6
  1. #1
    Join Date
    Jul 2005
    Posts
    23

    Question Accessing files in project folder (solved)

    Ive spent about an hour googling around looking for this solution. Perhaps I am not wording what I want correctly.

    Ive added .png files to a subfolder in my project folder. How do I access those files in the code??

    Im trying to implement: Image myImage = Image.FromFile(@"project_path\CARDS\spade.png");

    What are their paths from the project folder, it cant just be from my machine, when it comes time to package the project, those file paths obviously need to stay the same.

    Its probably so simple, I just cant figure it out tho.
    Last edited by mycomputerfund; March 9th, 2006 at 02:47 PM.

  2. #2
    Join Date
    Dec 2005
    Posts
    282

    Re: Accessing files in project folder

    If you wan't to use this folder also later in your finished program, you can select for your file under properties "Copy to output directory"

    then the file is in your actual working directory during running the program.

    This works for sure with VS2005. I don't know what is with other versions...
    Regards
    Hansjörg

  3. #3
    Join Date
    Jul 2005
    Posts
    23

    Re: Accessing files in project folder

    But what is the path of that directory? Right now the folder is simply in the project's folder ie. "C:\Documents and Settings\ Owner\Desktop\C#\WindowsApplication3\CARDS\spade.png".

    Again, I need to be able to just have the file included in the project and not just reference the image on my hard drive. Ive tried using the path "CARDS\spade.png" but it doesnt find it. I can see the folder in the project explorer in the box on the right. I just cant figure out how to have it "included" as part of the actual project, then call it from the code.

  4. #4
    Join Date
    Jul 2002
    Location
    India
    Posts
    505

    Re: Accessing files in project folder

    When you run your application in VS.net, the output files are copied to the bin/debug (or bin/release) folder under your project folder. So if your project name is WindowsApplication3, the output directory is WindowsApplication3/bin/debug.

    For your scenario what you can do is copy the file to the bin/debug folder and in you code access it using

    Code:
    AppDomain.CurrentDomain.BaseDirectory + "spade.png"
    When you deploy your app make sure the file is in the same folder as the executable.

    Hope this helps

    -Satish

  5. #5
    Join Date
    Jul 2002
    Location
    India
    Posts
    505

    Re: Accessing files in project folder

    Some more info...

    As hansipet has mentioned before, if you are using VS.Net 2005, you can set "Copy to output directory" in the files properties. However, if you are using a previous version, and absolutly don't want to manualy copy the file to the output directory, you can do what is mentioned in the article below.


    http://searchvb.techtarget.com/vsnet...293474,00.html

    -Satish

  6. #6
    Join Date
    Jul 2005
    Posts
    23

    Red face Re: Accessing files in project folder (solved)

    Amazing!! Thank you Satish it worked!!

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

Featured