Wednesday, 10 July 2013

Directory(Get all folders and files from a directory)

//this code written if image or any path file from database is not present in Repository(or any folder it will match) folder of application
            if (!string.IsNullOrEmpty(eventinfo.ImagePath))
            {
                ArrayList files = new ArrayList();
                String[] fileNameFromRepository = Directory.GetFiles("" + Server.MapPath(@"~/Repository/EventGallery/ImageGallery") + @"\" + eventinfo.Id +  "\\Images");
                for (int iFile = 0; iFile < fileNameFromRepository.Length; iFile++)
                    files.Add(new FileInfo(fileNameFromRepository[iFile]).Name);
                int countImage = 0;
                foreach (var FileName in fileNameFromRepository)
                {
                    if (new FileInfo(eventinfo.ImagePath).Name == new FileInfo(FileName).Name)
                        countImage++;
                }
                if (countImage == 0)
                    imgLogo.ImageUrl = "~/Images/NoImage.jpg";
            }

No comments:

Post a Comment