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
Related
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 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?
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...
I have an webbrowser control on my form. I am able display html files in that control. But my page contains some images if i give absolute path to it then images are displayed. But if i give relative path then images are not shown in the pages.
I have HtmlPages folder located at bin folder.
And i am assigning
FileStream source = new FileStream(#"..\HtmlPages\supportHtml.html", FileMode.Open, FileAccess.Read);
webBrowser.DocumentStream = source;
If i assign D:\myapp\bin\HtmlPages\file.png then there is no problem.
My images are stored in same folder. If i open html files with webbrowser then images are displayed.
What is the correct path to set ??
Relative paths are relative to WebBrowser.Url. Which, when you load the HTML directly, either through DocumentStream or DocumentText is about:blank. That's not going to help WB find the file, you must use an absolute path. Tinkering with the Url property is not an option.
Consider using Html Agility Pack to tinker with the file content before assigning it to the DocumentText property. Use Path.GetFullPath() to translate relative paths.