image not rendered when expected |
|
Author |
Message |
ManojSingh

|
Posted: Wed May 03 12:56:40 CDT 2006 |
Top |
ASP.Net >> 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;
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;
}
Web Programming124
|
|
|
|
 |
Patrice

|
Posted: Wed May 03 12:56:40 CDT 2006 |
Top |
ASP.Net >> image not rendered when expected
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
> 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;
>
> 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;
> }
>
|
|
|
|
 |
MSDN

|
Posted: Wed May 03 13:15:14 CDT 2006 |
Top |
ASP.Net >> image not rendered when expected
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
> 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;
>
> 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;
> }
>
|
|
|
|
 |
guffa

|
Posted: Wed May 03 16:01:16 CDT 2006 |
Top |
ASP.Net >> image not rendered when expected
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;
>
> 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;
> }
>
>
|
|
|
|
 |
stcheng

|
Posted: Wed May 03 22:25:36 CDT 2006 |
Top |
ASP.Net >> image not rendered when expected
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.)
|
|
|
|
 |
Bruce

|
Posted: Wed May 03 22:26:48 CDT 2006 |
Top |
ASP.Net >> image not rendered when expected
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
> 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;
>>
>> 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;
>> }
|
|
|
|
 |
stcheng

|
Posted: Thu May 04 01:40:43 CDT 2006 |
Top |
ASP.Net >> image not rendered when expected
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.)
|
|
|
|
 |
|
|