473,406 Members | 2,273 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,406 software developers and data experts.

image not rendered when expected

Although I have quite a bit of WinForms experience, I am new to ASP.NET. So
don't be surprised by the elementary question. :)

I am creating a webpage with a dropdown list that allows the user to select
an image from the list. Based on that feedback, the page calls a web service
to grab the requested image (based on an index from the dropdown) and place
it on the local file system. Then it is supposed to update the Image
control on the page by assigning a new path (via the ImageURL method on the
control). But the new image is never rendered. See code snip below.

I verified that the file accessed from the web service was actually placed
in its target location.

Is there some equivalent operation to the "invalidation " of a control that
is done in WinForms to force a redraw? Else, what else might I be missing?

Thanks, Bruce
-----------------------------------------------------------------

protected void ButtonShowImage_Click(object sender, EventArgs e)
{
long index;
byte[] bytes;

index = Convert.ToInt64( DropDownList.SelectedItem.ToString());
asset = m_ServerOld.GetAssetElements(index);
bytes = asset.fileImage;

string fullPath = @"c:\temp\" + asset.originatorName;
string fileSpec = fullPath + @"\" + asset.fileName;
DirectoryInfo target = new DirectoryInfo(fullPath);
if (!target.Exists) target.Create();

using (FileStream fs = new FileStream(fileSpec, FileMode.Create,
FileAccess.Write))
{
fs.Write(bytes, 0, bytes.Length);
}

// ImageBox.ResolveUrl(fileSpec);
ImageBox.ImageUrl = fileSpec;
}
May 3 '06 #1
6 1876
Use "view source" to see the rendered HTML. For now it looks like to me that
you are using the server side location fo the image. Remember that client
side this is not the same drive. You have to proviee the location on the web
site as an URL...

--
Patrice

"Bruce" <co*********@newsgroup.nospam> a écrit dans le message de news:
OV**************@TK2MSFTNGP02.phx.gbl...
Although I have quite a bit of WinForms experience, I am new to ASP.NET.
So don't be surprised by the elementary question. :)

I am creating a webpage with a dropdown list that allows the user to
select an image from the list. Based on that feedback, the page calls a
web service to grab the requested image (based on an index from the
dropdown) and place it on the local file system. Then it is supposed to
update the Image control on the page by assigning a new path (via the
ImageURL method on the control). But the new image is never rendered.
See code snip below.

I verified that the file accessed from the web service was actually placed
in its target location.

Is there some equivalent operation to the "invalidation " of a control
that is done in WinForms to force a redraw? Else, what else might I be
missing?

Thanks, Bruce
-----------------------------------------------------------------

protected void ButtonShowImage_Click(object sender, EventArgs e)
{
long index;
byte[] bytes;

index = Convert.ToInt64( DropDownList.SelectedItem.ToString());
asset = m_ServerOld.GetAssetElements(index);
bytes = asset.fileImage;

string fullPath = @"c:\temp\" + asset.originatorName;
string fileSpec = fullPath + @"\" + asset.fileName;
DirectoryInfo target = new DirectoryInfo(fullPath);
if (!target.Exists) target.Create();

using (FileStream fs = new FileStream(fileSpec, FileMode.Create,
FileAccess.Write))
{
fs.Write(bytes, 0, bytes.Length);
}

// ImageBox.ResolveUrl(fileSpec);
ImageBox.ImageUrl = fileSpec;
}

May 3 '06 #2
ImageBox.ImageUrl = fileSpec;
fileSpec should be a URL and NOT "c:\temp\"... etc..
it should be http://yourdomain/../../yourImage.ext absolute path, relative
path or what ever.

SA
"Bruce" <co*********@newsgroup.nospam> wrote in message
news:OV**************@TK2MSFTNGP02.phx.gbl...
Although I have quite a bit of WinForms experience, I am new to ASP.NET.
So don't be surprised by the elementary question. :)

I am creating a webpage with a dropdown list that allows the user to
select an image from the list. Based on that feedback, the page calls a
web service to grab the requested image (based on an index from the
dropdown) and place it on the local file system. Then it is supposed to
update the Image control on the page by assigning a new path (via the
ImageURL method on the control). But the new image is never rendered.
See code snip below.

I verified that the file accessed from the web service was actually placed
in its target location.

Is there some equivalent operation to the "invalidation " of a control
that is done in WinForms to force a redraw? Else, what else might I be
missing?

Thanks, Bruce
-----------------------------------------------------------------

