with a linkbutton of "Previous picture" and "next Picture".
my problem is that the image control doesn't show the image although it gets the right path ( i think so )
i use VS2005. with explorer 6.0
i want to display an image that placed in the path C:\Inetpub\wwwroot\Images\bluehills.jpg through the code.
when i use the properies page to set the imageUrl to "C:\inetpub\wwwroot\Images\Bluehills.jpg" it works great.
but when i do it from the code by setting imageUrl to "http://localhost:1096/Images/Bluehills.jpg" it doesn't work - i cant see nothing on the image control.
if i write the address :
"http://localhost:1096/Default.aspx" in the browser myself i see the same problem - a blank image control
if i try to show the image on the browser, with this address :
"http://localhost:1096/Images/Bluehills.jpg"
i get this error:
------------------------------------------------------------------------------
Server Error in '/' Application.
--------------------------------------------------------------------------------
The resource cannot be found.
Description: HTTP 404. The resource you are looking for (or one of its dependencies) could have been removed, had its name changed, or is temporarily unavailable. Please review the following URL and make sure that it is spelled correctly.
Requested URL: /Images/Bluehills.jpg
--------------------------------------------------------------------------------
Version Information: Microsoft .NET Framework Version:2.0.50727.832; ASP.NET Version:2.0.50727.832
-------------------------------------------------------------------------------
Does that has to do with the location of my project ? cause it is placed in
"C:\Documents and Settings\asaf\My Documents\Visual Studio 2005\Projects"
using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.IO;
namespace Chapter3PicView
{
public partial class _Default : System.Web.UI.Page
{
private String[] m_arrImageNames;
private String m_StrImageDirectory = @"C:\inetpub\wwwroot\Images";
private int imageNum = 0;
protected void Page_Load(object sender, EventArgs e)
{
// if it is the first load ( not refresh )
if (!IsPostBack)
{
// if there are images in the folder
if (GetImages())
{
// Set the ImageURL of Image1 to the first image that was found
Image1.ImageUrl = GetImageURL(m_arrImageNames[0]);
}
}
}
protected void LinkButton1_Click(object sender, EventArgs e)
{
ChangeImage(-1);
}
protected void LinkButton2_Click(object sender, EventArgs e)
{
ChangeImage(1);
}
private void ChangeImage(int intChange)
{
// Get the list of images
if (GetImages())
{
// update image index
imageNum += intChange;
// show image
Image1.ImageUrl = GetImageURL(m_arrImageNames[imageNum]);
}
}
private bool GetImages()
{
// Get the image filenames
m_arrImageNames = Directory.GetFiles(m_StrImageDirectory);
// Make sure there are images to display
if (m_arrImageNames.Length == 0)
return false;
return true;
}
private String GetImageURL(String StrImageFilePath)
{
String Str1 = Request.Url.GetLeftPart(UriPartial.Authority);
//String Str2 = Request.ApplicationPath;
String Str3 = @"/Images/";
String Str4 = StrImageFilePath.Substring(m_StrImageDirectory.Length +1);
return Str1 + Str3 + Str4;
}
}
}
The markup code is :
<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="Default.aspx.cs" Inherits="Chapter3PicView._Default" %> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml" > <head runat="server"> <title>Untitled Page</title> </head> <body> <form id="form1" runat="server"> <div> <asp:LinkButton ID="LinkButton1" runat="server" onclick="LinkButton1_Click" Width="98px">Previous Image</asp:LinkButton> <asp:Image ID="Image1" runat="server" Height="363px" ImageUrl="C:\inetpub\wwwroot\Images\Bluehills.jpg" Width="336px" /> <asp:LinkButton ID="LinkButton2" runat="server" onclick="LinkButton2_Click">Next Image</asp:LinkButton> </div> </form> </body> </html>
could it be i have two different problems? :
1. showing image on control
2. showing image on browser
how do i solve them?
thanks
*Always use code tags:) =>
This post has been edited by PsychoCoder: 04 November 2007 - 07:04 AM

New Topic/Question
Reply




MultiQuote





|