<CharlieDigital /> Programming, Politics, and uhh…pineapples

10Oct/08Off

A Sinking Ship

Posted by Charles Chen

Christopher Buckley straps on his lifevest:



Sorry, Dad, I'm Voting for Obama


Let me be the latest conservative/libertarian/whatever to leap onto the Barack Obama bandwagon. It’s a good thing my dear old mum and pup are no longer alive. They’d cut off my allowance.


Or would they?


...Sarah Palin is an embarrassment, and a dangerous one at that. [Kathleen Parker]’s not exactly alone. New York Times columnist David Brooks, who began his career at NR, just called Governor Palin “a cancer on the Republican Party.”


...John McCain has changed. He said, famously, apropos the Republican debacle post-1994, “We came to Washington to change it, and Washington changed us.” This campaign has changed John McCain. It has made him inauthentic. A once-first class temperament has become irascible and snarly; his positions change, and lack coherence; he makes unrealistic promises, such as balancing the federal budget “by the end of my first term.” Who, really, believes that?


As for Senator Obama: He has exhibited throughout a “first-class temperament,” pace Oliver Wendell Holmes, Jr.’s famous comment about FDR.


I’ve read Obama’s books, and they are first-rate. He is that rara avis, the politician who writes his own books. Imagine.


Obama has in him—I think, despite his sometimes airy-fairy “We are the people we have been waiting for” silly rhetoric—the potential to be a good, perhaps even great leader. He is, it seems clear enough, what the historical moment seems to be calling for.


So, I wish him all the best. We are all in this together. Necessity is the mother of bipartisanship. And so, for the first time in my life, I’ll be pulling the Democratic lever in November. As the saying goes, God save the United States of America.

Filed under: News No Comments
10Oct/08Off

Getting SharePoint Task Assignee

Posted by Charles Chen

One of the more interesting problems I've been working with is trying to figure out how to get the user information for the assignee (whom the task is assigned to). Getting the user ID and the the user display name is easy enough, but then that entails another lookup to find the the login name for the user.

For example, here is some code which retrieves the user information, but as a string:

using (SPSite site = new SPSite(siteUrl))
{
    using (SPWeb web = site.OpenWeb())
    {
        SPList tasks = web.Lists["Tasks"];
 

        foreach (SPListItem task in tasks.Items)
        {
            string assignedTo = Convert.ToString(task["Assigned To"]);

            Console.Out.WriteLine("> {0}", assignedTo);
        }
    }
}

This generates the following output:

> 37;#Brad Wright

> 40;#Daniel OConnor

> 46;#Charles

As mentioned, this is only part of the information we're after. To get the login name, we'd have to do some simple string parsing and then make a separate call to look up the user. Not a terrible amount of work, but more work, nonetheless.

Stepping through the debugger, I could see that the actual type of the field was SPFieldUserValue. My first attempt was to see if I could convert the value directly; no go. It turns out that the value retrieved (before calling the ToString()) is already a string. I ended up fumbling around with the very awkward GetFieldValue() method on the SPField class. It's not at all intuitive on how this method is supposed to be used, so I'm hoping this is useful:

using (SPSite site = new SPSite(siteUrl))
{
    using (SPWeb web = site.OpenWeb())
    {
        SPList tasks = web.Lists["Tasks"];
 

        foreach (SPListItem task in tasks.Items)
        {
            string fieldValue = Convert.ToString(task["Assigned To"]);

            SPFieldUserValue assignedTo = (SPFieldUserValue)
                task.Fields["Assigned To"].GetFieldValue(fieldValue);

            Console.Out.WriteLine("> {0} ({1})", 
                assignedTo.User.Name, assignedTo.User.LoginName);
        }
    }
}

And here is the output

> Brad Wright (FP1\bwright)

> Daniel OConnor (FP1\doconnor)

> Charles (FP1\charles)

The call is all kind of awkward and is completely non-intuitive. It's easier to think of it as item.Fields["Some Field"].ConvertToNativeOutputType(fieldValue). So you can see, this is a much more convenient way of retrieving the user from a list item (or any typed return value) once you get the hang of the weird nomenclature and usability issues.

Filed under: SharePoint No Comments
10Oct/08Off

The Unexpected

Posted by Charles Chen

As usual, the NRA endorsed a Republican candidate.  But in an unexpected move that no one saw coming, the American Hunters & Shooters Association has endorsed Barack Obama.



Senator Obama has clearly demonstrated his commitment to the 2nd Amendment.


His support of the Vitter amendment to HR 5441, the Department of Homeland Security Appropriations bill of 2007, is particularly telling. This amendment prevents the Government from confiscating guns in a time of crisis or emergency. Senator Obama's vote demonstrated a fundamental understanding of the meaning of the 2nd Amendment which means he recognizes the individual right of all citizens to keep and bear arms.


In addition, Senator Obama's commitment to conservation and protection of our natural resources and access to public lands demonstrates to us his commitment to America's hunting and shooting heritage.


Senator Obama will be a strong and authentic voice for America's hunters and shooters and it is with great pleasure that we endorse his candidacy.


It often slips by that Obama graduated from Harvard Law and was the selected to be the frst black president of the Harvard Law Review.  Not to mention that he taught Constitutional Law at the University of Chicago.  I think if there's one guy that's going to stand up for your Constitutional rights, it's this guy.


There is some controversy as to whether this group is legitimately pro-2nd Amendment, but the quote from their wiki page sums up their view the best:



"Because the gun issue has recently become a factor in the Democratic primary in Pennsylvania, I want to share the remarks I made today... [Millions of gun owners] not only wanted an organization that would protect their gun rights but an organization that was also committed to the protection of their communities as well as the protection of our lands."


The "communities" part is the most important, IMO.  Obviously, what is sensible in rural South Dakota isn't necessarily what is sensible in downtown Newark.


What's perhaps a bit more amusing is the Rednecks for Obama group.  A great quote from one of the group's founders:



"I don't care about his beer, I care about his intelligence.  We've had many democratic presidents, and we will still have our guns.  He is brilliant.  And he's not an elitist, though he has the education to be."


-Tony Viessman


Well said, Tony, well said.


And if you are still asking yourself "just who is Barack Obama?" then check out this Youtube video.




The kids are too damn cute.

Filed under: News No Comments