protected void ButtonShowImage_Click(object sender, EventArgs e)
{
long index;
byte[] bytes;

index = Convert.ToInt64( DropDownList.SelectedItem.ToString());
asset = m_ServerOld.GetAssetElements(index);
bytes = asset.fileImage;

string fullPath = @"c:\temp\" + asset.originatorName;
string fileSpec = fullPath + @"\" + asset.fileName;
DirectoryInfo target = new DirectoryInfo(fullPath);
if (!target.Exists) target.Create();

using (FileStream fs = new FileStream(fileSpec, FileMode.Create,
FileAccess.Write))
{
fs.Write(bytes, 0, bytes.Length);
}

// ImageBox.ResolveUrl(fileSpec);
ImageBox.ImageUrl = fileSpec;
}

May 3 '06 #3
You are saving the image on the hard drive of the server. The browser
doesn't have access to read from the hard drive of the server.

You have to save the file in a folder in the web root, so that the
browser can access the file via IIS.

If you save the file to Server.MapPath("somefolder/image.gif"), it will
be saved in a folder in the web, perhaps something like
"c:\inetpub\wwwroot\mysite\somefolder\image.gi f" It will be available to
the browser using the url "somefolder/image.gif".

Bruce wrote:
Although I have quite a bit of WinForms experience, I am new to ASP.NET. So
don't be surprised by the elementary question. :)

I am creating a webpage with a dropdown list that allows the user to select
an image from the list. Based on that feedback, the page calls a web service
to grab the requested image (based on an index from the dropdown) and place
it on the local file system. Then it is supposed to update the Image
control on the page by assigning a new path (via the ImageURL method on the
control). But the new image is never rendered. See code snip below.

I verified that the file accessed from the web service was actually placed
in its target location.

Is there some equivalent operation to the "invalidation " of a control that
is done in WinForms to force a redraw? Else, what else might I be missing?

Thanks, Bruce
-----------------------------------------------------------------

protected void ButtonShowImage_Click(object sender, EventArgs e)
{
long index;
byte[] bytes;

index = Convert.ToInt64( DropDownList.SelectedItem.ToString());
asset = m_ServerOld.GetAssetElements(index);
bytes = asset.fileImage;

string fullPath = @"c:\temp\" + asset.originatorName;
string fileSpec = fullPath + @"\" + asset.fileName;
DirectoryInfo target = new DirectoryInfo(fullPath);
if (!target.Exists) target.Create();

using (FileStream fs = new FileStream(fileSpec, FileMode.Create,
FileAccess.Write))
{
fs.Write(bytes, 0, bytes.Length);
}

// ImageBox.ResolveUrl(fileSpec);
ImageBox.ImageUrl = fileSpec;
}

May 3 '06 #4
Hi Bruce,

As for the image rendering issue, I agree with other member's suggetion
that we need to use http based web url to reference the image source in web
page instead of local physical file path. Physical path is not accessible
for pages published over internet web site/virtual directory. Therefore,
for your scenario, I think you can consider the following options:

1. Is it possible that you move the temp image file folder under your web
application's application root folder or that folder is alreay under such
place. Thus, we can use http based full url path to reference those temp
images. Or we can also use relative path for images. In addition, for
ASP.NET server control, there is a trick that we can use "~/..." style url
to reference the ASP.NET application's root dir. So if we put the temp
image dir under application's root dir, we can set our Image server
control's url like below:

ImageBox.ImageUrl = "~/tempImagedir/xxx.gif";
2. for dynamic created or retrieved images, we can also use httphandler to
expose it so that our page can reference that dynamicc generated image
through the httphandler's url. e.g:

<img src="myimageHandler.img?imgid=xxxxx" />

And here are some good tech article discussing on use httphandler to output
image content:

#A simple ASP.NET photo album
http://weblogs.asp.net/bleroy/archiv...08/424714.aspx

#Using ASP.NET HTTP Handlers to create a photo album
http://www.microsoft.com/belux/msdn/...et/httphandler.
mspx

In addition, for ASP.NET developing, you can have a look at the following
websites since there're many good resource there:

http://msdn.microsoft.com/asp.net/

http://www.asp.net/Default.aspx?tabindex=0&tabid=1

Hope this helps.

Regards,

Steven Cheng
Microsoft Online Community Support
==================================================

When responding to posts, please "Reply to Group" via your newsreader so
that others may learn and benefit from your issue.

==================================================
This posting is provided "AS IS" with no warranties, and confers no rights.

Get Secure! www.microsoft.com/security
(This posting is provided "AS IS", with no warranties, and confers no
rights.)


