Its Done

Thursday, 8 January 2009 15:50 by frimbooze

I done some more work on the photo display widget. I have done the following today. I would say I have done a fair days work.

blog_08012009

  • Fixed the upload handler , now returns text/html instead of text/plain, the upload control uses a normal submission inside and temp Iframe. When the content type was set as ‘plain’ the returned JSON would be encapsulated insde <pre> html tags causing a eval error.
  • Since the above was fixed had the upload form refresh the datastore to include the new images.
  • I added a click listener to the dataview control, when an image is clicked it will load a new window positioned at the top of the screen(useful for the large screen shots) with the image inside, though not as pretty as say ‘lightbox’, it works.
  • Implemented a pass key on the image upload form a security to stop unwanted uploads.
  • Fixed a CSS issue with the dataview, overflows of floated elements.

Be the first to rate this post

  • Currently 0/5 Stars.
  • 1
  • 2
  • 3
  • 4
  • 5

Been Learning

Wednesday, 7 January 2009 20:13 by frimbooze

I had a very happy Christmas and new year but now its back to work and learning. I purchased Learning Ext JS from packet publishing, the book came with a password protected pdf version which is always a plus with me.

image

I rate this book very highly for a beginner like me with plenty of well explained explanations. My two great criticisms

(1) Used coldfusion and PHP , should stick to one backend language.

(2) Not enough Meat once the beginners tag ends.

For the price and with the inclusion of an e-book and removing the beginner tag on one of the harder JavaScript libraries its a must buy and if you pirate it burn in hell.

The result of my first successful (nearly finished) project with the Ext JS library and .net background

photoframe

The can be found on the root page (aka my portal) at http://www.icomefromthenet.net.

It allows images (jpg,gif,png) to be uploaded , these images are stored in a sql-lite DB. The Json stream is loaded at page start with the data filtered on the client side using the Ext JS store widget. An generic ASHX handler is used to retrieve each image from the DB, optional thumbnail function is included as well.

Areas Used from the Libary

  1. DataVew and x-templates
  2. FormPanel, normal Panel
  3. FileUpload control
  4. DB Bound combo Box
  5. Json Store and Http Proxy.

Still to complete

  1. Fix the DataVew CSS
  2. Upload more photos
  3. A Better selection of photos onload.
  4. Maybe Less Blue.

Be the first to rate this post

  • Currently 0/5 Stars.
  • 1
  • 2
  • 3
  • 4
  • 5

A custom User Control - Photos

Saturday, 12 January 2008 07:19 by Frimbob

Overview: I was looking for the ability to print out a page of photos without having to mannualy create a page, to this end I have created a custom user control that will search a set folder at run-time for images under sub-directories, with each catagory being its own catagory.

The challange included.

  1. Methods to paraise the directories and a relation data-store
  2. Developing a function that would print each catagory, and the Correct relative Paths.
  3. Develop the HTML  that would allow an assingable number of photos on each line.
  4. CSS techniques to make them look good.

Part 1 -The Properties

