OCDProgrammer.com

It's Microsoft's World, and I'm just living in it
View Clarence Klopfstein's profile on LinkedIn

Clarence Klopfstein's Facebook profile

This site is under construction...

Categories

New Comments

Referring Sites


Disclaimer

  • This is MY blog. The views represented here are not in relation to anybody else. Please read my full disclaimer for a more complete disclaimer.

DateTime.ToString() Patterns

July 17, 2008 03:00 by ckincincy

Many times when programming in .NET you need your DateTime variable to display in various formats:

08/22/2006
Tuesday, 22 August 2006
etc...

This is thankfully made pretty trivial with the ToString() function.  Just pass in the appropriate format string and you will get what you need.

You can find a great list of these here.


Working with Zip files in .NET

July 2, 2008 03:00 by ckincincy

Recently I was working on a project that required me to unzip a file and process its contents.

But I needed to first figure out how to unzip a file.  To the rescue came the SharpZipLib.  This is under the GPL but is specifically released for personal and commercial use.

In my very basic use it worked like a champ.


List all installed fonts on your machine

June 24, 2008 03:00 by ckincincy

I recently ran across this post and loved it!  I do some image creation stuff and the hardest part of my task is picking a font.  Now I can print out my installed fonts and quickly pick one out.

Now here is the guys code, but slightly edited.  As his had a few syntax errors in it. 

try
{
    StringBuilder sb = new StringBuilder();
 
    foreach (FontFamily family in FontFamily.Families)
    {
    sb.Append("<h2 style='color:blue;font-family:Arial;'>" + family.Name + "</h2>");
    sb.Append("<font face='" + family.Name + "' size='6'>");
    sb.Append("The quick brown fox jumps over the lazy dog. 1234567890");
    sb.Append("</font><hr/>");
    sb.Append(Environment.NewLine);
    }
 
    lblFontList.Text = sb.ToString();
}
catch (Exception ex)
{
    lblErrorMessage.Text = ex.ToString();
}

.NET USERS GROUP

February 19, 2008 19:30 by ckincincy

titleWent to my first ever .NET Users Group here in Cincinnati.  I've been monitoring this group from a distance for sometime, just haven't taken the time to attend a meeting (even when I worked 10 minutes from their location) previously.  However, a co-worker of mine wanted to attend and with her being a bit of a n00b I told her I'd accompany her to the meeting.

Going into it I knew an old friend of mine was going to be there from his blog, but was pleasantly surprised to see another friend as well.  The three of us used to go to church together, I've since moved on from that church, but they still attend.  It was good to touch base with some old friends.

The topic of discussion was on source safe solutions.  Kind of dry in the fact that while source safe is critical in an IT environment, its hard to cover a whole 90 minutes on the topic.  The panel did a great job though.

I think I may try to make this a regular thing... time will tell.

You should at least give it a try.


Creating a photo gallery

November 12, 2007 21:35 by ckincincy

I needed a simple way to create a photo gallery for my churches website, so I started off by doing a search for something that already exist.  I found gphotonet, and thought it was a good thing to start with.

However there were some things I wasn't happy with.  First it would require a lot of heavy lifting by the web server to create the thumbnails on the fly.  Second it would have me uploading some pretty large images (as 10MP cameras put some serious file sizes out).  So first I took some of the logic in this code and created an application that would create the images for me as static files.  Then I edited the page to load from my custom directories and from the database that would have some basic information about the galleries.  Now all of that I would hope you could figure out on your own, but if you need help feel free to contact me.

What I liked about this process was how easy it was to load the image into an ASP.NET component :<asp:datalist/>  This is just a really cool feature.  

I started off by creating an array list and looping through the images in a directory and filling the array list, then I used databound to put that array in the datalist, IT takes care of the rest creating the galleries you see on my churches website.  Here is the basic HTML and code behind I used:

HTML:
 <asp:DataList runat="server" id="dlPictures" RepeatDirection="Horizontal"  
         RepeatColumns="2"
         GridLines = "None"
         ItemStyle-HorizontalAlign="Center"
         cellpadding="5"
         cellspacing="0"
         BorderColor ="Black"
         BorderStyle="Solid"
         BorderWidth="0"
         HorizontalAlign="Center"
         VerticalAlign="Middle" >    
      <ItemTemplate>
        <%# Container.DataItem %>
      </ItemTemplate>
    </asp:DataList>

Code to fill DataList:
         string picUrl = Request.QueryString["picDir"];
            ArrayList pics = new ArrayList();
            if (picUrl != null && picUrl != string.Empty)
            {
                string html;
                foreach (string s in Directory.GetFiles(Server.MapPath(picUrl + "\\250"), "*.jpg"))
                {
                    html = "<a href=\"viewimage.aspx?path=" + picUrl + "&img=" +
                        Path.GetFileName(s) + "\">" + "<img border=\"0\" src=\"" +
                        picUrl + "\\250\\" + Path.GetFileName(s) + "\" \">" + "</a>";

                    pics.Add(html);
                }
            }
            else
            {
                string DB_CON = @"MY DB CONNETION";
                string SQL = "MY SQL STATEMENT";

                OleDbConnection con = new OleDbConnection(DB_CON);
                OleDbCommand cmd = new OleDbCommand(SQL, con);

                con.Open();
                OleDbDataReader rdr = cmd.ExecuteReader();
                if (rdr.HasRows)
                {
                    while (rdr.Read())
                    {
                        string html;
                        string AlbumPath = rdr["path"].ToString();
                        string AlbumName = rdr["album"].ToString();
                        string AlbumCount = rdr["count"].ToString();
                        html = "<a href=\"default.aspx?picDir=" + AlbumPath +
                            "\">" + "<img border=\"0\" src=\"" +
                            AlbumPath + "\\gallery.jpg" + "\" />" + "</a>" +
                            "<br/>" + AlbumName + " - " + AlbumCount + " images";
                        pics.Add(html);
                    }
                }
                rdr.Close();
                rdr.Dispose();
                cmd.Dispose();
                con.Close();
                con.Dispose();
            }

            dlPictures.DataSource = pics;
            dlPictures.DataBind();

 

Hope this helps you. 


Categories: ASP.NET
Actions: E-mail | Permalink | Comments (1) | Comment RSS