Problem med at vise billeder.
Jeg er ved at forsøge mig med at lave et galleri/fotoalbum. Jeg har min aspx-side, min codebehind fil og en mappe 'pics' med billeder.Hvis jeg lægger mappen roden som "C:\pics\", kan jeg få siden til at vise billederne uden problemer, men det duer ikke rigtigt, når jeg skal uploade det til min hjemmeside. Derfor har jeg prøvet med MapPath, men selv om jeg, så vidt jeg kan vurdere, får den korrekte path, vil siden ikke vise billederne.
Håber min forklaring giver mening. Er der nogen, der har et bud på, hvad jeg gør galt?
Her er koden fra codebehind filen (c#):
public partial class _Gallery : System.Web.UI.Page
{
ArrayList fileList = new ArrayList();
string path;
int currentPic = 0;
protected void Page_Load(object sender, EventArgs e)
{
// VIRKER IKKE
path = this.MapPath(this.ToString());
path = path.Substring(0, path.LastIndexOf('\\')+1);
path += "pics\\";
// VIRKER
// path = "c:\\pics\\";
RetrieveFileList();
if (!this.IsPostBack)
{
ViewState["currentPic"] = 0;
}
else
{
currentPic = (int) ViewState["currentPic"];
}
AssignPictures();
}
private void RetrieveFileList()
{
DirectoryInfo dir = new DirectoryInfo (path);
try
{
FileInfo[] files = dir.GetFiles();
foreach (FileInfo fi in files)
{
if (fi.Extension.Equals(".jpg"))
{
fileList.Add(fi.Name);
}
}
}
catch (Exception e) { }
}
private void AssignPictures()
{
try
{
imgMain.ImageUrl = path + (string)fileList[currentPic];
Label1.Text = imgMain.ImageUrl;
Label2.Text = path + (string)fileList[currentPic];
ImageButton1.ImageUrl = path + "thumb_" + (string)fileList[currentPic];
ImageButton2.ImageUrl = path + "thumb_" + (string)fileList[currentPic + 1];
ImageButton3.ImageUrl = path + "thumb_" + (string)fileList[currentPic + 2];
ImageButton4.ImageUrl = path + "thumb_" + (string)fileList[currentPic + 3];
}
catch (Exception e1){}
ViewState["currentPic"] = currentPic;
}
protected void Button1_Click(object sender, EventArgs e)
{
if (currentPic > 0)
currentPic--;
AssignPictures();
}
protected void Button2_Click(object sender, EventArgs e)
{
if (currentPic < (fileList.Count/2)-1)
currentPic++;
AssignPictures();
}
}