Error executing template "Designs/Web/Paragraph/Gallery.cshtml"
System.IO.DirectoryNotFoundException: Could not find a part of the path 'e:\dynamicweb.net\solutions\Skabertrangweb\nijmegenmarchen.net.dynamicweb-cms.com\files\Images\Web\Galleries\95'.
at System.IO.__Error.WinIOError(Int32 errorCode, String maybeFullPath)
at System.IO.FileSystemEnumerableIterator`1.CommonInit()
at System.IO.FileSystemEnumerableIterator`1..ctor(String path, String originalUserPath, String searchPattern, SearchOption searchOption, SearchResultHandler`1 resultHandler, Boolean checkHost)
at System.IO.Directory.EnumerateFiles(String path, String searchPattern, SearchOption searchOption)
at CompiledRazorTemplates.Dynamic.RazorEngine_c6e4ddb3ff804fb3baa909bac5f21bf6.Execute() in e:\dynamicweb.net\solutions\Skabertrangweb\nijmegenmarchen.net.dynamicweb-cms.com\files\Templates\Designs\Web\Paragraph\Gallery.cshtml:line 26
at RazorEngine.Templating.TemplateBase.RazorEngine.Templating.ITemplate.Run(ExecuteContext context, TextWriter reader)
at RazorEngine.Templating.RazorEngineService.RunCompile(ITemplateKey key, TextWriter writer, Type modelType, Object model, DynamicViewBag viewBag)
at RazorEngine.Templating.RazorEngineServiceExtensions.<>c__DisplayClass16_0.b__0(TextWriter writer)
at RazorEngine.Templating.RazorEngineServiceExtensions.WithWriter(Action`1 withWriter)
at Dynamicweb.Rendering.Template.RenderRazorTemplate()
1 @using System.Drawing
2 @using System.Text
3 @using System.Drawing.Imaging
4 @using System.IO
5
6 @{
7 string Folder = GetString("Item.Folder");
8 string FileLinkText = GetString("Item.FileLinkText");
9 string EmptyFolderMsg = GetString("Item.EmptyFolderMsg");
10 string Layout = !string.IsNullOrWhiteSpace(GetString("Item.Layout")) ? GetString("Item.Layout") : "Classic";
11 string galleryClass = "gallery gallery"+Layout;
12 int AmountOnPage = GetInteger("Item.AmountOnPage");
13 int columns = GetInteger("Item.NumberOfColumns")>0 ? GetInteger("Item.NumberOfColumns") : 5;
14 int MinMaxWidth = GetInteger("Item.MinMaxWidth");
15 int MinMaxHeight = GetInteger("Item.MinMaxHeight");
16 int NormalMaxWidth = GetInteger("Item.NormalMaxWidth");
17 int NormalMaxHeight = GetInteger("Item.NormalMaxHeight");
18 int count = 0;
19 bool MinForgetAspectRatio = GetBoolean("Item.MinForgetAspectRatio");
20 bool NormalForgetAspectRatio = GetBoolean("Item.NormalForgetAspectRatio");
21 bool HideImageTitle = GetBoolean("Item.HideImageTitle");
22 bool ShowDownloadLink = GetBoolean("Item.ShowDownloadLink");
23
24
25 string filesPath = System.Web.HttpContext.Current.Server.MapPath(""+@Folder.Replace("/", "\\"));
26 var files = Directory.EnumerateFiles(""+filesPath, "*.*", SearchOption.TopDirectoryOnly)
27 .Where(s => s.EndsWith(".jpeg", StringComparison.OrdinalIgnoreCase) || s.EndsWith(".jpg", StringComparison.OrdinalIgnoreCase) || s.EndsWith(".png", StringComparison.OrdinalIgnoreCase));
28
29 string thumbFolder = !MinForgetAspectRatio ? MinMaxWidth.ToString() + "x" + MinMaxHeight.ToString() : "resized"+MinMaxWidth.ToString() + "x" + MinMaxHeight.ToString();
30 string thumbFolderPath = filesPath+"\\"+thumbFolder;
31 string resizedFolder = !NormalForgetAspectRatio ? NormalMaxWidth.ToString() + "x" + NormalMaxHeight.ToString() :"resized"+NormalMaxWidth.ToString() + "x" + NormalMaxHeight.ToString();
32 string resizedFolderPath = filesPath+"\\"+resizedFolder;
33 string galleryElementID = "gallery_" + GetValue("ParagraphID");
34
35 int currentPageNo = 1;
36 if(!string.IsNullOrEmpty(System.Web.HttpContext.Current.Request.QueryString["pageNo"])){
37 int.TryParse(System.Web.HttpContext.Current.Request.QueryString["pageNo"], out currentPageNo);
38 }
39
40 bool isAjaxRequest = !string.IsNullOrEmpty(System.Web.HttpContext.Current.Request.QueryString["isAjax"]);
41 }
42
43 @if(!isAjaxRequest && !Directory.Exists(thumbFolderPath)){
44 DirectoryInfo dt = Directory.CreateDirectory(thumbFolderPath);
45 }
46 @if(!isAjaxRequest && !Directory.Exists(resizedFolderPath)){
47 DirectoryInfo dr = Directory.CreateDirectory(resizedFolderPath);
48 }
49
50 <div class="@galleryClass" id="@galleryElementID">
51
52 @foreach (string p in files.Skip((currentPageNo-1)*AmountOnPage).Take(AmountOnPage))
53 {
54 string imgPath = p.Replace(filesPath, string.Empty);
55 string imagePath = Folder+p.Replace(filesPath, string.Empty).Replace("\\", "/");
56 string imageNameWithExtension = imgPath.Replace("\\", "");
57
58 string[] parts = imageNameWithExtension.Split('.');
59 Image image = Image.FromFile(p);
60 string imageName = Path.GetFileNameWithoutExtension(imageNameWithExtension); //parts.Length==2 ? parts[0] : string.Empty;
61 string imageExtension = Path.GetExtension(imageNameWithExtension); //parts.Length==2 ? parts[1] : string.Empty;
62
63 string thumbFile = thumbFolderPath+"\\" + imageName + imageExtension;
64 string thumbFilePath = Folder+thumbFile.Replace(filesPath, string.Empty).Replace("\\", "/");
65 string resizedFile = resizedFolderPath+"\\" + imageName + imageExtension;
66 string resizedFilePath = Folder+resizedFile.Replace(filesPath, string.Empty).Replace("\\", "/");
67 DateTime dt = File.GetLastWriteTime(p);
68 DateTime dtt = File.GetLastWriteTime(thumbFile);
69 DateTime dtr = File.GetLastWriteTime(resizedFile);
70
71
72
73
74 if(!NormalForgetAspectRatio){
75 if(!File.Exists(resizedFile) || DateTime.Compare(dt, dtr) > 0){
76
77 double imageHeight = image.Height;
78 double imageWidth = image.Width;
79 double imageHeightX = imageHeight / NormalMaxHeight;
80 double imageWidthX = imageWidth / NormalMaxWidth;
81
82 double sizeReduction = imageHeightX > imageWidthX ? imageHeightX : imageWidthX;
83
84 int newImageHeight = sizeReduction>1 ? Convert.ToInt32(imageHeight / sizeReduction) : image.Height;
85 int newImageWidth = sizeReduction>1 ? Convert.ToInt32(imageWidth / sizeReduction) : image.Width;
86
87 using(var newImg = new Bitmap(newImageWidth, newImageHeight)){
88 Graphics g = Graphics.FromImage(newImg);
89 g.DrawImage(image, new Rectangle(0,0,newImageWidth,newImageHeight));
90 newImg.Save(resizedFile, System.Drawing.Imaging.ImageFormat.Bmp);
91 g.Dispose();
92 }
93 }
94 }
95 else{
96 if(!File.Exists(resizedFile) || DateTime.Compare(dt, dtr) > 0){
97 using(Image normal = new Bitmap(image, NormalMaxWidth, NormalMaxHeight)){
98 normal.Save(resizedFile);
99 }
100 }
101
102 }
103 if(MinForgetAspectRatio){
104 if(!File.Exists(thumbFile) || DateTime.Compare(dt, dtt) > 0){
105 using(Image thumb = new Bitmap(image, MinMaxWidth, MinMaxHeight)){
106 thumb.Save(thumbFile);
107 }
108 }
109 }
110 else{
111 if(!File.Exists(thumbFile) || DateTime.Compare(dt, dtt) > 0){
112
113 double imageHeight = image.Height;
114 double imageWidth = image.Width;
115 double imageHeightX = imageHeight / MinMaxHeight;
116 double imageWidthX = imageWidth / MinMaxWidth;
117
118 double sizeReduction = imageHeightX > imageWidthX ? imageHeightX : imageWidthX;
119
120 int newImageHeight = sizeReduction>1 ? Convert.ToInt32(imageHeight / sizeReduction) : image.Height;
121 int newImageWidth = sizeReduction>1 ? Convert.ToInt32(imageWidth / sizeReduction) : image.Width;
122
123 using(Image thumb = new Bitmap(image, newImageWidth, newImageHeight)){
124 thumb.Save(thumbFile);
125 }
126
127 }
128 }
129
130 string id = "LBimgNumber"+count;
131 PropertyItem[] propItems = image.PropertyItems;
132 int counting = 0;
133 string metaTitle = string.Empty;
134
135
136 <div class="LBimg" id="@id">
137 @foreach(PropertyItem propItem in propItems){
138 if(propItem.Id.ToString("x")=="10e"){
139 ASCIIEncoding encodings = new ASCIIEncoding();
140 metaTitle = encodings.GetString(propItem.Value).ToString();
141 metaTitle = metaTitle.Substring(0,metaTitle.Length -1); //fix to remove wierd blackdiamond char at end.
142 }
143 }
144
145
146 @{
147 string title = !string.IsNullOrEmpty(metaTitle) ? metaTitle : imageName;
148 string text = !HideImageTitle ? title : string.Empty;
149 }
150
151 <a href="@resizedFilePath" data-lightbox="@galleryElementID" title="@title">
152 <img src="@thumbFilePath" alt="@title" title="@title"/>
153 </a>
154 <div class="imageContent">
155 @if(!string.IsNullOrEmpty(text)){
156 <span class="imageMetaTitle">@text</span>
157 }
158 @if(!string.IsNullOrWhiteSpace(FileLinkText) && ShowDownloadLink){
159 long fileLength = new FileInfo(p).Length / 1024;
160 string fileSize = "("+image.Width+" x "+image.Height+" - "+fileLength+" kb.)";
161 <span class="imageInfo">@fileSize</span>
162 <a class="imageDlLink" href="@imagePath" download>@FileLinkText</a>
163
164 }
165 </div>
166
167 </div>
168
169
170 count++;
171 image.Dispose();
172 }
173 </div>
174 @if(files.Count()>AmountOnPage){
175 int numberOfPages = (files.Count()+AmountOnPage - 1)/AmountOnPage;
176 string gpID = galleryElementID+"gp";
177
178 <div style="clear:both;" id="@gpID" class="galleryPagination">
179 @for(int pn=1; numberOfPages>=pn; pn++){
180 string cssClass = "notActive";
181 if(pn == currentPageNo) { // If current page
182 cssClass = "active";
183 }
184 <a href="#" data-page="@pn" class="galleryPage @cssClass">@pn</a>
185 }
186 </div>
187 }
188
189
190
191 @if(Layout == "Grid"){
192
193 <style>
194 #@(galleryElementID) {
195
196
197 line-height: 0;
198 -webkit-column-count: @columns;
199 -webkit-column-gap: 10px;
200 -moz-column-count: @columns;
201 -moz-column-gap: 10px;
202 column-count: @columns;
203 column-gap: 10px;
204
205 }
206
207 #@(galleryElementID) img {
208
209 width:100%;
210 height:auto;
211 margin-bottom:10px;
212 }
213
214
215 #@(galleryElementID) .LBimg {
216 float:none;
217 margin-left:0px !important;
218 margin-top:0px !important;
219 margin-right:0px !important;
220 margin-bottom:0px !important;
221 padding:0px;
222 width:100%;
223 position:relative;
224 overflow:hidden;
225 }
226
227 #@(galleryElementID) .LBimg .imageContent {
228
229 position:absolute;
230 left:-9000px;
231 bottom:0px;
232 width:100%;
233 height:25%;
234 min-height:30px;
235 padding-top:10%;
236 padding-left:5%;
237 background-color:yellow;
238
239 }
240
241 </style>
242
243 }
244
245 @if(Layout == "Classic"){
246
247 double lbWidth = 100/columns;
248
249 <style>
250 .LBimg{width:@(lbWidth)%;margin-top:20px;}
251 div.gallery div.LBimg:nth-of-type(@(columns)n+1){clear:both;}
252 .LBimg img{max-width:100%;}
253 </style>
254 }
255
256 <script>
257
258 var skabertrang = {
259 gallery: {
260 init: function(){
261 $(".galleryPagination").on("click", "a.notActive", function(e){
262 e.preventDefault();
263 skabertrang.gallery.getGalleryPage($(this).attr('data-page'), $(this).closest(".galleryPagination").prev(".gallery").attr('id'));
264 skabertrang.gallery.getGalleryPage($(this).attr('data-page'), $(this).closest(".galleryPagination").attr('id'));
265 });
266 },
267 getGalleryPage: function(pageNo, appendToElementId){
268 $.ajax({
269 url: skabertrang.settings.rawUrl,
270 type: "GET",
271 cache: false,
272 data:{ "pageNo": pageNo, "isAjax": true }
273 }).done(function(data){
274 console.log('done');
275 $("#"+appendToElementId).html($(data).find("#"+appendToElementId).html());
276 // Insert new images
277 }).fail(function(error){
278 console.log('error');
279 }).complete(function(e){
280 console.log('complete');
281 });
282 }
283 },
284 utils:{
285 getUrlParamDelimiter: function(querystring){
286 if(querystring.indexOf("?") >= 0){
287 return "&";
288 } else {
289 return "?";
290 }
291 }
292 },
293 settings: {
294
295 }
296 };
297 </script>
298
299 <script>
300 /**
301 TODO: Move this to MasterTemplate
302 NOTICE: Be sure to include it AFTER the skabertrang js library.
303 **/
304
305 skabertrang.settings = {
306 rawUrl: '@GetGlobalValue("Global:Pageview.Url.Raw")'
307 };
308
309 (function(){
310 skabertrang.gallery.init();
311 })();
312 </script>
313