Display all your albums

I wanted to create a list of CDs I had burned on my laptop. Instead of just looking at them and writing them down, I, of course, wrote a program to do it. It literally took my five minutes. OK, maybe six.

I created an ASP.NET page, because the project where my test code is an ASP.NET project, and it’s easy to copy the resulting text out of a web page. First, the controls in the aspx page:

        <asp:TextBox ID="txtPath" runat="server" />
        <asp:Button ID="btnSubmit" Text="Go" runat="server" onclick="btnSubmit_Click" />

 And now the code behind. Don’t’ forget to include the System.IO namespace:

         protected void btnSubmit_Click(object sender, EventArgs e)
        {
            if (txtPath.Text.Length == 0)
            {
                Response.Write("<br>Put something in the textbox, chief.");
                return;
            }
            string[] ArtistList = Directory.GetDirectories(txtPath.Text);
            foreach (string Artist in ArtistList)
            {
                string[] AlbumList = Directory.GetDirectories(Artist); 
                foreach (string Album in AlbumList)
                {
                    Response.Write("<br>Artist = " + Artist + ", album = " + Album);
                } 
            }

 See, I even put an in-depth data validation in there!

 And the output of this code is like this:

Artist = d:\music\Buddy Guy, album = d:\music\Buddy Guy\Buddy’s Baddest The Best of Buddy Guy
Artist = d:\music\Evanescence, album = d:\music\Evanescence\Fallen
Artist = d:\music\Switchfoot, album = d:\music\Switchfoot\Hello Hurricane
Artist = d:\music\U2, album = d:\music\U2\All That You Can’t Leave Behind

Yep, I could easily make it better, but so could you, so get to it.

Advertisements
  1. Leave a comment

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: