Re: 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".

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


.