how to set a proper path of a image file? Windows App - C#

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • Anuhas
    New Member
    • Jan 2008
    • 23

    how to set a proper path of a image file? Windows App - C#

    Dear Experts,

    My project involves developing a Windows Application where i need to load a picture and i used the following code,

    Bitmap myBitmap3 = new Bitmap(@"C:\App \images\logo.bm p");

    however, this is not convenient as if i try to use the same project folder in another pc, it doesn't work. so i tried the following,

    Bitmap myBitmap3 = new Bitmap(@"\image s\logo.bmp");

    however, it doesn't work either,

    Can you help me?
  • dip_developer
    Recognized Expert Contributor
    • Aug 2006
    • 648

    #2
    Originally posted by Anuhas
    Dear Experts,

    My project involves developing a Windows Application where i need to load a picture and i used the following code,

    Bitmap myBitmap3 = new Bitmap(@"C:\App \images\logo.bm p");

    however, this is not convenient as if i try to use the same project folder in another pc, it doesn't work. so i tried the following,

    Bitmap myBitmap3 = new Bitmap(@"\image s\logo.bmp");

    however, it doesn't work either,

    Can you help me?
    create a folder in your solution....sav e the image in that folder.......sa ve the image path in your database.....in my opinion this approach is easy

    Comment

    • Anuhas
      New Member
      • Jan 2008
      • 23

      #3
      Originally posted by dip_developer
      create a folder in your solution....sav e the image in that folder.......sa ve the image path in your database.....in my opinion this approach is easy

      i am not using any database..
      is there any other way?

      Comment

      • dip_developer
        Recognized Expert Contributor
        • Aug 2006
        • 648

        #4
        Originally posted by Anuhas
        i am not using any database..
        is there any other way?
        then clearly state your problem......wh ere to load your picture......?? ?

        Comment

        • spacemanafrica
          New Member
          • Mar 2008
          • 6

          #5
          Originally posted by Anuhas
          Dear Experts,

          My project involves developing a Windows Application where i need to load a picture and i used the following code,

          Bitmap myBitmap3 = new Bitmap(@"C:\App \images\logo.bm p");

          however, this is not convenient as if i try to use the same project folder in another pc, it doesn't work. so i tried the following,

          Bitmap myBitmap3 = new Bitmap(@"\image s\logo.bmp");

          however, it doesn't work either,

          Can you help me?
          You can get the path to the application like this:

          Code:
            System.Reflection.Assembly asm = System.Reflection.Assembly.GetExecutingAssembly();
            string exedir = asm.Location.Substring(0, asm.Location.LastIndexOf('\\') + 1);
          then...

          Code:
          Bitmap myBitmap3 = new Bitmap(@exedir + "images\logo.bmp");

          Comment

          • Anuhas
            New Member
            • Jan 2008
            • 23

            #6
            Originally posted by spacemanafrica
            You can get the path to the application like this:

            Code:
              System.Reflection.Assembly asm = System.Reflection.Assembly.GetExecutingAssembly();
              string exedir = asm.Location.Substring(0, asm.Location.LastIndexOf('\\') + 1);
            then...

            Code:
            Bitmap myBitmap3 = new Bitmap(@exedir + "images\logo.bmp");
            thanks for your reply,
            i tried ur code,
            but when i executed the variable asm.location gets assigned with the path of the .exe file in the debug\bin folder, not to Windows App folder..
            how to correct this?

            Comment

            • Anuhas
              New Member
              • Jan 2008
              • 23

              #7
              Originally posted by dip_developer
              then clearly state your problem......wh ere to load your picture......?? ?
              Dear Experts,

              for my project, i am using an image which i inserted into the project folder and i am using that image as the background of the project. also when i click a button i am changing the background to another image which is a requirement of my project. i was able to do that. but the problem is the image path. i tested it with the absolute path. now i need to set a proper path so that i can use the same project to upgrade in another pc. reply.

              Comment

              • Anuhas
                New Member
                • Jan 2008
                • 23

                #8
                how to set a proper path of a image file? Windows App - C#

                Dear Experts,

                for my project, i am using an image which i inserted into the
                project folder and i am using that image as the background of the project.

                also when i click a button i am changing the background to
                another image which is a requirement of my project. i was able to do that. but the problem is the image path.

                i tested it with the absolute path. now i need to set a proper path
                so that i can use the same project to upgrade in another pc. reply.

                this is the code i tested first,

                Bitmap myBitmap3 = new Bitmap(@"C:\App \images\logo.bm p");

                however, this is not convenient as if i try to use the same project folder in another pc, it doesn't work. so i tried the following,

                Bitmap myBitmap3 = new Bitmap(@"\image s\logo.bmp");

                however, it doesn't work either,

                Can you help me?

                Comment

                • Plater
                  Recognized Expert Expert
                  • Apr 2007
                  • 7872

                  #9
                  I have merged these two threads. Please refrain from double posting.

                  Comment

                  Working...