Show all image in Folder on Server
Hello everybody, I want to show all image in Folder on Server by using Image control. I using a string array to save all file name and when I click button "show", the image is showed on Image control by order. Here my code.
//String array to save filename
public string[] nfile=new string[100];
int i ;
int j;//to show by order
protected void Button3_Click(object sender, EventArgs e)
{
//Load all image to string array
i = 0;
btnNext.Enabled = true;
foreach (string file in Directory.GetFiles(Server.MapPath("Sample") + "\\", "*.jpg"))
{
string namefile = file.Remove(0, 60);//"d:\DZHosts\LocalUser\toanhoi\www.buiductoan.somee.com\Sample\","");
namefile.Trim();//namefile="a.jpg"
nfile[i] = namefile;
i++;
}
j = 0;
}
//Button show
if (j <= i)
{
ImgView.ImageUrl ="~/Sample" + nfile[j];
j++;
}
But If I click show button, nfile array wil return null.I don't understand.Can you help me to fix?