How can i load image from Application Folder by using Short url( like ~\Images\default.jpeg ,but not working) to PictureBox
-
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
-
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
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 -
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
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:
-
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 KreskowiakThank you for your kind replay
-
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