[code:vb] </p> <font size="2"></font><font size="2">&lt;%<font size="2" color="#0000ff">@</font><font size="2"> </font><font size="2" color="#a31515">Control</font><font size="2"> </font><font size="2" color="#ff0000">Language</font><font size="2" color="#0000ff">=&quot;VB&quot;</font><font size="2"> </font><font size="2" color="#ff0000">ClassName</font><font size="2" color="#0000ff">=&quot;PhotoDisplay&quot;</font><font size="2"> %&gt; &lt;%<font size="2" color="#0000ff">@</font><font size="2"> </font><font size="2" color="#a31515">Import</font><font size="2"> </font><font size="2" color="#ff0000">Namespace</font><font size="2" color="#0000ff">=&quot;System.IO&quot;</font><font size="2"> %&gt; </font><font size="2"></font></font><font size="2"><font size="2">&lt;%<font size="2" color="#0000ff">@</font><font size="2"> </font><font size="2" color="#a31515">Import</font><font size="2"> </font><font size="2" color="#ff0000">Namespace</font><font size="2" color="#0000ff">=&quot;BlogEngine.Core&quot;</font><font size="2"> %&gt; </font><font size="2"> <p> &lt;%<font size="2" color="#0000ff">@</font><font size="2"> </font><font size="2" color="#a31515">Import</font><font size="2"> </font><font size="2" color="#ff0000">Namespace</font><font size="2" color="#0000ff">=&quot;System.Data&quot;</font><font size="2"> %&gt;</font> </p> </font></font></font></font><font size="2" color="#0000ff"> <p> &lt;<font size="2" color="#a31515">script</font><font size="2"> </font><font size="2" color="#ff0000">runat</font><font size="2" color="#0000ff">=&quot;server&quot;&gt;</font> </p> </font><font size="2"> <p> &nbsp; </p> <p> <font size="2" color="#008000">&#39;Image Folder Property</font> </p> </font><font size="2"> <p> <font size="2" color="#0000ff">Private</font><font size="2"> _imageFolderPath </font><font size="2" color="#0000ff">As</font><font size="2"> </font><font size="2" color="#0000ff">String</font><font size="2"> = </font><font size="2" color="#a31515">&quot;../pics/photos/&quot;</font> </p> </font><font size="2"><font size="2" color="#0000ff">Private</font><font size="2"> intItemsPerRow </font><font size="2" color="#0000ff">As</font><font size="2"> </font><font size="2" color="#0000ff">Integer</font><font size="2"> = 4 </font><font size="2"> <p> &nbsp; </p> <p> <font size="2" color="#0000ff">Public</font><font size="2"> </font><font size="2" color="#0000ff">Property</font><font size="2"> ItemsPerRow() </font><font size="2" color="#0000ff">As</font><font size="2"> </font><font size="2" color="#0000ff">Integer</font> </p> </font></font><font size="2"> <p> <font size="2" color="#0000ff">Get</font> </p> </font><font size="2"><font size="2" color="#0000ff">Return</font><font size="2"> intItemsPerRow </font><font size="2"><font size="2" color="#0000ff">End</font><font size="2"> </font><font size="2" color="#0000ff">get</font><font size="2"> <font size="2" color="#0000ff">Set</font><font size="2">(</font><font size="2" color="#0000ff">byVal</font><font size="2"> value </font><font size="2" color="#0000ff">AS</font><font size="2"> </font><font size="2" color="#0000ff">Integer</font><font size="2">) </font><font size="2"></font></font><font size="2"><font size="2"> <p> intItemsPerRow = value </p> <font size="2" color="#0000ff">End</font><font size="2"> </font><font size="2" color="#0000ff">Set</font><font size="2"> </font><font size="2"><font size="2" color="#0000ff">End</font><font size="2"> </font><font size="2" color="#0000ff">Property </font><font size="2" color="#0000ff"> <p> &nbsp; </p> </font></font></font></font></font></font><font size="2"> <p> <font size="2" color="#0000ff">Public</font><font size="2"> </font><font size="2" color="#0000ff">Property</font><font size="2"> ImageFolderPath() </font><font size="2" color="#0000ff">As</font><font size="2"> </font><font size="2" color="#0000ff">String</font> </p> </font><font size="2"> <p> <font size="2" color="#0000ff">Get</font> </p> </font><font size="2"><font size="2" color="#0000ff">Return</font><font size="2"> _imageFolderPath </font><font size="2"> <p> <font size="2" color="#0000ff">End</font><font size="2"> </font><font size="2" color="#0000ff">Get</font> </p> </font></font><font size="2"><font size="2" color="#0000ff">Set</font><font size="2">(</font><font size="2" color="#0000ff">ByVal</font><font size="2"> value </font><font size="2" color="#0000ff">As</font><font size="2"> </font><font size="2" color="#0000ff">String</font><font size="2">) </font><font size="2"> <p> _imageFolderPath = value </p> <p> <font size="2" color="#0000ff">End</font><font size="2"> </font><font size="2" color="#0000ff">Set</font> </p> </font></font><font size="2"> <p> <font size="2" color="#0000ff">End</font><font size="2"> </font><font size="2" color="#0000ff">Property</font> </p> </font> <p> [/code]

