in

ASP.NET Weblogs

Dave Burke - A freelance .NET Developer specializing in Online Communities

A freelance .NET Developer

April 2004 - Posts

  • Come get your 2001 MSDN Library Images here

    I was cleaning out my MSDN feed folder and came across this, sent out April 23:  The MSDN Library October 2001 ISO CD Image discs (in Japanese.)   2001?????   Whatever...

     

  • Arrays. Use'm or lose'm

    Arrays used to be hard.  Oh hell.  They're still hard.  Array[] verses ArrayList?  Use one when?  What???  The double brackets go with the object type, not the variable? Curlies around the declaration, not parentheses?

    But still, they pass multiple values real good!

    We'll pass three strings from a method: a list of user IDs, the emails of those users, and the users' names.  I was going to create a quick data structure, which would have been preferrable for strongly typed use, but I wanted to use the array.  Pretty ecomonical, actually.


    public string[] GetTeamStuff()
    {
     team_ids = "1,2,3";
     string[] Team =
      {
       team_ids,
       Users.GetEmails(team_ids).
       Users.GetNames(team_ids),
      };
     return Team;
    }

    and used as

    txtTeamEmails.Text = GetTeamStuff()[1];

  • Handling the comma. Period.

    One of my favorite words for as long as I can remember is "minutia" (or "minutiae" plural.)  My blog is filled with minutiae, and would have been more aptly titled ".NET Minutiae and Very Little Else."  That title might be taken, of course... 

    I'm not obsessed with economic code, but I like to write about it when it happens.  Kind of like when my dog scares up a wild turkey from out of some brush during our lunchtime walks.  I tell you about that, but I don't want to take focus off the comma.

    Traditionally the approach would be something like

    string comma = ", ";
    int i = 0;
    while (dr.Read())
    {
     if (i==0) 
      user_names += dr["user"].ToString();
     else
      user_names += comma + dr["user"].ToString();
     i++;
    }

    but the new and improved version is

    string comma = "";
    while (dr.Read())
    {
     team_uids += comma + dr["uid"].ToString();
     comma = ", ";
    }

    Now some stud will show me how this can be improved.  Always happens (which is pretty darn cool!), so check the comments in 24.

  • Using SQL to obtain unique values, a guilty pleasure

    I have a list of int IDs of individuals associated with a subject, with the list coming from various sources.  There are most likely duplicates, but I want unique values only.

    I considered what type of algorithm I would use.  An array perhaps, sort it and compare.  Quick sort?  Double-linked list?  Binary tree?  (I'm being ridiculous now.  Sorry.)  But then it hit me that all of the user IDs, regardless of their origination, were found in a users SQL table, so after obtaining a team_ids string which looked something like '3,44,313,313,12', I turned to SQL to be my brains:

     sql = "select distinct id from users where id in (" + team_ids + ") order by id";
     SqlDataReader dr = SQLHelper.ExecuteReader(sql);
     while (dr.Read())...
     

    KISS, baby.

  • More on handling SQL null dates


    Null SQL date values have been yankin' my nose hairs out of place lately, I think primarily because I'm using business objects more extensively which requires more value handling.  I'm going to say that the following is an Insider's TIP for handling null dates until someone tells me I'm full of crap, which inevitably seems to happen with Insider Tips.

    I want to display "N/A" if the date from my business object class property is null.  '1/1/0001' continued to display as I went through

    if (datein.Year == 1)..... if (datein.Year == null)....  if (datein.Year.ToString() = '1/1/0001').... if (datein.Year == System.DBNull.Value)

    Then I went with the following, which seems to do the trick.  Seems if I compare the Year of a null value to a date that I know is less than any other date in the system that I'll achieve the desired results.

    public string NAitDate(System.DateTime datein)
    {
     if (datein.Year < 1950)
      return "N/A";
     else
      return datein.ToShortDateString();
    }

     

  • Safe sex = celibacy = Outlook Level 1 File Type Security

    The original title of this post was going to be “Outlook Level 1 Security Blows” but I didn't want to come off as too righteous.  Besides, my encounter with this ingenious approach to enhanced security was yesterday and I'm better now.

    I needed an .MDB from our church secretary.  “Oh just send it to me as an email attachment,” I told her.  Then I discovered Microsoft Outlook Level 1 File Type Security, where 52 file extensions are blocked, and though your message may possess a paperclip, the infobar in the message window only tells you what file you cannot today, tomorrow, or ever retrieve...unless you want to hack the registery or something.

    How does this work?  Do a bunch of mid-managers get together in a Redmond second floor office somewhere around an oval table and someone poses the question, “How do we make Outlook more secure?“  Then someone says, “We can turn off the ability to receive attachments.“  And someone else who happens to be awake at the time says, “What?  Turn off file attachments!!“  And the originator of the thought says, “No, no, no.  Only 52 or so different file types.  We'll let .DOC and .XLS files pass.  I don't think they have any executable virus issues.“  And the questioner says, “Ohhh.  Okay.“  Heads nod. 

    Isn't this like the ultra-conservative line, that if you want to practice safe sex, you keep your winky in your pants?  And if you want to keep your pc safe from viruses, you cut off its ability to exchange files?

    For whoever thinks I'm being too tough here, I can give you the phone number of the church secretary and YOU can walk her through the process of renaming an .MDB file to a .TXT (“but gee, Dave, nothing I do works!  It still has that icon with the key on it!“), or walking her through FTPing to a secure file location on the internet (“no, that's F-T-P, as in 'Paul,' colon, forward-slash, forward-slash...no, the other one“, or Zipping up the file (“uh, what's winzip, again, Dave?“) 

    If I'm looking at this issue incorrectly, or if there IS a quick solution that I didn't discover in the two hours I wasted on it, then I'll apologize and promise never to use the word “winky“ again in my blog. 

    Outlook help on “About Unblocking Attachments“...

    If you need to share files that have file types blocked by this feature, you have several options, including the following:

    • Rename the files to include a temporary file type that is not on the list of blocked file types. For example, you might rename MyFile.exe to MyFile.exe_EXTRA, and then attach the file to the e-mail message. You can include instructions in the message to save the file with the correct name, for example, MyFile.exe, when the recipients save the file to their computers.
    • Use a program, such as WinZip, to package files before you attach them to your e-mail message. In your message, you can include instructions explaining how to extract the files from the package to make it easy for recipients to access the files.
    • Post the files to a secure network share. In your message, you can include a link to the share that you have given the recipients access to.

    If your organization uses Microsoft Exchange Server, your e-mail administrator can control which file types are blocked. For more information, contact your administrator. If you are the e-mail administrator, you can learn more about configuring blocked attachment behavior in Outlook by referencing the Microsoft Office 2003 Resource Kit.

     

  • Object reference instance error and the web.config

    Problem

    Your app is looking for an appsetting value in the web.config and when it isn't found generates the error 

    Object reference not set to an instance of an object.

    Resolution

    Add the friggen' appsetting value

    Analysis

    Wooo-wee!  This is a humdinger of a tough bug to track down.  Usually you'll have pretty clear information in the stack to pinpoint the missing object, or it may be something as obvious as a Label webcontrol missing in the .ASPX.  But there's very little to go on when its a missing appsetting value.  This error generally appears when testing a new app on a production server after updating the /bin/dlls, which is a bad thing.  This also makes diagnosis more difficult, so a documented procedure to update the server web.config prior to updating the dlls is a good thing.

    For more information

    See comments.

  • Compile less. Code more

    A would suspect a lot of developers compile their apps too often.  Its easier to sit there, watch a compile, and confirm a code update works correctly, than to keep banging out code and staying on message.  The longer a guy writes code the less they need to confirm that something works.  At least I'm finding that I'm compiling less often and being more productive as a result.  And there's room for improvement, as I'm more conscious of it.

    If I were a manager I'd probably watch a developer code for a while and would no doubt interject,

    “Why did you compile just then?“

    “To check my updates.“

    “You changed the text of a LABEL, for Christ's sake!“

    Another reason I wouldn't make a very good manager....

     

     

  • RoboCopy DOES solve all the world's woes

    I posted last night about authentication issues using RoboCopy to copy to HQ over VPN.  I stayed with it (like old dogs do) and found the solution.  Incredible but true, but the solution was to use a Windows 2000 Server as the destination instead of Windows 2003!

    One of those “Well I'll be darn!” fixes.  I'm sure someone knows the specific W2K3 technical reason why this is the case.  For me I'll conclude its one of those “all the doors and windows closed” compared to “all the doors and windows open” sort of things.

    btw, thank you to William Bartholomew and Michael Carr for your input on robocopy alternatives.  Those comments are found in the original.  I did investigate XXCopy and all I gotta say is SWITCH CITY, BABY!  /s /ca /cb, that sort of thing.  Hundreds of 'em.  They're in the xxcopy help file which I piped to a text file here.

     

  • Blank space economies

    Maybe I'm old school (heck, I know I'm old school), but I like using the tried-and-true <Table> and <img src=”/blank.gif”.. formatting approach to websites as opposed to CSS absolute positioning.  There were exceptions when I used the CSS absolute approach, but I use HTML formatting mostly.

    I rewrote an old page this morning and was curious how the approach to creating a blank space with a blank.gif file evolved.

    initially using a Label control

    lblBlanker.Text = "<img src=\"/images/utils/blank10x10.gif\" width=\"" +
     int.Parse(dr["width"].ToString() + 50).ToString() + "\" height=\"20\">";

    then using an Image control

    imgBlanker.ImageUrl = "/images/utils/blank10x10.gif";
    imgBlanker.Width = pw.width + 50;
    imgBlanker.Height = 20;

    then a static library

    Cntrls.DoBlanker(imgBlanker, pw.width + 50, 20);

    Less is less, after all.

More Posts Next page »