ASP.NET
  Home arrow ASP.NET arrow Page 3 - Slapping Together a Photo Gallery in ASP.N...
ASP Free Forums 
.NET  
ASP  
ASP Code  
ASP.NET  
ASP.NET Code  
BrainDump  
C#  
Code Examples  
Database  
Database Code  
IIS  
Microsoft Access  
MS SQL Server  
Silverlight  
Visual Basic.NET  
Windows Scripting  
Windows Security  
XML  
Mobile Linux 
App Generation ROI 
IBM® developerWorks 
ASP Web Hosting  
ASP.NET Web Hosting 
Windows Web Hosting
 
Weekly Newsletter
 
Developer Updates  
Free Website Content 
 RSS  Articles
 RSS  Forums
 RSS  All Feeds
Write For Us Get Paid 
Request Media Kit
Contact Us 
Site Map 
Privacy Policy 
Support 
 USERNAME
 
 PASSWORD
 
 
  >>> SIGN UP!  
  Lost Password? 
ASP.NET

Slapping Together a Photo Gallery in ASP.NET Part II
By: Harish Kamath
  • Search For More Articles!
  • Disclaimer
  • Author Terms
  • Rating: 4 stars4 stars4 stars4 stars4 stars / 22
    2005-04-11

    Table of Contents:
  • Slapping Together a Photo Gallery in ASP.NET Part II
  • Working with Files
  • Of Albums and Photos
  • Two Sides of a Coin
  • My Gallery
  • My Gallery - Demystified
  • Conclusion

  • Rate this Article: Poor Best 
      ADD THIS ARTICLE TO:
      Del.ici.ous Digg
      Blink Simpy
      Google Spurl
      Y! MyWeb Furl
    Email Me Similar Content When Posted
    Add Developer Shed Article Feed To Your Site
    Email Article To Friend
    Print Version Of Article
    PDF Version Of Article
     
     
    ADVERTISEMENT


    Slapping Together a Photo Gallery in ASP.NET Part II - Of Albums and Photos


    (Page 3 of 7 )

    This second example demonstrates some of the more useful static methods of the File() object. Take a look at the code listing below:

    <%@ Page Language="C#" Debug="true" %>
    <%@ Import Namespace="System.IO" %>
    <SCRIPT Language="C#" runat="server">

    // custom function to return the list of photographs
    // a.k.a. image files for a particular file system location
    void GetPhotos(string strFileSystemPath) {

     // define array to store list of "Photos"
     string[] aryPhotos;

     // use the GetFiles() static method
     // to obtain a list of image i.e. JPEG files
     aryPhotos = Directory.GetFiles(strFileSystemPath, "*.jpg");

     // iterate over array of "Photos" to
     / get details of each Photo
     foreach(string strPhotoFilePath in aryPhotos) {

      output.Text += "File Name: " + strPhotoFilePath.Substring(strFileSystemPath.Length + 1) + "<BR>";
      output.Text += "Created On: " + File.GetCreationTime(strPhotoFilePath) + "<BR>";
      output.Text += "Last Modified On: " + File.GetLastWriteTime(strPhotoFilePath) + "<BR>";
      output.Text += "Attributes: " + File.GetAttributes(strPhotoFilePath).ToString();
      output.Text += "<HR WIDTH=\"25%\" ALIGN=\"LEFT\">";

     }
    }

    void Page_Load(Object sender, EventArgs e) {

     // path to a particular Photo Album
     // i.e. folder on the file system
     string strPhotoAlbumPath = " E:\\inetpub\\wwwroot\\Gallery\\London";

     // check if the specified Photo Album i.e. folder exists
     if(Directory.Exists(strPhotoAlbumPath)) {

     // get the list of photos
     // in a particular Photo Album
     GetPhotos(strPhotoAlbumPath);

     } else {

     output.Text = "Sorry, the folder <U>" + strPhotoAlbumPath + "</U> could not be located.";

     }
    }
    </SCRIPT>
    <HTML>
    <HEAD>
        <TITLE>My Gallery</TITLE>
        <BASEFONT face="Arial" />
    </HEAD>
    <BODY>
        <asp:Label id="output" runat="server" />
    </BODY>
    </HTML>

    Here is a quick look at the output generated by this script before I get into the mandatory explanations:

    Here, I've defined a string variable titled "strPhotoAlbumPath." This stores the path to a selected "Photo Album," i.e. file system folder. Next, I have updated my custom GetPhotos() function - it made a brief appearance in the first article - to display information about each image file that the script encounters in the folder.

    Let me take you through the changes: I have defined a string array titled "aryPhotos" to store the locations of the different files. Next, I have invoked the GetFiles() method to initiate the array. A simple "foreach" loop allows me to iterate through the array and to display relevant file information using the following methods:

    • GetCreationTime() returns the date and time when the file, in question, was created.

    • GetLastWriteTime(), as the names suggests, it returns the time when the file was last modified.

    • GetAttributes() returns the attributes in the form of a FileAttribute() enumeration value. 

    And there's a lot more. Review the following URL for more information: http://msdn.microsoft.com/library/en-us/cpref/html/frlrfSystemIOFileClassTopic.asp

    A final note, before I move to the next section: a simple "if-else" loop in the Page_Load() function ensures that the server does not spit a screen full of errors if the specified folder does not exist. This is evident from the output shown below:

    More ASP.NET Articles
    More By Harish Kamath


     

    ASP.NET ARTICLES

    - Adding Content to a Static ASP.NET Website
    - Building a Static ASP.NET Website in a Basic...
    - Develop Your First ASP.NET Website with Visu...
    - Run ASP.NET in Windows XP Home with Cassini ...
    - How to Test a Web Application
    - How to Add Code and Validation Controls to a...
    - Working in Source and Split Views to Build a...
    - How to Build a Web Form for a One-Page Web A...
    - How to Develop a One-Page Web Application
    - An ASP.NET Web Application in Action
    - Developing ASP.NET Web Applications
    - An Introduction to ASP.NET Web Programming
    - Introduction to the ADO.NET Entity Framework...
    - Completing an In-Text Advertising System und...
    - Programming an In-Text Advertising System un...





    © 2003-2009 by Developer Shed. All rights reserved. DS Cluster 2 Hosted by Hostway
    For more Enterprise Application Development news, visit eWeek