Nothing too Special Here 2 public properties that can be set on the tag, the first being the root folder for the images and the second the number of photos on each row. 

Part 2 - The Data Structures

[code:vb] </p> <font size="2" color="#0000ff"> <p> Private<font size="2"> </font><font size="2" color="#0000ff">Function</font><font size="2"> FolderListArray(</font><font size="2" color="#0000ff">ByVal</font><font size="2"> _imageFolderPath </font><font size="2" color="#0000ff">As</font><font size="2"> </font><font size="2" color="#0000ff">String</font><font size="2">) </font><font size="2" color="#0000ff">As</font><font size="2"> </font><font size="2" color="#0000ff">Object</font> </p> </font><font size="2"></font><font size="2" color="#0000ff">Dim</font><font size="2"> photoCollection </font><font size="2" color="#0000ff">As</font><font size="2"> </font><font size="2" color="#0000ff">New</font><font size="2"> NameValueCollection</font><font size="2"> <p> <font size="2" color="#0000ff">Dim</font><font size="2"> j </font><font size="2" color="#0000ff">As</font><font size="2"> </font><font size="2" color="#0000ff">Integer</font> </p> </font><font size="2"> <p> <font size="2" color="#0000ff">Dim</font><font size="2"> aryChildFolder() </font><font size="2" color="#0000ff">As</font><font size="2"> </font><font size="2" color="#0000ff">String</font> </p> </font><font size="2"> <p> <font size="2" color="#0000ff">Dim</font><font size="2"> strFileName </font><font size="2" color="#0000ff">As</font><font size="2"> </font><font size="2" color="#0000ff">String</font> </p> </font><font size="2"> <p> <font size="2" color="#0000ff">Dim</font><font size="2"> strFolderName </font><font size="2" color="#0000ff">As</font><font size="2"> </font><font size="2" color="#0000ff">String</font> </p> </font><font size="2"> <p> <font size="2" color="#0000ff">Dim</font><font size="2"> SplitAry1() </font><font size="2" color="#0000ff">As</font><font size="2"> </font><font size="2" color="#0000ff">String</font> </p> </font><font size="2"> <p> <font size="2" color="#0000ff">Dim</font><font size="2"> SplitAry2() </font><font size="2" color="#0000ff">AS</font><font size="2"> </font><font size="2" color="#0000ff">String</font> </p> </font><font size="2"> <p> <font size="2" color="#0000ff">Dim</font><font size="2"> i </font><font size="2" color="#0000ff">As</font><font size="2"> </font><font size="2" color="#0000ff">Integer</font><font size="2"> </font><font size="2" color="#008000">&#39;increment each directory</font> </p> </font><font size="2"> <p> <font size="2" color="#0000ff">Dim</font><font size="2"> l </font><font size="2" color="#0000ff">As</font><font size="2"> </font><font size="2" color="#0000ff">Integer</font> </p> </font><font size="2"> <p> &nbsp; </p> <p> <font size="2" color="#008000">&#39;store the directories here</font> </p> </font><font size="2"> <p> <font size="2" color="#0000ff">if</font><font size="2"> (Directory.Exists(MapPath(_imageFolderPath)) ) </font><font size="2" color="#0000ff">Then</font> </p> </font><font size="2"></font><font size="2" color="#0000ff">Dim</font><font size="2"> aryDirectories() </font><font size="2" color="#0000ff">As</font><font size="2"> </font><font size="2" color="#0000ff">String</font><font size="2"> = Directory.GetDirectories(MapPath(_imageFolderPath))</font><font size="2"> <p> <font size="2" color="#0000ff">Dim</font><font size="2"> length </font><font size="2" color="#0000ff">As</font><font size="2"> </font><font size="2" color="#0000ff">Integer</font><font size="2"> = aryDirectories.Length</font> </p> </font><font size="2" color="#0000ff">For</font><font size="2"> i = 0 </font><font size="2" color="#0000ff">To</font><font size="2"> length - 1</font><font size="2"> <p> <font size="2" color="#008000">&#39;create a ary for the childfolders file list</font> </p> </font><font size="2"> <p> aryChildFolder = Directory.GetFiles(aryDirectories(i), <font size="2" color="#a31515">&quot;*.jpg&quot;</font><font size="2">) </font><font size="2" color="#008000">&#39;assign the list</font> </p> </font><font size="2"></font><font size="2" color="#0000ff">For</font><font size="2"> j = 0 </font><font size="2" color="#0000ff">To</font><font size="2"> aryChildFolder.Length - 1</font><font size="2"> <p> strFileName = Path.GetFileName(aryChildFolder(j)) </p> <p> strFolderName = Path.GetDirectoryName(aryChildFolder(j)) </p> SplitAry1 = strFolderName.Split(</font><font size="2" color="#a31515">&quot;\&quot;</font><font size="2">)</font><font size="2"> SplitAry2 = _imageFolderPath.Split(<font size="2" color="#a31515">&quot;/&quot;</font><font size="2">) </font><font size="2"> <p> strFolderName =<font size="2" color="#a31515">&quot; &quot;</font> </p> </font></font><font size="2"></font><font size="2" color="#0000ff">For</font><font size="2"> l = 0 </font><font size="2" color="#0000ff">To</font><font size="2"> SplitAry2.Length - 1 </font><font size="2" color="#0000ff">Step</font><font size="2"> 1</font><font size="2"> <p> <font size="2" color="#0000ff">If</font><font size="2"> (SplitAry2(l).Length &gt; 0 </font><font size="2" color="#0000ff">And</font><font size="2"> SplitAry2(l) &lt;&gt; </font><font size="2" color="#a31515">&quot;..&quot;</font><font size="2">) </font><font size="2" color="#0000ff">Then</font> </p> </font><font size="2"> <p> strFolderName = strFolderName &amp; <font size="2" color="#a31515">&quot;/&quot;</font><font size="2"> &amp; SplitAry2(l) </font><font size="2" color="#008000">&#39;equal to current</font> </p> </font><font size="2"> <p> <font size="2" color="#0000ff">End</font><font size="2"> </font><font size="2" color="#0000ff">If</font> </p> </font><font size="2"></font><font size="2" color="#0000ff">Next</font><font size="2"> l</font><font size="2"> <p> strFolderName = strFolderName &amp; <font size="2" color="#a31515">&quot;/&quot;</font><font size="2"> &amp; SplitAry1(SplitAry1.Length - 1)</font><font size="2" color="#008000">&#39; the childDirectory</font> </p> </font><font size="2"> <p> strFolderName = strFolderName.Trim() </p> <p> strFolderName = strFolderName.Replace(<font size="2" color="#a31515">&quot;~&quot;</font><font size="2">, </font><font size="2" color="#a31515">&quot;&quot;</font><font size="2">) </font><font size="2" color="#008000">&#39;only work if ~ char exists in string which sould only be at the start</font> </p> </font><font size="2">strFolderName = strFolderName.TrimStart(</font><font size="2" color="#a31515">&quot;/&quot;</font><font size="2">)</font><font size="2"> <p> strFolderName = strFolderName.Trim() </p> <p> <font size="2" color="#008000">&#39;add the items to the collection</font> </p> </font><font size="2"> <p> photoCollection.Add(strFolderName, strFileName) </p> </font><font size="2" color="#0000ff">Next</font><font size="2"> j</font><font size="2"></font><font size="2" color="#0000ff">Next</font><font size="2"> i</font><font size="2"> <p> &nbsp; </p> <p> <font size="2" color="#008000">&#39;Dim jjjj = HttpContext.Current.Request.ApplicationPath</font> </p> </font><font size="2"> <p> <font size="2" color="#008000">&#39;aryDirectories(i)</font> </p> </font><font size="2"> <p> &nbsp; </p> <p> <font size="2" color="#008000">&#39;return a the collection</font> </p> </font><font size="2"> <p> FolderListArray = photoCollection </p> <p> <font size="2" color="#0000ff">Else</font> </p> </font><font size="2"> <p> <font size="2" color="#008000">&#39;return an empty collection</font> </p> </font><font size="2"> <p> FolderListArray = photoCollection </p> <p> <font size="2" color="#0000ff">End</font><font size="2"> </font><font size="2" color="#0000ff">If</font> </p> </font><font size="2"> <p> <font size="2" color="#0000ff">End</font><font size="2"> </font><font size="2" color="#0000ff">Function</font> </p> </font> <p> [/code]

