private string AddImage(string s, string inSubpage) { Image currentImage; int imgHeight, imgWidth; MyImageInfo iInfo = new MyImageInfo(); Cache.Remove(s); if(Cache[s] == null) { FileStream fs = new FileStream(s, FileMode.Open, FileAccess.Read, FileShare.Read); iInfo.size = (int)fs.Length/1024; try { currentImage = Image.FromStream(fs); } catch(OutOfMemoryException e) { return "There was an error loading file information for " + Path.GetFileName(s); } iInfo.height = currentImage.Height; iInfo.width = currentImage.Width; currentImage.Dispose(); fs.Close(); iInfo.lastModified = File.GetCreationTime(s).ToString("d", null); Trace.Write("Cache insert",s); Cache.Insert(s, iInfo, new CacheDependency(s)); } else { Trace.Write("Cache hit", s); Trace.Write(Cache[s].ToString()); iInfo = (MyImageInfo)Cache[s]; } ScaleFactorCalculations(out imgHeight, out imgWidth, iInfo.height, iInfo.width); string filename = Path.GetFileName(s); string PathVar = Path.Combine(BaseImagePath, Path.Combine(inSubpage, filename)); PathVar = PathVar.Replace("\\", "/"); if(filename.Length > 20) filename = filename.Substring(0,17) + "..."; StringBuilder htmlout = new StringBuilder(); htmlout.Append("<a href=\""); htmlout.Append(PathVar); htmlout.Append("\">"); htmlout.Append("<img src=\"thumbnail.ashx?img="); htmlout.Append(PathVar); htmlout.Append("&w="); htmlout.Append(imgWidth); htmlout.Append("&h="); htmlout.Append(imgHeight); htmlout.Append("\" width=\""); htmlout.Append(imgWidth); htmlout.Append("\" height=\""); htmlout.Append(imgHeight); htmlout.Append("\" alt=\""); htmlout.Append(filename); htmlout.Append("\" /></a>"); htmlout.Append("<p class=\"galleryimageinfo\">"); htmlout.Append("<a href=\""); htmlout.Append(PathVar); htmlout.Append("\">"); if(ShowName) { htmlout.Append(filename); htmlout.Append("<br />"); } if(ShowSize) { htmlout.Append(iInfo.width); htmlout.Append(" x "); htmlout.Append(iInfo.height); htmlout.Append("<br />"); } if(ShowFileSize) { htmlout.Append(iInfo.size); htmlout.Append("KB<br />"); } if(ShowDate) { htmlout.Append("Uploaded: "); htmlout.Append(iInfo.lastModified); } htmlout.Append("</a></p>"); return htmlout.ToString(); }
private string AddImage(string s, string inSubpage) { Image currentImage; int imgHeight, imgWidth; MyImageInfo iInfo = new MyImageInfo(); Cache.Remove(s); if (Cache[s] == null) { FileStream fs = new FileStream(s, FileMode.Open, FileAccess.Read, FileShare.Read); iInfo.size = (int)fs.Length / 1024; try { currentImage = Image.FromStream(fs); } catch (OutOfMemoryException e) { return("There was an error loading file information for " + Path.GetFileName(s)); } iInfo.height = currentImage.Height; iInfo.width = currentImage.Width; currentImage.Dispose(); fs.Close(); iInfo.lastModified = File.GetCreationTime(s).ToString("d", null); Trace.Write("Cache insert", s); Cache.Insert(s, iInfo, new CacheDependency(s)); } else { Trace.Write("Cache hit", s); Trace.Write(Cache[s].ToString()); iInfo = (MyImageInfo)Cache[s]; } ScaleFactorCalculations(out imgHeight, out imgWidth, iInfo.height, iInfo.width); string filename = Path.GetFileName(s); string PathVar = Path.Combine(BaseImagePath, Path.Combine(inSubpage, filename)); PathVar = PathVar.Replace("\\", "/"); if (filename.Length > 20) { filename = filename.Substring(0, 17) + "..."; } StringBuilder htmlout = new StringBuilder(); htmlout.Append("<a href=\""); htmlout.Append(PathVar); htmlout.Append("\">"); htmlout.Append("<img src=\"thumbnail.ashx?img="); htmlout.Append(PathVar); htmlout.Append("&w="); htmlout.Append(imgWidth); htmlout.Append("&h="); htmlout.Append(imgHeight); htmlout.Append("\" width=\""); htmlout.Append(imgWidth); htmlout.Append("\" height=\""); htmlout.Append(imgHeight); htmlout.Append("\" alt=\""); htmlout.Append(filename); htmlout.Append("\" /></a>"); htmlout.Append("<p class=\"galleryimageinfo\">"); htmlout.Append("<a href=\""); htmlout.Append(PathVar); htmlout.Append("\">"); if (ShowName) { htmlout.Append(filename); htmlout.Append("<br />"); } if (ShowSize) { htmlout.Append(iInfo.width); htmlout.Append(" x "); htmlout.Append(iInfo.height); htmlout.Append("<br />"); } if (ShowFileSize) { htmlout.Append(iInfo.size); htmlout.Append("KB<br />"); } if (ShowDate) { htmlout.Append("Uploaded: "); htmlout.Append(iInfo.lastModified); } htmlout.Append("</a></p>"); return(htmlout.ToString()); }