0
Reply

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

Shah Shishir

Shah Shishir

Oct 10 2008 3:16 AM
4.8k
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.