This function will return a NamedValueCollection , the basic structure has each subdirectory as the key with each graphics file assoicated to that key, since a directory requires a unique name all keys will be unique.

The MapPath function is used to resolve a full path from the application root the  _imageFolderPath property is not enough for the Directory.Get methods.

The Directory.GetFiles(aryDirectories(i), "*.jpg") ensures that only JPEG files are save into the collection.

The above code can utilize parameters with the "~" or the relative ".." pass to it, the above code creates a key that drives from the root of the applicaiton to the parent directory . The images however must be organised into a subdirectory even if you just call it e.g "allphotos".

If there are no files found or issue with the paths, the named colleciton will be return as empty and an error will print.

Part 3 - The Html

[code:vb] </p> <font size="2" color="#0000ff"><font size="2" color="#0000ff"> <p> Private<font size="2" color="#000000"> </font><font size="2" color="#0000ff">Function</font><font size="2" color="#000000"> CreateHTML(</font><font size="2" color="#0000ff">ByRef</font><font size="2" color="#000000"> aryCollection </font><font size="2" color="#0000ff">As</font><font size="2" color="#000000"> </font><font size="2" color="#0000ff">Object</font><font size="2" color="#000000">) </font><font size="2" color="#0000ff">As</font><font size="2" color="#000000"> </font><font size="2" color="#0000ff">String</font> </p> </font><font size="2"> <p> <font size="2" color="#008000">&#39;create the stringbuilder</font> </p> </font><font size="2"> <p> <font size="2" color="#0000ff">Dim</font><font size="2"> strHtmlString </font><font size="2" color="#0000ff">As</font><font size="2"> </font><font size="2" color="#0000ff">New</font><font size="2"> StringBuilder </font><font size="2" color="#008000">&#39;to build the HTML String</font> </p> </font><font size="2"> <p> <font size="2" color="#0000ff">Dim</font><font size="2"> aryValues() </font><font size="2" color="#0000ff">As</font><font size="2"> </font><font size="2" color="#0000ff">String</font><font size="2"> </font><font size="2" color="#008000">&#39;Holds an array of Keys</font> </p> </font><font size="2"> <p> <font size="2" color="#0000ff">Dim</font><font size="2"> i </font><font size="2" color="#0000ff">As</font><font size="2"> </font><font size="2" color="#0000ff">Integer</font><font size="2"> </font><font size="2" color="#008000">&#39;loop counter </font> </p> </font><font size="2"> <p> <font size="2" color="#0000ff">Dim</font><font size="2"> intNumbOfRows </font><font size="2" color="#0000ff">As</font><font size="2"> </font><font size="2" color="#0000ff">Integer</font><font size="2"> </font><font size="2" color="#008000">&#39;loop counter</font> </p> </font><font size="2"> <p> <font size="2" color="#0000ff">Dim</font><font size="2"> k </font><font size="2" color="#0000ff">As</font><font size="2"> </font><font size="2" color="#0000ff">Integer</font><font size="2"> </font><font size="2" color="#008000">&#39;loop counter</font> </p> </font><font size="2"> <p> &nbsp; </p> <p> <font size="2" color="#008000">&#39;Preview Image Html Start</font> </p> </font><font size="2"> <p> strHtmlString.Append(<font size="2" color="#a31515">&quot;&lt;div&gt;&quot;</font><font size="2">) </font><font size="2" color="#008000">&#39;opening tag</font> </p> </font><font size="2">strHtmlString.Append(<font size="2" color="#a31515">&quot;&lt;span style=&quot;&quot;background: #b4afa3; padding: 0 1px; border: 1px solid #dcd7c8; &quot;&quot;&gt;&quot;</font><font size="2">) </font><font size="2">strHtmlString.Append(<font size="2" color="#a31515">&quot;&lt;img id=&quot;&quot;imgPreview&quot;&quot; alt=&quot;&quot;PreviewImage&quot;&quot; style=&quot;&quot;padding:5px; background:white;&quot;&quot; /&gt;&quot;</font><font size="2">) strHtmlString.Append(<font size="2" color="#a31515">&quot;&lt;/span&gt;&quot;</font><font size="2">) </font><font size="2"></font></font><font size="2"><font size="2"> <p> strHtmlString.Append(<font size="2" color="#a31515">&quot;&lt;/div&gt;&quot;</font><font size="2">) </font><font size="2" color="#008000">&#39;close the opening tag</font> </p> </font></font></font></font><font size="2">strHtmlString.Append(<font size="2" color="#a31515">&quot;&lt;br /&gt;&quot;</font><font size="2">) </font><font size="2"> <p> <font size="2" color="#008000">&#39;preview Image Stop</font> </p> </font></font><font size="2"> <p> &nbsp; </p> <p> <font size="2" color="#008000">&#39;Catagory Html Start</font> </p> </font><font size="2"> <p> <font size="2" color="#0000ff">For</font><font size="2"> </font><font size="2" color="#0000ff">Each</font><font size="2"> key </font><font size="2" color="#0000ff">As</font><font size="2"> </font><font size="2" color="#0000ff">String</font><font size="2"> </font><font size="2" color="#0000ff">In</font><font size="2"> aryCollection.Keys </font><font size="2" color="#008000">&#39;loop through every subDirectory</font> </p> </font><font size="2"> <p> strHtmlString.Append(<font size="2" color="#a31515">&quot;&lt;div&gt;&quot;</font><font size="2">) </font><font size="2" color="#008000">&#39;opening tag</font> </p> </font><font size="2">strHtmlString.Append(<font size="2" color="#a31515">&quot;&lt;strong style=&quot;&quot;font-size:120%&quot;&quot;&gt;&quot;</font><font size="2">) </font><font size="2"> <p> strHtmlString.Append(key) <font size="2" color="#008000">&#39; Name of the Catagory</font> </p> </font></font><font size="2">strHtmlString.Append(<font size="2" color="#a31515">&quot;&lt;/strong&gt;&quot;</font><font size="2">) </font><font size="2">strHtmlString.Append(<font size="2" color="#a31515">&quot; (Click Image to Enlarge)&quot;</font><font size="2">) </font><font size="2"> <p> strHtmlString.Append(<font size="2" color="#a31515">&quot;&lt;hr /&gt;&quot;</font><font size="2">) </font><font size="2" color="#008000">&#39;line space</font> </p> </font></font></font><font size="2"> <p> strHtmlString.Append(<font size="2" color="#a31515">&quot;&lt;table cellspacing=&quot;&quot;10&quot;&quot;&gt;&quot;</font><font size="2">) </font><font size="2" color="#008000">&#39;opend the table</font> </p> </font><font size="2"> <p> aryValues = aryCollection.GetValues(key) </p> <font size="2"> <p> <font size="2" color="#0000ff">If</font><font size="2"> (((aryValues.Length) </font><font size="2" color="#0000ff">Mod</font><font size="2"> intItemsPerRow) &gt; 0) </font><font size="2" color="#0000ff">Then</font><font size="2"> </font><font size="2" color="#008000">&#39; if there is a remainder do an integer division and add one to round up </font> </p> </font></font><font size="2"> <p> <font size="2" color="#008000">&#39;the rounding will round down so add extra row to compensate</font> </p> </font><font size="2"> <p> intNumbOfRows = (aryValues.Length \ intItemsPerRow) + 1 <font size="2" color="#008000">&#39;rounds up</font> </p> </font><font size="2"> <p> <font size="2" color="#0000ff">Else</font><font size="2"> : intNumbOfRows = ((aryValues.Length) / intItemsPerRow) </font><font size="2" color="#008000">&#39; no round as there is no remainder</font> </p> </font><font size="2"> <p> <font size="2" color="#0000ff">End</font><font size="2"> </font><font size="2" color="#0000ff">If</font> </p> </font><font size="2"> <p> <font size="2" color="#0000ff">While</font><font size="2"> (i &lt; aryValues.Length) </font><font size="2" color="#008000">&#39;loop through all files in the subdirectory</font> </p> </font><font size="2"><font size="2" color="#0000ff">For</font><font size="2"> j </font><font size="2" color="#0000ff">As</font><font size="2"> </font><font size="2" color="#0000ff">Integer</font><font size="2"> = 1 </font><font size="2" color="#0000ff">To</font><font size="2"> intNumbOfRows </font><font size="2">strHtmlString.Append(<font size="2" color="#a31515">&quot;&lt;tr&gt;&quot;</font><font size="2">) <font size="2" color="#0000ff">While</font><font size="2"> (k &lt; intItemsPerRow </font><font size="2" color="#0000ff">And</font><font size="2"> i &lt; aryValues.Length) </font><font size="2"></font></font><font size="2"><font size="2"> <p> strHtmlString.Append(<font size="2" color="#a31515">&quot;&lt;td&gt;&quot;</font><font size="2">) </font><font size="2" color="#008000">&#39;background: #b4afa3;</font> </p> </font></font></font></font><font size="2">strHtmlString.Append(<font size="2" color="#a31515">&quot;&lt;span style=&quot;&quot;background: #b4afa3; padding: 0 1px; border: 1px solid #dcd7c8; &quot;&quot;&gt;&quot;</font><font size="2">) </font><font size="2">strHtmlString.Append(<font size="2" color="#a31515">&quot;&lt;img style=&quot;&quot;padding:5px; background:white;&quot;&quot; src=&quot;&quot;&quot;</font><font size="2">) </font><font size="2"> <p> strHtmlString.Append(key) </p> strHtmlString.Append(<font size="2" color="#a31515">&quot;/&quot;</font><font size="2">) </font><font size="2"> <p> strHtmlString.Append(aryValues(i)) </p> strHtmlString.Append(<font size="2" color="#a31515">&quot;&quot;&quot; width=&quot;&quot; 100px &quot;&quot; onclick=&#39;imgPreview.src = this.src; window.scrollTo(0,80);&#39;/&gt;&quot;</font><font size="2">) strHtmlString.Append(<font size="2" color="#a31515">&quot;&lt;/span&gt;&quot;</font><font size="2">) </font><font size="2"></font></font><font size="2"><font size="2">strHtmlString.Append(<font size="2" color="#a31515">&quot;&lt;/td&gt;&quot;</font><font size="2">) </font><font size="2"> <p> k = k + 1 <font size="2" color="#008000">&#39;move onto next item</font> </p> </font></font></font></font></font></font></font><font size="2"> <p> i = i + 1 <font size="2" color="#008000">&#39; move onto next image in the subdirectory</font> </p> </font><font size="2"> <p> <font size="2" color="#0000ff">End</font><font size="2"> </font><font size="2" color="#0000ff">While</font> </p> </font><font size="2"> <p> k = 0 <font size="2" color="#008000">&#39;reset for next loop </font> </p> </font><font size="2">strHtmlString.Append(<font size="2" color="#a31515">&quot;&lt;/tr&gt;&quot;</font><font size="2">) </font><font size="2"><font size="2" color="#0000ff">Next</font><font size="2"> j </font><font size="2"> <p> <font size="2" color="#0000ff">End</font><font size="2"> </font><font size="2" color="#0000ff">While</font> </p> </font></font></font><font size="2"> <p> i = 0 <font size="2" color="#008000">&#39;reset for next loop</font> </p> </font><font size="2"> <p> strHtmlString.Append(<font size="2" color="#a31515">&quot;&lt;/table&gt;&quot;</font><font size="2">) </font><font size="2" color="#008000">&#39;close the table</font> </p> </font><font size="2"> <p> strHtmlString.Append(<font size="2" color="#a31515">&quot;&lt;/div&gt;&quot;</font><font size="2">) </font><font size="2" color="#008000">&#39;close opening tag</font> </p> </font><font size="2"><font size="2" color="#0000ff">Next</font><font size="2"> key </font><font size="2"> <p> <font size="2" color="#008000">&#39;Catagory Html Stop</font> </p> </font></font><font size="2"> <p> <font size="2" color="#008000">&#39;Return the HTML String</font> </p> </font><font size="2"> <p> CreateHTML = strHtmlString.ToString </p> <p> <font size="2" color="#0000ff">End</font><font size="2"> </font><font size="2" color="#0000ff">Function</font> </p> </font></font><font size="2"><font size="2"></font></font> <p> [/code]

