I have image control.I want to load image from my specific path.
i have a code in page behind
string imagePath ="E:/DotNetProjects/Templates/Default/icons/Computer.png";
imgEditor.ImageUrl = imagePath;
imgEditor.AlternateText = "Unable To Find Image";
path is exist and image is also available but always load alternate text.
imgEditor is my image control ID.
Plz help to catch my mistake.Thanks.
Just put your image in solution(any folder or even in root) and path image uri from that (with src in asp page) like :
src="Templates/Default/icons/Computer.png"
The imagePath is a filesystem path... you need a URL... (something like http://...). The URL must be accessible from the browser i.e. you need to setup your webserver (IIS) to serve the respective path... I would recommend putting the image into the solution/project so that the URL is relative...
Related
I am setting an absolute path to Image control. This path is having spaces. After assigning the path to ImageURL property of the Image ASP.NET control, it does not show the image. I don't have option to remove the spaces as it is the requirement. Also, this path is outside the root directory(There is basically a FileUpload control that takes the file and then I am assigning the path to Image control).
Firstly is it possible to do. If yes how? Below are the code blocks relevant to the question
Server Code
target.ImageUrl = strImagePath;
where target is the Image control id
File Path: C:\Users\WebMaster\Downloads\2 States Full Vedio Songs 720p Bluray Encodded By(Khanz)\Screenshoot\vlcsnap-2014-05-17-13h22m13s103.png
Rendered HTML
<img id="target" alt="[Jcrop Example]" src="C:\Users\WebMaster\Downloads\2%20States%20Full%20Vedio%20Songs%20720p%20Bluray%20Encodded%20By(Khanz)\Screenshoot\vlcsnap-2014-05-17-13h22m13s103.png" />
Thanks in advance for your help.
Thanks Manson. I was so wrong. The image has to be hosted on the web server to access. Actually, this is what I want to cut down. Uploading the image from local user path to server folder was taking time. But I forgot the basics. Re-writing your comment as answer.
I am trying to programmatically set image of ImageButton.
My code is below:
String path="Images/1/";
path= path + string.Format("{0}", _ds.Tables[_bplp.SqlEntityX].DefaultView[0]["Photograph"]);
ImageButton1.ImageUrl = path;
I am saving images in my site folder Images/1 , and storing image name in database.
Problem lies when I am trying to display image in ImageButton.
Although after debugging it, path variable is taking correct path of image
as "Images/1/imagename.jpg", but still ImageButton doesnot show image.
Also, Images folder lies at root level of website.
try this
replace this
String path="Images/1/";
with
String path="~/Images/1/";
Also, you can try ResolveUrl();
ImageButton1.ImageUrl = ResolveUrl("~/" + path);
Problem was in my webconfig file, I had set incorrect site folder url in that, above code is working fine now
Thanks to all
I am developing a C# web project. I run it on the local web server.
I draw. I show image as follows:
bitmap.Save(Server.MapPath("diagram.jpg"), ImageFormat.Jpeg);
Image1.ImageUrl = ResolveUrl("diagram.jpg");
I don't see new image. Only old one, which I had after changing image name
(Say, I change diagram.jpg to diagram2.jpg).
Browser is Firefox.
The design page in C# is simple. Just Image and few TextBoxes on the page.
No UpdatePanel and such.
Something with caching... But how to fight with that...
But how to fight with that.
Always use a separate path / name. Pug a GUID somewhere. Simple like that. Different file can not be cached.
I'm not sure what ResolveUrl does, but try adding a querystring to the image url so that the page always gets a "fresh" file. Something like this:
Image1.ImageUrl = ResolveUrl(string.Format("diagram.jpg?v={0}", Guid.NewGuid()));
You can alternative write the image file as
diagram.jpg?ver=2
to keep the same image file, but force the browser to update it.
If Image has Same name and URL browser picks the image from the cache and displays the same for faster loading of the pages.
Even if you change the image server side the same cached image is displayed until you clear the cache of the browser. You can use query string to change image url like below.
Image1.ImageUrl = ResolveUrl("diagram.jpg?" + DateTime.Now.Ticks.ToString());
I have an image in one of my project folders:
Lets say its in:
~/App_Themes/Default/images/SomeImage.png
I want to load this image into a System.Drawing.Image, how do I do that?
If I try using the FromFile method of the Image class:
Image img = Image.FromFile("~/App_Themes/Default/images/SomeImage.png", true);
I get a FileNotFoundException.
I have read some suggesting to store the image into the Server but that's not an option. Is there any way to load this into the Image?
You seem to be using a relative path instead of a file path to locate the image. Try this:
var path = #"~/App_Themes/Default/images/SomeImage.png";
using (Image img = Image.FromFile(Server.MapPath(path)))
{
do some stuff
}
I had a similar problem. The problem for me was that I accidentally added Image folder inside of App_Code folder. I did not updated the code accordingly and therefore I was getting exception.
As soon I removed the Image folder out of App_Code folder, the problem was resolved.
Of course I could have updated also the path in the code.
If I get any image tag from any website I want to be able to get the full path to the image file.
eg:
src="http://www.example.com/images/foo.gif" //This is fine
src="images/foo.gif"
src="/images/foo.gif"
for the bottom two src attributes, how can i get the full image path?
I want to treat the src attribute universally and always get the full path of an image.
if you have the url of the page that holds the image, and the url of the image, you can use new Uri(pageUri, imageUri) to combine the urls and get the full url