I just use simple code to load image in asp.net image control, it works fine in IE but firefox does't show image. the line of code is:
string path = "F:\\Image\\";
string img = "header-firefox.PNG";
Image1.ImageUrl = path + img;
and the error is:
The address wasn't understood
Firefox doesn't know how to open this address, because the protocol (f) isn't associated with any program.
even file:///F:/Image/header-firefox.PNG path is not working in code even.
Do you mean that is the path you see in the HTML? I understand that the backslashes are escaped in C# but surely in the HTML the path should be "\\192.172.60.05\Users\4133.Png"?
Have you tried navigating to \192.172.60.05\Users\4133.Png directly in Firefox?
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'm trying to load several images from URLs to a pictureBox.
My problem is that "pictureBox.Load(URL)" or "pictureBox.ImageLocation = URL" doesn't work.
I don't know why, I think it is because the URL doesn't have an extension like .jpg.
private void button3_Click(object sender, EventArgs e)
{
string URL = "https://internetmarke.deutschepost.de/internetmarke/franking/image/view/1403556118.do";
pictureBox1.ImageLocation = URL;
}
The URL works in Firefox and the picture is shown. But in IE it doesn't work and I think that's the same reason why it's not working in .NET.
IE says "unknown filetype" and wants to download a "1403556118.do" file.
In C# I only get a red X in the pictureBox.
When I first try to load it in IE, it works in the pictureBox (IE cache?)
Does somebody knows another possibility to load this images to a pictureBox?
EDITED: Added sample code.
Today I've tested the code on three different computers and with different Internet connections; Home DSL, Company DSL and a UMTS/3G Surf-Stick. All without any proxies and also tested without virusscan.
In every single scenario it didn't work, same as I wrote in my first post.
After I accessed some of the URLs in Firefox or IE, the images of these URLs showed up in my application. All others remained a red X.
Is there any different (old-school^^) method to load these images, like downloading the HTTP-Stream into a byte array and then copy this into pictureBox.Image or something?
Dino
pictureBox1.ImageLocation = "http://www.micoequipment.com/products/large/MF_260_l.jpg"; //should work
Make sure that image is accessible via web browser (test it before). Also, please make sure that you are calling correct picture box :)
It works for me.
#Andrew:
pictureBox1.ImageLocation = "http://www.micoequipment.com/products/large/MF_260_l.jpg";
This Works!
pictureBox1.ImageLocation = "https://internetmarke.deutschepost.de/internetmarke/franking/image/view/1403556118.do";
This doesn't work!
Your link and my link both work in Firefox. But my link doesn't work in IE and it doesn't work in .NET and in the pictureBox.
This should work since you're loading an image from a remote URL:
pictureBox1.Load(URL);
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 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...