tree view properties in web application - asp.net

i open a web application in visual studio 2008...
it contain the tree view properties as,
TreeNodeType type;
type = new TreeNodeType();
type.Type = "folder";
type.ImageUrl = "Images/" + "folder.gif";
type.ExpandedImageUrl = "Images/" + "folderopen.gif";
i dont know how this image tag comes.. and how to chage that...

If your image directory is in the root of the application you should use the tilde character '~' at the start:
type.ImageUrl = "~/Images/" + "folder.gif";
you should include the full path to the image from the root, so if the image is in Content/Images:
type.ImageUrl = "~/Content/Images/" + "folder.gif";
At runtime, the '~/' is translated to the correct path to the image and rendered to the page.
If this is not working, you need to post the relevant markup of the page and the codebehind. Alos, it would help if you rightclick the image in IE and slect properties. You can see the expected path there. Or open the page in Firefox, with the Firebug Addon installed, right click the image and select Inspect Element. This will show you the path that was rendered and you can compare this to where the image actually is in your project.

Related

asp.net image tag displays image only in visual studio debugging mode

I'd like to compile and deploy a finished image that will efficiently display the image I've set up in the following line:
imgtag.ImageUrl = "..\..\Images\IMG_Temp\" & "PVATmp" & Trim(CStr(mlnk)) & ".jpg"
This line displays the image smoothly and quickly in the designer when I debug, but not after the program is compiled and displayed on an IIS Web server instance. For one thing, the image is displayed on a postback in designer, but that condition in the deployed version cannot show the image. I have to refresh the page.
Any ideas?
The path the image is displayed from is relative. ..\..Means you are moving 2 levels up from where you are now. "where you are now" likely means something different while debugging than it does when deployed.
Also, does your variable mlnk have a value?
Try to use like this:
imgtag.ImageUrl = Server.MapPath("~/Images/IMG_TEMP/PVATmp" + Trim(CStr(mlnk)) + ".jpg";
This is in case when you IMAGES folder is located in the root path

How to display image on web page from ADODB.stream object

I have a classic ASP question.
I need to show images on my webpage.
But because of the security reasons, I cannot simply put all of my images in the images folder in my website folder and I need to put them outside of my website folder.
For example, my website folder is located at:
C:\Inetpub\wwwroot\mysite\
But I need to put images (which I want to show on my web pages) at:
C:\images\
I am trying to use ADODB.stream object to pull the images using ASP vb codes as shown below:
<%
Response.ContentType = "image/png"
Set adoStream = Server.CreateObject("ADODB.Stream")
adoStream.Open
adoStream.Type = 1
FPath = "C:\images\1.png"
adoStream.LoadFromFile FPath
Response.BinaryWrite adoStream.Read
adoStream.Close
Set adoStream = Nothing
Response.End
%>
When I launch this webpage in internet explorer, the page shows a File Download window/message for downloading the image file "1.png" rather than displaying the image on the web page.
How can I fix the code to show the image on the web page rather than downloading the image file?
That code generates an image as the return type, so there is no HTML to display the image in, if you call this code directly say it's called image.asp then you would do something like this in another page that displays HTML.
<img src="image.asp" />
This will call your code and output the raw image binary as this is what <img> expects.
If you want to produce multiple images from the file system or database pass a querystring parameter such as ?id=yourimage and change the code to select different images.

Image control in asp.net?

In web application, i am trying to display image in .aspx page, for that i write code like this in page_load event ,
Image1.ImageUrl = #"C:\Users\Public\Pictures\Sample Pictures\Koala.JPEG";
but image is not displaying, can you help me thank you.
there is problem with the path of image ...you need to give relative path for image rather than physical path
something like this
Image1.ImageUrl="~/Images/Bird1.jpg"
here image is in the Images folder of the application. i.e.which is part of project
First create a Images folder in your Solution Explorer. Then store your image in that folder and refer like as below.
Example
<asp:Image ID="Image1" runat="server" ImageUrl="~/Images/Bird1.jpg" />
Check in deatil : Image Control Example
You cannot use your local path as the path to your image, instead place the web site url with a relative path to the image

why can't I programmatically set the imageurl on an Image control?

I have an ASP.NET 2010 app and am trying something very simple. I use Image control through out and basically wanted to say, before I assign an image to it (from a class) look for the image; if it's not there, use the default no_image jpeg I have. I have verified the image is there ad nauseam. If I set the property in the IDE to point to this image, it'll display. However, if I set it programmatically, even if I hard-code the path programmatically, it doesn't show.
Forgettign about getting the proper path and all that, (of which Ive tried several things) I can;t even hard code the relative path. Here I copied & pasted the relative path from the properties window...
Image1.ImageUrl = "~/UploadedPictures/Users/no_profile_picture.jpg"
This doesn't work. It translates into src="../../UploadedPictures/Users/no_profile_picture.jpg" which is correct but the image doesn't display.
If I hardcode the absolute path it doesn't work either...
Image1.ImageUrl = "C:\Inetpub\wwwroot\myApp\UploadedPictures\Users\no_profile_picture.jpg"
You have to use a virtual path. Try adding ~ before your path.
Image1.ImageUrl = "~/UploadedPictures/Users/no_profile_picture.jpg"

Image URL is correct but image not showing

I have a website on GoDaddy. All permissions are set correctly and the image DOES exist. However when the page loads the image for the item selected does not show. Here is my code
imagepath = "~/spaimages/" + currentSpaModel.Name.ToString() + ".png";
if (File.Exists(Server.MapPath(imagepath)))
{ this.spaimage.ImageUrl = Server.MapPath(imagepath); }
spaimage is an ASP control and thr URL that the image is set to is D:\hosting\xxxxxxx\calspas\spaimages\modelname.png
What am I doing wrong.
The file path D:\hosting\xxxxxxx\calspas\spaimages\modelname.png is the folder where the image resides on the web server. You are sending this as the <img> tag's src attribute, which tells the browser, "Go get the image at D:\hosting\xxxxxxx\calspas\spaimages\modelname.png." The browser cannot go off to the D drive of the web server, so it looks on its own D drive for that folder and image.
What you mean to do is to have the <img> tag's src attribute be a path to a folder on the website. You're just about there - just drop the Server.MapPath part when assigning the image path to the ImageUrl property. That is, instead of:
this.spaimage.ImageUrl = Server.MapPath(imagepath);
Do:
this.spaimage.ImageUrl = imagepath;
See if that works.
Thanks
Often, if an image "does not show" (I assume a red-x-equivalent is being displayed to show "broken image"), I right-click the broken image, copy the URL and open the URL in a separate browser window.
This way, when the image is being generated by some script, I see any error text that the script might have shown. If not, the real image would be displayed.
In addition, add an else block to the
if (File.Exists(Server.MapPath(imagepath)))
like
else
{
Response.Write(string.Format(
"File does not exist at '{0}'.",
Server.MapPath(imagepath)));
}
For debugging purposes.

Resources