The above code builds a table for each catagory using the paramert 'intItemsPerRow', to determine the need number of table rows. inline evet hander is used to print each image to the previmage at the top of the page.

Part 4 - The PageLoad

[code:vb] </p> <font size="2"><font size="2"> <p> Public Sub Page_Load() </p> </font><font size="2" color="#0000ff">Dim</font><font size="2"> aryCollection </font><font size="2" color="#0000ff">As</font><font size="2"> NameValueCollection </font></font><font size="2"> <p> <font size="2" color="#0000ff">Dim</font><font size="2"> strHtml </font><font size="2" color="#0000ff">As</font><font size="2"> </font><font size="2" color="#0000ff">String</font> </p> </font><font size="2"> <p> &nbsp; </p> <p> aryCollection = FolderListArray(_imageFolderPath) </p> <p> <font size="2" color="#0000ff">If</font><font size="2">(aryCollection.Count &gt; 0) </font><font size="2" color="#0000ff">then</font> </p> </font><font size="2"> <p> strHtml = CreateHTML(aryCollection) </p> <p> Label1.Text = strHtml </p> <p> <font size="2" color="#0000ff">Else</font> </p> </font><font size="2"> <p> Label1.Text = <font size="2" color="#a31515">&quot;Error Directory does not exist or invaid path given &quot;</font> </p> </font><font size="2"> <p> <font size="2" color="#0000ff">End</font><font size="2"> </font><font size="2" color="#0000ff">if</font> </p> </font><font size="2"> <p> <font size="2" color="#0000ff">End</font><font size="2"> </font><font size="2" color="#0000ff">Sub</font> </p> </font><font size="2"><font size="2" color="#0000ff">&lt;/</font><font size="2" color="#a31515">script</font><font size="2" color="#0000ff">&gt; </font><font size="2" color="#0000ff">&lt;<font size="2" color="#a31515">asp</font><font size="2" color="#0000ff">:</font><font size="2" color="#a31515">Label</font><font size="2"> </font><font size="2" color="#ff0000">ID</font><font size="2" color="#0000ff">=&quot;Label1&quot;</font><font size="2"> </font><font size="2" color="#ff0000">runat</font><font size="2" color="#0000ff">=&quot;server&quot;</font><font size="2"> </font><font size="2" color="#ff0000">EnableViewState</font><font size="2" color="#0000ff">=&quot;false&quot;</font><font size="2"> </font><font size="2" color="#ff0000">Text</font><font size="2" color="#0000ff">=&quot;Label&quot;&gt;&lt;/</font><font size="2" color="#a31515">asp</font><font size="2" color="#0000ff">:</font><font size="2" color="#a31515">Label</font><font size="2" color="#0000ff">&gt; </font><font size="2" color="#0000ff"></font></font></font> <p> [/code]

The Label1 is used to hold the HTML, if the namedvalue collection is = 0 then and error is printed.

Be the first to rate this post

  • Currently 0/5 Stars.
  • 1
  • 2
  • 3
  • 4
  • 5
Tags:   ,
Categories:   ASP.NET
Actions:   E-mail | Permalink | Comments (224) | Comment RSSRSS comment feed