Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. Windows Forms
  4. How can i load image from Application Folder by using Short url( like ~\Images\default.jpeg ,but not working) to PictureBox

How can i load image from Application Folder by using Short url( like ~\Images\default.jpeg ,but not working) to PictureBox

Scheduled Pinned Locked Moved Windows Forms
graphicsquestion
5 Posts 3 Posters 4 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • M Offline
    M Offline
    Member 4363680
    wrote on last edited by
    #1

    Advance Thanks for your kind response i am using PictureBox1 to load image ,below is my code PictureBox1.Image = new Bitmap("C:\\Users\\Thahir\\Desktop\\folobiz\\school\\Images\\default.jpeg"); It works ,But i want to reduce the URL,so that folobiz is my root folder, i want URL like ~\Images\default.jpeg(Its not working) Pls Replay

    D L 3 Replies Last reply
    0
    • M Member 4363680

      Advance Thanks for your kind response i am using PictureBox1 to load image ,below is my code PictureBox1.Image = new Bitmap("C:\\Users\\Thahir\\Desktop\\folobiz\\school\\Images\\default.jpeg"); It works ,But i want to reduce the URL,so that folobiz is my root folder, i want URL like ~\Images\default.jpeg(Its not working) Pls Replay

      D Offline
      D Offline
      Dave Kreskowiak
      wrote on last edited by
      #2

      This isn't a web app. There's no replacement for "~" outside of a web app. It's always best to use fully qualified filepaths, even if you have to build them from a known folder, like this:

      string DesktopFolder = Environment.GetFolderPath(SpecialFolder.Desktop);
      .
      .
      .
      string imagePath = Path.Combine(DesktopFolder, "folobiz\\\\school\\\\Images\\default.jpg");
      

      A guide to posting questions on CodeProject[^]
      Dave Kreskowiak

      M 1 Reply Last reply
      0
      • M Member 4363680

        Advance Thanks for your kind response i am using PictureBox1 to load image ,below is my code PictureBox1.Image = new Bitmap("C:\\Users\\Thahir\\Desktop\\folobiz\\school\\Images\\default.jpeg"); It works ,But i want to reduce the URL,so that folobiz is my root folder, i want URL like ~\Images\default.jpeg(Its not working) Pls Replay

        L Offline
        L Offline
        Lost User
        wrote on last edited by
        #3

        As Dave replied, that particular notation is reserved for web-apps. You can write a short method that replaces the "~" character with the path of the running executable, similar to this;

        public static string ToRelativePath(string source)
        {
        return source.Replace("~",
        System.IO.Path.GetDirectoryName(
        System.Reflection.Assembly.GetEntryAssembly().Location));
        }

        I are Troll :suss:

        1 Reply Last reply
        0
        • D Dave Kreskowiak

          This isn't a web app. There's no replacement for "~" outside of a web app. It's always best to use fully qualified filepaths, even if you have to build them from a known folder, like this:

          string DesktopFolder = Environment.GetFolderPath(SpecialFolder.Desktop);
          .
          .
          .
          string imagePath = Path.Combine(DesktopFolder, "folobiz\\\\school\\\\Images\\default.jpg");
          

          A guide to posting questions on CodeProject[^]
          Dave Kreskowiak

          M Offline
          M Offline
          Member 4363680
          wrote on last edited by
          #4

          Thank you for your kind replay

          1 Reply Last reply
          0
          • M Member 4363680

            Advance Thanks for your kind response i am using PictureBox1 to load image ,below is my code PictureBox1.Image = new Bitmap("C:\\Users\\Thahir\\Desktop\\folobiz\\school\\Images\\default.jpeg"); It works ,But i want to reduce the URL,so that folobiz is my root folder, i want URL like ~\Images\default.jpeg(Its not working) Pls Replay

            L Offline
            L Offline
            Lost User
            wrote on last edited by
            #5

            Use AppDomain.CurrentDomain.BaseDirectory

            1 Reply Last reply
            0
            Reply
            • Reply as topic
            Log in to reply
            • Oldest to Newest
            • Newest to Oldest
            • Most Votes


            • Login

            • Don't have an account? Register

            • Login or register to search.
            • First post
              Last post
            0
            • Categories
            • Recent
            • Tags
            • Popular
            • World
            • Users
            • Groups