in

Blog By Bob

Blog by Bob

March 2007 - Posts

  • Movin On

    Well, today is my last day at my current job. The next week should be fun, finishing some side work, packing all I own and moving it back to Charlotte for my new job, which I think is going to be amazingly fun!

    As they say, as painful as it might be in the short term, change is definitely good. WOOT!

  • ADO.NET Silliness

    I look at alot of the constructors for ADO.NET and I just have to ask, why? oh God why?

    Take, for instance, the relationship between a SqlConnection object and a SqlCommand object.

    To me, the clearest and still quickest way to instantiate both would be:

    SqlConnection connection = new SqlConnection(ConfigurationManager.ConnectionStrings["SqlServer"].ConnectionString);

    SqlCommand command = connection.CreateCommand("select * from blah");

    Or so you would think, but even though there is an override for SqlCommand for a command text so you can say:

    SqlCommand command = new SqlCommand("select * from blah", connection);

    There isn't an override in CreateCommand to slap that query text in there, but at the same time I really don't like having to pass the connection object to the command guy to get them linked, when SqlConnection's CreateCommand factory makes it so clear how things hook together. Sigh, I guess I just need to override it and use my own shiznit.

  • Wikipedia and You

    I never really got into Wikipedia enough to actually edit anything, but someone sent me down a path and now I see the evil in anyone being able to edit it. I don't know how long it will stay, but there is currently an entry under January 3rd.

    1972 - Robert Mills, the Creator of Blog By Bob[1]

    Look under births and then 1972. The internet is mine.

    This post brought to you by the letter W

  • Adding Misery To Pain : The New Commodore

    Commodore

    So, while we are on the subject of Commodore, I might as well touch on a subject that I have been purposely avoiding, the reincarnation (sic) of Commodore. Basically, a company has purchased the Commodore name and is selling a line of gaming PCs with Commodore logos on them. Some nice looking machines, with some nice specs, but quit sullying the name my brothers...

  • Who would ever need more than 640k of RAM?

    I am pretty sure the much touted comment by Bill Gate's is more an urban myth than reality, but then again, I still think with an updated OS, the C 64 is all we would ever need.
    c 64
  • Public Service Announcement

    Free Starbucks coffee between 10am and 12pm today. Tastes like ground dirt if you ask me...

    http://www.starbucks.com/ourcoffees/coffee_break.asp

  • Global Warming Has To Stop

    So, my office mate at work sent *13* emails for no reason at all today. *That* my friends is what causes global warming, and it needs to stop.
  • Windows 2003 Server SP2

    I heard a rumor that Windows 2003 Server SP2 is up on Windows Update for download. I might be lying though, I don't see it for download anywhere else.
  • Directory.Delete(true)

    The Directory.Delete() method has two overloads. One (which we haven't demonstrated here) takes no parameters and does a simple delete and the file or directory goes to the recycle bin. The other takes one parameter - a Boolean which indicates whether the delete operation is recursive.

    They should add a warning to this:

    If you expect your application to run under a priviledged account, please make sure you check the path first...

    Thanks for playing, please drive through.

  • Active Directory Membership and Roles in ASP.NET 2.0

    Most of the things I read about using AD with ASP.NET ends up being way more complex than it needs to be. Toss this in your web.config between the system.web tags:

    <authentication mode="Windows" />
    <
    identity impersonate="true"/>
    <
    roleManager enabled="true" defaultProvider="AspNetWindowsTokenRoleProvider">
    <
    providers>
    <
    clear/>
    <
    add name="AspNetWindowsTokenRoleProvider" applicationName="/" type="System.Web.Security.WindowsTokenRoleProvider" />
    </
    providers>
    </
    roleManager>
    <
    membership defaultProvider="ADMembershipProvider">
    <
    providers>
    <
    add name="ADMembershipProvider" applicationName="/" type="System.Web.Security.ActiveDirectoryMembershipProvider" connectionStringName="ADConnectionString" attributeMapUsername="sAMAccountName" connectionProtection="Secure" />
    </
    providers>
    </
    membership>

    Make sure your virtual or site is using Integrated Windows Authentication.

    Done. Not a believer?

     Well, I kind of lied. If you are on XP, you really cant get this to work without hard coding a username and password for a domain user who has access to query LDAP into the membership provider (I guess that is how Microsoft defines secure by default, patch please) so change that guy to look like this:

    <add name="ADMembershipProvider" applicationName="/" type="System.Web.Security.ActiveDirectoryMembershipProvider" connectionStringName="ADConnectionString" attributeMapUsername="sAMAccountName" connectionUsername="Domain\user" connectionPassword="securepassword" connectionProtection="Secure" />

    Run your code, pop into a break point and type

    Membership.GetUser() which will return a Membership user with a bunch of info about you, and try Roles.GetRolesForUser() will will get all of your roles or Roles.IsUserInRole("role") which will return true if you are in a role, false if you aren't or FileNotFound otherwise. (Just Kidding). You can add/remove roles etc.

    BLAM! Winner! Between the membership and roles providers you can pretty much do anything you can do from the AD Users and Groups snap-in, all from the comforts of C#. 

    Brought to you by the letters 'A' and 'D'

     

  • An IE for Everyone

    evolt.org

    In case anyone has already noticed, if you develop your CSS for IE 7, you have pretty much screwed the pooch on how it will look in IE 6. I had heard some rumors about standalone IE browsers and came upon the greatest IE page on the internet. Go get some IE, just don't try to surf with IE 3...

  • .NET For Dummies

    I read over at TristanK's site that Microsoft has released a content site for beginning and amateur developers. At least noone recommend I spend some quality reading time there...

  • Writing a Dynamic Playlist in ASP.NET (C# of course)

    I have an FTP directory that I keep my music in, and I have a Windows Play List file in it (.wpl). Windows Playlist Files are human readable xml files you can alter in notepad, so when I add a new song to the directory, I just open the file and add another line. A wpl file looks like this:

     <?wpl version="1.0"?>
    <smil>
        <head>
            <meta name="Generator" content="Microsoft Windows Media Player -- 10.0.0.3646"/>
            <title>Playlist1</title>
        </head>
        <body>
            <seq>
                <media src="http://blogbybob.com/music/mysong.wma" mce_src="http://blogbybob.com/music/mysong.wma"/>
            </seq>
        </body>
    </smil>

    So, I had a thought one day. Just the one, of course. Would it be nice if I could add the file, and have it show up automatically when I opened media player?

    Well, amazingly enough, it is actually pretty easy to do. The main thing to do is "trick" IE into thinking that your wonderful aspx page is actually a wpl file. Fire up Visual Studio, start a new Web Site and go into your default.aspx file.

    Highlight all that crap and delete it. Wait, I mean, all of it but the first line. My bad. And I actually named my file music.aspx, but whatever.

    Anyhow change the file contents to look like this:

    <%@ Page Language="C#" AutoEventWireup="true" CodeFile="music.aspx.cs" Inherits="_Music" %>

    <?wpl version="1.0"?>

    <smil>
      <
    head>
        <
    meta name="Generator" content="Microsoft Windows Media Player -- 10.0.0.3646"/>
        <
    title>musicbybob</title>
      </
    head>
      <
    body>
        <
    seq>
          <
    asp:Literal runat="server" ID="litPlaylist" />
        </
    seq>
      </
    body>
    </
    smil>

    except your first line should still point to whatever code behind you are using. Right click that guy and choose View Code.

    We are going to get rid of all but 2 of the using statements and add some code to the Page_Load event. When you are done it should look like this:

    using System;
    using System.IO;

    public partial class _Music : System.Web.UI.Page
    {
      protected void Page_Load(object sender, EventArgs e)
      {
        Response.Clear();
        Response.ContentType =
    "video/x-ms-wma";
        Response.AddHeader(
    "Content-Disposition", "inline;filename=musicbybob.wpl");
        litPlaylist.Text =
    string.Empty;

        DirectoryInfo d = new DirectoryInfo(Server.MapPath("music"));

        foreach (FileInfo f in d.GetFiles())
        {
          litPlaylist.Text +=
    "<media src=\"http://" + Request.Url.Host +"/"+ Request.ApplicationPath + "/music/" + f.Name + "\"/>";
        }
      }
    }

    Except your class name should match whatever is in your aspx page. Yeah, I used some crappy variable names and was all around lazy, but it works, and sometime I *like* to be lazy. This will read anything in the music folder below where this file lives. You can also add other wpl files in the music folder that point to other places if you have music spread around. Music added to those "other" places won't be dynamically added though. The code also doesn't navigate subdirectories in your music folder.

    Or so I assume, I never actually tried it.

    Anyhow, to see this in action, click the Radio button in the main navigation menu above.

     Update:Download the code here

    This post is brought to you by the letter 'M'

  • The Lack of Real Multi Monitor Support

    Every developer I know (except the crazies) uses 2 ore more monitors. I was working diligently today, when my mind shot off on a tangent about how much better life would be if Microsoft would finally actually add REAL support for multiple monitors.

    For instance, lets revisit the Microsoft changes in Vista. They added the nice fancy Windows-Tab task switcher, which is much cooler than the old Alt-Tab. But it sucks. They could have used the opportunity to add multi-monitor support. Get rid of the old crappy switcher all together. Alt-Tab becomes the new fancy switcher. Windows-Tab? Switch between applications anchored to the monitor that currently has focus.

    Working in Excel today, I was again reminded of the lacking multi-monitor support. What could make my experience in Excel (and other apps) more productive? How about 2 maximize options for the parent, one to maximize to the current monitor. Another, maybe right clicking the maximize button, to maximize to all monitors. Have this work on child windows as well. BOOM. Open Excel, maximize to all monitors. Open 2 documents, maximize each inside Excel to one monitor. No more manually resizing the windows around to make the fit their respective machines.

    What else? Been inside VS lately? Open 2 different kinds of documents. A code behind and an aspx page for instance. Fit them one to each monitor. Click on one, then the other. By default the toolbars are different heights. So the screen goes all jittery whack while it resizes everything. Move back and forth quickly. Bah. Did you also notice that most likely your break between the 2 files, that you so carefully placed right at the break between the monitors also jiggery slipped around and probably doesn't line up when you have focuse on one monitor or the other?

    Come on Microsoft. Something this trivial can not be that hard. You want to empower users in a way that keeps them coming back? This is a one I would like to see. Make it supported in Windows at the API level, none of this crappy half ass support we have in video card drivers now.

More Posts
Copyright © :: BlogByBob.com
Powered by Community Server (Non-Commercial Edition), by Telligent Systems