A little advice, when using the file system in ASP.NET, leverage Server.MapPath
:
string[] ssImgs = Directory.GetFiles(Server.MapPath("~/images/movies"));
where ~/images/movies
is the full relative path from the root of the web application.
Secondly, before just grabbing an index of the array, make sure it's actually there. It would be better to change your indexing code to something like this:
Label1.Text = ssImgs.Length >= 1 ? ssImgs[0] : "File 1 not found.";
Label2.Text = ssImgs.Length >= 2 ? ssImgs[1] : "File 2 not found.";
By making these two changes you won't have to worry about getting a DirectoryNotFound
exception or an IndexOutOfRange
exception.