ASP.NET
  Home arrow ASP.NET arrow Page 5 - 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  
Visual Basic.NET  
Windows Scripting  
Windows Security  
XML  
ASP Web Hosting  
ASP.NET Web Hosting 
Mobile Linux 
App Generation ROI 
Windows Web Hosting
 
IBM® developerWorks 
Sun Developer Network 
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: 4 stars4 stars4 stars4 stars4 stars / 30
    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 - Etcetera


    (Page 5 of 6 )

    So far, I've demonstrated how you can use different .NET objects to navigate around the file system. For the sake of completeness, I will now demonstrate how you can create folders using the DirectoryInfo() object.

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

    void Page_Load(Object o,EventArgs a) {

    if(Page.IsPostBack) {

      // Clear the output text box
      output.Text = "";

      try {

       if(txtDirectoryName.Text != "") {

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

    // create an instance of the DirectoryInfo() object
    // on the basis of the file-system path provided
    DirectoryInfo objCurrentFolder = new DirectoryInfo(strFileSystemPath);

        // A quick check if a folder by the same name already exists
        string strNewFolderPath = strFileSystemPath + "\\" + txtDirectoryName.Text;
        DirectoryInfo objNewFolder = new DirectoryInfo(strNewFolderPath);

    // check if folder exists already
        if(objNewFolder.Exists) {

    // if it does, display error message...
         output.Text = "A folder by this name already exists.";

        } else {

    // ... and if it does, create a new folder with the required name
         objNewFolder = objCurrentFolder.CreateSubdirectory(txtDirectoryName.Text);
         output.Text = "Folder \"" + txtDirectoryName.Text + "\" was created successfully.";
        }


       } else {

        output.Text = "Please enter a folder name to be created.";
       }

      } catch (Exception e) {

       output.Text = "An error occurred: " + e.Message;

      } finally {

       hypBack.Visible = true;
       txtDirectoryName.Visible = false;
       btnSubmit.Visible = false;
      }
     }
    }
    </SCRIPT>
    <HTML>
    <HEAD>
    <BASEFONT face="Arial">
    </HEAD>
    <BODY>
    <FORM runat="server">
    <asp:Label id="output" runat="server" Text="Folder Name"/>
    <asp:TextBox id="txtDirectoryName" Text="" runat="server"/>
    <asp:Button id="btnSubmit" Text="Create Directory" runat="server" />
    </FORM>
    <asp:HyperLink id="hypBack" Text="<< Back" NavigateUrl="javascript:window.history.go(-1)" visible="false" runat="server" />
    </BODY>
    </HTML>

    Here is the output after the required folder has been successfully created:

    If things do not go quite the way you expected, you should an error that looks like this:.

    To kick things off in this script, I've created an instance DirectoryInfo() object for the root folder, specified in the "strFileSystemPath" string variable. Next, I've instantiated another DirectoryInfo() object representing the new folder that I wish to create.

    The "Exists" property of the DirectoryInfo() object can be used to verify whether a folder with the same name already exists. If yes, the script exits with a polite message, as seen above. If not, I've invoked the CreateSubdirectory() method to create the required folder.

    The many "if-else" blocks in the script take care of different scenarios that I may come across. A closer look at the error messages associated with each block should help to make things clear.

    Deleting a directory is not a problem. The DirectoryInfo() object has a handy Delete() method to delete a particular directory. Go ahead, give it a shot and I'm sure that you'll not be disappointed.

    Want to make things interesting? Just pass a Boolean "true" value to this Delete() method. Within seconds, the Delete() method will wipe out your entire collection. As you might have guessed, if this Boolean parameter is set to "true," the ASP.NET script will delete all files recursively.

    This is not a very smart move. Always use the Delete() method with great care. Period.

    More ASP.NET Articles
    More By Harish Kamath


     

    ASP.NET ARTICLES

    - Disadvantages of the ASP.NET MVC Framework
    - Advantages of the ASP.NET MVC Approach
    - ASP.NET Web Forms Weaknesses
    - ASP.NET Web Forms Meets ASP.NET MVC
    - Source Code for Saving and Retrieving Data w...
    - Using GridView to Save and Retrieve Data wit...
    - Handling Dynamic Images in ASP.NET 3.5 AJAX ...
    - Retrieving Data with AJAX and the GridView C...
    - Playing with Images in ASP.NET 3.5 AJAX Appl...
    - Saving and Retrieving Data with AJAX
    - Enhancing PHP Via the ASP.NET AJAX Framework...
    - Enhancing PHP Programming with the ASP.NET A...
    - Classes and ASP.NET AJAX
    - Using ASP.NET AJAX
    - Building a Simple Storefront with LINQ

     
    Application Delivery: Everything You Wanted to Know, but Didn`t Know You Needed to Ask
    A comprehensive guide to examining the topics of Wide-area Data Services and app....

     
    Best Practices: Safe and Secure Hardware Asset Recovery
    Companies increasingly must meet EPA and local requirements for the disposal of ....

     
    Managing SSL Security in Multi-Server Environments
    Read this white paper to learn how to simplify management of your organization's....

     
    Open Source Security Myths
    Open Source Software (OSS) is computer software whose source code is available t....

     
    Power and Cooling Capacity Management for Data Centers
    This paper describes the principles for achieving power and cooling capacity man....

     




    © 2003-2008 by Developer Shed. All rights reserved. DS Cluster 5 hosted by Hostway
    Stay green...Green IT