Pages

Saturday, September 17, 2011

File Manager Update

Noticed a slight improvement with how data is populated and return.
If the file isn’t an image the width and height is equal to zero. Non-image files (png, jpg, bmp, gif, jpeg) width and height are set to 128 and a generic image is assign.
The testing for whether file’s width and height are zero was performed will displaying the image from JavaScript. This update moves the testing from JavaScript to when the files are being populated from the C# handler: fileManagerHandler.ashx.
C# Code below:
   1: protected void populate()
   2: {
   3:     using (adminDBEntities contxt = new adminDBEntities())
   4:     {
   5:         string relPath = requestVals.currentFolder;
   6:  
   7:         IEnumerable<zFileInfo> media = contxt.Medias.Where(m => m.path == relPath).OrderBy(m => m.name).Select(m => new zFileInfo
   8:                {
   9:                    id = m.ID,
  10:                    name = m.name,
  11:                    ext = m.MediaType.ext,
  12:                    path = m.path,
  13:                    w = m.width == 0 ? 128 : m.width,
  14:                    h = m.height == 0 ? 128 : m.height
  15:                });
  16:  
  17:         folder.files = media.ToList();
  18:     }
  19: }

This will reduce the JavaScript size and rendering files for display and much cleaner.

No comments:

Post a Comment