473,770 Members | 4,999 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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 "invalidati on " 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.Se lectedItem.ToSt ring());
asset = m_ServerOld.Get AssetElements(i ndex);
bytes = asset.fileImage ;

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

using (FileStream fs = new FileStream(file Spec, FileMode.Create ,
FileAccess.Writ e))
{
fs.Write(bytes, 0, bytes.Length);
}

// ImageBox.Resolv eUrl(fileSpec);
ImageBox.ImageU rl = fileSpec;
}
May 3 '06 #1
6 1893
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*********@ne wsgroup.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 "invalidati on " 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.Se lectedItem.ToSt ring());
asset = m_ServerOld.Get AssetElements(i ndex);
bytes = asset.fileImage ;

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

using (FileStream fs = new FileStream(file Spec, FileMode.Create ,
FileAccess.Writ e))
{
fs.Write(bytes, 0, bytes.Length);
}

// ImageBox.Resolv eUrl(fileSpec);
ImageBox.ImageU rl = fileSpec;
}

May 3 '06 #2
ImageBox.ImageU rl = 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*********@ne wsgroup.nospam> wrote in message
news:OV******** ******@TK2MSFTN GP02.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 "invalidati on " 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.Se lectedItem.ToSt ring());
asset = m_ServerOld.Get AssetElements(i ndex);
bytes = asset.fileImage ;

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

using (FileStream fs = new FileStream(file Spec, FileMode.Create ,
FileAccess.Writ e))
{
fs.Write(bytes, 0, bytes.Length);
}

// ImageBox.Resolv eUrl(fileSpec);
ImageBox.ImageU rl = 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\www root\mysite\som efolder\image.g if" 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 "invalidati on " 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.Se lectedItem.ToSt ring());
asset = m_ServerOld.Get AssetElements(i ndex);
bytes = asset.fileImage ;

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

using (FileStream fs = new FileStream(file Spec, FileMode.Create ,
FileAccess.Writ e))
{
fs.Write(bytes, 0, bytes.Length);
}

// ImageBox.Resolv eUrl(fileSpec);
ImageBox.ImageU rl = 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.ImageU rl = "~/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="myimageHan dler.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.co m> wrote in message
news:eo******** ******@TK2MSFTN GP03.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\www root\mysite\som efolder\image.g if" 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 "invalidati on " 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.Se lectedItem.ToSt ring());
asset = m_ServerOld.Get AssetElements(i ndex);
bytes = asset.fileImage ;

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

using (FileStream fs = new FileStream(file Spec, FileMode.Create ,
FileAccess.Writ e))
{
fs.Write(bytes, 0, bytes.Length);
}

// ImageBox.Resolv eUrl(fileSpec);
ImageBox.ImageU rl = 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
8279
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 image floated right. The placement is there in IE6 but not the image. It does not matter whether the DTD is strict or transitional
0
2051
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 error when trying to hit one of my pages... --------------------------------------------------------------------- Invalid URI: There is an invalid sequence in the string. ---------------------------------------------------------------------
8
1472
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 that. I am writing a WebControl Library and I want to generate everything from there... In the Render Sub of the Control I output some HTML and there I need to reference to a file in the <img> element, is there anyway to NOT have to point to a...
11
4210
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 way? -tt.
0
1889
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 input button that would allow for both text and an image on it. I am attempting to accomplish this by basing off of the asp:button control. I added a property for the image url and one to determine if the image is displayed on the left or right...
1
2236
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. I've also built an administrative interface that allows someone to scroll through a datalist of the JPG images of the page and to delete the unwanted items. The JPG previews of the webpage are rendered in several sizes: iconic, mid-sized 600px...
5
9854
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. Spcifically, it started with: list-style-image: url(../../misc/menu-expanded.png);
4
4734
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 source below. I can't seem to figure out why IE7 won't recognize the image map. Thanks for your help Ryan
3
1557
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 remote server, the ASPX page shows the Labels but it doesn't show the image. Strangely the source code of the ASPX page includes the image code. What could the problem be? Thanks,
0
9592
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9425
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10231
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10059
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
9871
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
8887
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
5452
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
3972
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
3
2817
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.