0
Answer

Index was outside the bounds of the array in asp.net using c#

Shah Shishir

Shah Shishir

16y
4.8k
1
Dear sir,

When i load / run my application this code at that time i m gatting this error in code.
Error := Index was outside the bounds of the array. so i think my code is somewhere wrong. so plz correct my code and help me as early as possible..hear i give my code.

Code
======================================
 string PathToFolder = Server.MapPath("~/banners/" + Label2.Text);
        string[] RotatingImgFiles = Directory.GetFiles(PathToFolder);
        Random Rnd = new Random();
        int n = new Random().Next(0,Count);
        FileInfo file = new FileInfo(RotatingImgFiles[Rnd.Next(0,n)]);
        bannerimage.ImageUrl = ("~/banners/" + Label2.Text + "/" + file.Name);
===============================================

So plz help me as early as possible.
Thanks with regards in advance.

[ Shah Shishir.]
Prasnet.net Pvt. Ltd.
Ahmedabad.