How to create Image helper in asp.net mvc?

[spacer height =”5px”]

How to create Image helper in asp.net mvc?

public class ImagesHelper

{

        //private static IList<string> AllowedImageFormats = new List<string> { ".jpg", ".jpeg", ".png", ".gif" };

 

public static void GetImagesWithThumb(string PhysicalPath, List<string> AllowedImageFormats, out List<string> Images, out List<string> Thumbs)

  {

DirectoryInfo dir = new DirectoryInfo(PhysicalPath);

 Images = new List<string>();

 Thumbs = new List<string>();

try

   {

var Files = dir.EnumerateFiles("*.*", SearchOption.TopDirectoryOnly);

 

                foreach (FileInfo Image in Files)

    {

                    if (AllowedImageFormats.Contains(Image.Extension.ToLower()))

                    {

                        if (Image.Name.ToLower().Contains("_tm."))

                        {

 

                            Thumbs.Add(Image.Name);

                        }

                        else

                        {

                            Images.Add(Image.Name);

                        }

                    }

    }

   }

catch (DirectoryNotFoundException)

   {

                

   }

  }

 

public static void GetImages(string PhysicalPath, List<string> AllowedImageFormats, out List<string> Images)

  {

 Images = new List<string>();

DirectoryInfo dir = new DirectoryInfo(PhysicalPath);

try

   {

var Files = dir.EnumerateFiles("*.*", SearchOption.TopDirectoryOnly);

 

foreach (FileInfo Image in Files)

    {

                    if (AllowedImageFormats.Contains(Image.Extension.ToLower()))

                    {

                        Images.Add(Image.Name);

                    }

    }

   }

catch (DirectoryNotFoundException)

   {

 

   }

  }

 }

(Visited 84 times, 1 visits today)

Leave a Reply

Your email address will not be published. Required fields are marked *