ASP.NET
  Home arrow ASP.NET arrow Page 2 - Slapping a Photo Gallery Together 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 a Photo Gallery Together in ASP.NET Part I
By: Harish Kamath
  • Search For More Articles!
  • Disclaimer
  • Author Terms
  • Rating: 3 stars3 stars3 stars3 stars3 stars / 31
    2005-04-04

    Table of Contents:
  • Slapping a Photo Gallery Together in ASP.NET Part I
  • Say Cheese
  • Digging Deeper
  • Different Strokes
  • Etcetera
  • 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 a Photo Gallery Together in ASP.NET Part I - Say Cheese


    (Page 2 of 6 )

    Before I get into the nitty gritty of coding the "Photo Gallery" application, let me give you a little note on how I've organized my photo collection on the server. I've already hinted that I plan to use the file and folder management classes available on the .NET platform in order to develop this application. So, it logically follows that the most convenient manner to organize the photographs on the file-system is by creating a folder structure that reflects the location and purpose of each vacation.

    Consider the following folder structure:

    E:\inetpub\wwwroot\
    +---Gallery

    +---Australia
    |    +---Christmas
        |    \---New_Year
      +---London
        |    \---The_Tube
        +---New York
        |    \---Independence_Day
        \---Singapore
            \---Shopping_Festival

    As seen above, the folder structure is almost self-explanatory as far as the location and purpose of each vacation is concerned. You can easily follow a similar naming convention for each image file in each album and voila - you do not need to worry about storing the descriptions for your photographs separately!

    Next, you have to look into the permissions assigned to the entire folder structure that forms a part of the application. It is essential to ensure that the special "ASPNET" user - created at the time of installation of the .NET framework - has the required permissions (especially if you wish to create folders dynamically using ASP.NET scripts) across the entire folder structure, listed above.

    Now, its time to get our hands dirty with some code - the following example introduces the Directory() object:

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

        void Page_Load(Object sender, EventArgs e) {

                // path to the root folder of the "Photo Gallery"
                string strPhotoGalleryRoot = "E:\\inetpub\\wwwroot\\Gallery";

     // check if the above folder exists
                if(Directory.Exists(strPhotoGalleryRoot)) {
                    output.Text = "The folder <U>" + strPhotoGalleryRoot  + "</U> found.";
                } else {
                    output.Text = "Sorry, the folder <U>" + strPhotoGalleryRoot + "</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>

    Save this script under the root folder of the Web server and load it into your favorite browser to view the one of the following outputs:

    1. If the "Gallery" folder, stored in the "strPhotoGalleryRoot" variable, exists.

    2. If the "Gallery" folder does not exist at the specified location.

    Coming back to the code listing: for starters, I've imported the "System.IO" namespace as the Directory() object as part of the "System.IO" .NET assembly. As you may already know, it is recommended that you import the required namespaces using the "import" directive, as it allows you to create object instances without having to provide the complete class path at the time of instantiation.

    Next, I've defined a variable titled "strPhotoGalleryRoot" - as the name suggests, I use this string variable to store the path to the root folder of my "Photo Gallery."

    It's time to say hello the Directory() object. This .NET object, equipped with a bunch of static methods, allows you to work with any folder located on the file system of the Web server. For the uninitiated, static methods are object methods that can be invoked without the need to create an object instance of the underlying class.

    Finally, the above example  demonstrates the use of the Exists() static method of the Directory() object - it returns a "true" value if a particular path exists or a "false" value otherwise.

    More ASP.NET Articles
    More By Harish Kamath


     

    ASP.NET ARTICLES

    - 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...
    - Building an In-Text Advertising System Under...
    - Developing a Mini ASP.NET AJAX Server Centri...





    © 2003-2009 by Developer Shed. All rights reserved. DS Cluster 1 Hosted by Hostway
    Stay green...Green IT