May 4 '06 #5
Thank you to all three of you who gave answers!

You were right on. I tacitly assumed that the ASP.NET process would
magically do a mapping from my server file location to a URL in the HTML it
emits, but in retrospect that's probably not even feasible. I've got it
now.

Thanks, Bruce

"Göran Andersson" <gu***@guffa.com> wrote in message
news:eo**************@TK2MSFTNGP03.phx.gbl...
You are saving the image on the hard drive of the server. The browser
doesn't have access to read from the hard drive of the server.

You have to save the file in a folder in the web root, so that the browser
can access the file via IIS.

If you save the file to Server.MapPath("somefolder/image.gif"), it will be
saved in a folder in the web, perhaps something like
"c:\inetpub\wwwroot\mysite\somefolder\image.gi f" It will be available to
the browser using the url "somefolder/image.gif".

Bruce wrote:
Although I have quite a bit of WinForms experience, I am new to ASP.NET.
So don't be surprised by the elementary question. :)

I am creating a webpage with a dropdown list that allows the user to
select an image from the list. Based on that feedback, the page calls a
web service to grab the requested image (based on an index from the
dropdown) and place it on the local file system. Then it is supposed to
update the Image control on the page by assigning a new path (via the
ImageURL method on the control). But the new image is never rendered.
See code snip below.

I verified that the file accessed from the web service was actually
placed in its target location.

Is there some equivalent operation to the "invalidation " of a control
that is done in WinForms to force a redraw? Else, what else might I be
missing?

Thanks, Bruce
-----------------------------------------------------------------

protected void ButtonShowImage_Click(object sender, EventArgs e)
{
long index;
byte[] bytes;

index = Convert.ToInt64( DropDownList.SelectedItem.ToString());
asset = m_ServerOld.GetAssetElements(index);
bytes = asset.fileImage;

string fullPath = @"c:\temp\" + asset.originatorName;
string fileSpec = fullPath + @"\" + asset.fileName;
DirectoryInfo target = new DirectoryInfo(fullPath);
if (!target.Exists) target.Create();

using (FileStream fs = new FileStream(fileSpec, FileMode.Create,
FileAccess.Write))
{
fs.Write(bytes, 0, bytes.Length);
}

// ImageBox.ResolveUrl(fileSpec);
ImageBox.ImageUrl = fileSpec;
}

May 4 '06 #6
Hey Bruce,

You can also have a look at the httphandler approach to expose image stream
mentioned in my last reply.

Hope that also helps.

Regards,

Steven Cheng
Microsoft Online Community Support
==================================================

When responding to posts, please "Reply to Group" via your newsreader so
that others may learn and benefit from your issue.

==================================================
This posting is provided "AS IS" with no warranties, and confers no rights.

Get Secure! www.microsoft.com/security
(This posting is provided "AS IS", with no warranties, and confers no
rights.)

May 4 '06 #7

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

4
by: boclair | last post by:
Is this a known problem with IE6? I have a provisional two column layout, the left menu column is positioned absolute. The contents column is positioned relative. The contents column has an...
0
by: Greg Christie | last post by:
I think I have a somewhat unique situation here, so I thought I should post it for the few poor souls who run across it and try to google it like I did. First of all, I was getting the following...
8
by: Lars Netzel | last post by:
Hey! I wrote a message yersterday and got some good answers and have now managed to generate a nice image. The problem is that it's all generated in an Images.Aspx file and I don't really want...
11
by: Tomek Toczyski | last post by:
What is the best way to attach a caption to an image in xhtml? I can attach a caption to a table by a "<caption>" tag but I would like to do sth similar to an image. How to do it in a natural...
0
by: David | last post by:
Hello all. I am trying to implement my first server control and have run into two problems that I cannot solve. I need the assistance of someone with more experience. My goal was to create an...
1
by: | last post by:
I've built an application that scrapes JPG images of webpages and PDF instances of those webpages automatically from an RSS feed. References to the scraped resources are persisted to our database....
5
by: Roy Smith | last post by:
Be kind to me, I'm a CSS newbie... I've been playing with drupal, building a web site (hyc-test.org). I started with the "sky" theme, but didn't like the way it rendered list items in menus. ...
4
by: Ryan Knopp | last post by:
This is an update from a previous post, I just simplified the code. It seems that I can't get the image map to work with IE7. The page is located here http://www.theknopps.com/test.html and the...
3
by: RN1 | last post by:
A user control has an image & a few Labels. When I view the ASPX page that uses this user control in my local machine, the image can be seen but when I upload the ASPX page & the ASCX page to my...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.