image not rendered when expected

B

Bruce

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;
}
 
P

Patrice

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...
 
?

=?ISO-8859-1?Q?G=F6ran_Andersson?=

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.gif" It will be available to
the browser using the url "somefolder/image.gif".
 
S

Steven Cheng[MSFT]

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/archive/2005/09/08/424714.aspx

#Using ASP.NET HTTP Handlers to create a photo album
http://www.microsoft.com/belux/msdn/nl/community/columns/desmet/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.)
 
B

Bruce

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 said:
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.gif" It will be available to
the browser using the url "somefolder/image.gif".
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;
}
 
S

Steven Cheng[MSFT]

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.)
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,580
Members
45,055
Latest member
SlimSparkKetoACVReview

Latest Threads

Top