Home Contact Search Syndication   Login
  191 Posts • 2276 Comments • 158 Trackbacks   

 Recent Posts


 Search


  

 Archives

 Post Categories

 Ryan Farley Sites

Wednesday, September 12, 2007 #

A co-worker pointed out to me something cool that is coming in SQL 2008. A new keyword for MERGE has been introduced. This new type of statement reduces some of the tedious work you typically do when adding data to a table in SQL. As things are now, you will check for the existence of a row, and then proceed to update the matched row if it exists, or insert the new data if the matching row did not exist. The new MERGE keyword allows you to do this all in a single statement.

This new MERGE statement reduces the following pseudo code:

/*
    -- save parent table data
    If Data Indentifier found in Parent Data Table
        Update Data
    Else
        Insert Data
    End

    -- save child table data
    Delete from Child Data Table all items not in Data
    Update Child Data Table with all items in Data
    Insert into Child Data Table all new items in Data
*/

To the following:

/*
    -- save parent table data
    MERGE Data to Parent Data Table

    -- save child table data
    MERGE Data to Chid Data Table
*/

posted @ 7:57 AM | Feedback (6)

Wednesday, March 07, 2007 #

Dave Burke has a long running series of posts on his blog titled “CS Bytes” (example) and “CS Nugglets” (example). If you work with Community Server at all, you've probably found that these posts are pure gold. Completely invaluable information that I look forward to every day. I'm not sure I'd enjoy working with Community Server as much without Dave taking the time to gather all the best CS info for me ;-)

I have two new CS sites on the verge of going live. One a product site for an addon for the great CRM software SalesLogix called Outlook2CRM, and another for a user community site for professionals working with SalesLogix, called Good Training. Having worked with CS to build and customize these sites, I look forward to the great info collected by Dave every day (and the helpful people who post the stuff in the first place!)

Thanks for your help Dave! Long live CS Bytes and CS Nugglets!

posted @ 7:40 AM | Feedback (14)

Sunday, January 21, 2007 #

My son, Trapper, just had his 9th birthday party this weekend. I had my friend, Neil (kungfootrooper.com) come, who just completed his new Darth Vader costume to give the boys something to gawk over. Even though I knew it was my fiend Neil underneath I can't even describe how powerful and awe-inspiring it was to be in the presence of Darth Vader. Neil is a big guy and makes a really menacing Darth Vader. It was an indescribable feeling and felt like the fulfillment of a childhood dream to stand next to Darth Vader, up close and in person.

The picture does not do it justice but it will be a memorable experience. Thanks Neil. BTW, Neil just recently marched in the Rose Bowl parade in CA as a Storm Trooper and even got to meet George Lucas. Neil is documenting it on kungfootrooper.com.

posted @ 2:30 PM | Feedback (10)

Friday, December 01, 2006 #

I've mentioned my love for my RSS aggregator before, GreatNews. This week I came across a new user-submitted style for GreatNews called Web-2-Zero, created by Jorwa. This is a great looking style and is very pleasing to the eye - despite the name ;-)

Take a look:

There's a couple of things I didn't quite like about this style so I'm posting my own revised copy. The style posted by Jorwa was set to overflow into 2 columns, which is great for newspaper views, but for how I like to read (which is often posts with source code in them) I want to see the text in the full width, so I removed that. Jorwa's style also removed images from the text, again optimized for a newspaper view. I removed that as well. I also added a line after each post to separate each post when in a newspaper view and did a little different treatment for comments.

Speaking of GreatNews. I still love it as much as ever. I did test out the new Jubilee build of RSS Bandit this week. While it does have some great features and looks nice, you just can beat the speed of GreatNews. RSS Bandit felt a bit sluggish in comparison. Keep up the great work Jack!

posted @ 8:01 AM | Feedback (8)

Tuesday, October 24, 2006 #

Internet Explorer 7 introduced the Windows RSS Platform. The Windows RSS Platform will be a core part of Windows Vista, but with IE7 it is now avilable on XP as well. The new functionality in IE7 to consume RSS feeds is made capable by the Windows RSS platform. This new functionality exists in Outlook 2007 also, giving you the ability to consume RSS feeds in Outlook folders ala Newsgator style, which can also synchronize with the Windows RSS Platform.

What makes this all so cool is that you now have the ability to have a single common store for subscribed RSS feeds. Well, this is the goal I suppose, although it will take some time for RSS Reader vendors to switch over - if that ever happens. Newsgator/FeedDemon has a utility for synching the Newsgator online feed store with the Windows RSS Platform.

Accessing the Windows RSS Platform is a simple task. The RSS Platform is exposed by a COM-based API found in msfeeds.dll (in the System32 directory). Add a reference to the COM dll and add a using directive for the namespace in the generated interop assembly and it's all easy work to use. Although, do keep in mind that this is a COM based reference so you'll need to take care to properly release all objects.

Let's say we want to populate a TreeView control with the feeds found in the local RSS store. An easy enough task, take a look:

using System.Runtime.InteropServices;
using Microsoft.Feeds.Interop;
//..

private void loadFeeds()
{
    TreeNode rootnode = treeView1.Nodes.Add("Feeds");
    IFeedsManager feedmgr = null;
    IFeedFolder rootfolder = null;

    try
    {
        // instanciate a new FeedManager
        feedmgr = new FeedsManagerClass();
        
        // get reference to the root feed store folder
        // there is always a root 
        rootfolder = (IFeedFolder)feedmgr.RootFolder;

        // call method to recursively add subfolders and feeds to treeview
        addNode(rootnode, rootfolder);
        treeView1.ExpandAll();
    }
    finally
    {
        Marshal.ReleaseComObject(rootfolder);
        Marshal.ReleaseComObject(feedmgr);
    }
}
private void addNode(TreeNode parentnode, IFeedFolder folder)
{
    // check to see if the current folder has subfolders
    if (folder.Subfolders != null)
    {
        foreach (IFeedFolder subfolder in (IFeedsEnum)folder.Subfolders)
        {
            TreeNode foldernode = parentnode.Nodes.Add(subfolder.Name);
            // recursively add subfolders under current folder
            addNode(foldernode, subfolder);
        }
    }
    
    // if current folder has feeds add them under the folder node
    if (folder.Feeds != null)
    {
        foreach (IFeed feed in (IFeedsEnum)folder.Feeds)
        {
            TreeNode feednode = parentnode.Nodes.Add(feed.Name);
            feednode.Tag = feed;
        }
    }
}

Once you've gotten the list of feeds it is just as easy to get the items from a feed. In the example above I placed a reference to the feed in the tag of the TreeNode objects. Let's grab that on the TreeView's AfterSelect event and get the items from the feed to fill a ListView.

private void treeView1_AfterSelect(object sender, TreeViewEventArgs e)
{
    listView1.Items.Clear();
    if (e.Node.Tag != null)
    {
        IFeed feed = e.Node.Tag as IFeed;
        if (feed != null)
        {
            foreach (IFeedItem item in (IFeedsEnum)feed.Items)
            {
                ListViewItem li = new ListViewItem();
                li.Text = item.Title;
                li.SubItems.Add(item.PubDate.ToShortDateString());
                if (!item.IsRead) li.Font = new Font(li.Font, FontStyle.Bold);

                li.Tag = item;
                listView1.Items.Add(li);
            }
        }
    }
}

So now as a last task, when an item in the ListView is selected let's display the text for the item in a webbrowser control.

private void listView1_SelectedIndexChanged(object sender, EventArgs e)
{
    if (listView1.SelectedItems.Count > 0 && listView1.SelectedItems[0].Tag != null)
    {
        ListViewItem li = listView1.SelectedItems[0];
        IFeedItem item = li.Tag as IFeedItem;
        if (item != null)
        {
            // let's mark the item as read
            item.IsRead = true;
            li.Font = new Font(li.Font, FontStyle.Regular);
            
            // set the item's text in the webbrowser
            webBrowser1.DocumentText = item.Description;
        }
    }
}

So, that's easy enough. Just as easy to do other things as well, such as add a new feed to the local store.

private void addRyanFarleysFeed() // ;-)
{
    IFeedsManager feedmgr = null;
    IFeedFolder rootfolder = null;
    IFeedFolder folder = null;
    IFeed feed = null;
    
    try
    {
        // instanciate a new FeedManager
        feedmgr = new FeedsManagerClass();
        
        // get reference to the root feed store folder
        rootfolder = (IFeedFolder)feedmgr.RootFolder;

        // if we wanted to add the feed to an existing folder in the store
        // we could use the following (for example, if we wanted to store
        // the feed in a folder called "My Feeds")
        folder = (IFeedFolder)rootfolder.GetSubFolder("My Feeds");
        
        // if you didn't want to add it in a subfolder (ie: in the root instead)
        // then you'd just use the reference to the root folder
        
        feed = (IFeed)folder.CreateFeed("{ public virtual blog; }", "http://ryanfarley.com/blog/rss.aspx");
        // now force an async download of the items in the feed
        feed.AsyncDownload();
    }
    finally
    {
        Marshal.ReleaseComObject(feed);
        Marshal.ReleaseComObject(folder);
        Marshal.ReleaseComObject(rootfolder);
        Marshal.ReleaseComObject(feedmgr);
    }
}

So now in the course of about 10 minutes you've created your own simple RSS Reader that uses the Windows RSS Platform as the backend. Here's a screenshot of the sample I threw together using the same code I outlined above:


(click for larger view)

There's a whole lot more the Feed API can do, including downloading enclosures and more.

posted @ 9:54 AM | Feedback (16)

Monday, October 09, 2006 #

I've been a long time fan of TextPad. I live by my text editor. My text editor is probably one of the most highly used applications on my pc. Seriously. TextPad has been great and I've always loved it. I decided on TextPad years ago after I grew dissatisfied with UltraEdit, I've tried a few others along the way, such as Notepad2, but none would compare to my favorite TextPad. Funny thing is, I wasn't looking for a new text editor, but I came across a new one today that I had not heard of before and I decided to give it a try.

Enter Twistpad

Twistpad is an awesome text editor. It would have to be to get me to decide to move away from TextPad. Complete with syntax highlighting, plugin support, collapsable text blocks ala Visual Studio regions, code snippets & template support, a built in clipboard ring, and a whole lot more.

So what made me decide to switch? Well, one thing for sure, Twistpad is a really great looking app. It has a very Visual Studio looking UI, and I do like that. A lot. However, some of my favorite features are:

All in all, I am loving my new text editor. I have to say I didn't think the day would ever come that I would move away from TextPad. So far I love what I see. Sure there are some things that are missing, such as unicode support (coming in the next version) and maybe a shell extension to get better context menu support in Windows, but all in all I am happy.

posted @ 4:26 PM | Feedback (18)

Friday, September 01, 2006 #

I was catching up on some Scott Hanselman posts today after going through Scott's new Utilmate Tools list (which is a great list) and came accross Scott's post on Console. Wow. I am in love. I've always been a big command-prompt junkie and this app is the cat's meow. A tabbed console windows app with better support for copy/paste and so much more.

How is it that Scott always find out about these kinds of awesome apps. This one is worth using for sure. I'm on the 2.0 beta build 125. I have mine with tabs for loading the VS 2005 & VS 2003 environment vars on separate tabs and a few other custom ones for setting environment vars as well.

posted @ 9:13 PM | Feedback (16)

Wednesday, August 23, 2006 #

Phil Factor had a great post where he spins the creation of the world as an IT project. A really amusing read.

"Art thou sure of meeting the aggressive six-day schedule for this project, verily??"

The smartly-clad angels looked nervously around for a spokesman. After a moment, a well-groomed executive angel stepped forward.

"We have, er...hath..., a total commitment to quality delivery of an effective solution"

"...meaning?"

"Our mission is to achieve total excellence in meeting the timescales for delivery of the project to the defined and agreed scope".

"Quality...excellence...", harmonised the assembled IT angels, upon hearing this confirmation of their mission statement, and rustled their feathered-wings to signal their commitment and solidarity.

"..and we're all clear on the project deliverables?" asked God. "Being more of the instinctive sort of executive, I realise I may have been heavy on the overall project vision...you know 'let there be light', and that sort of stuff...and light on the practicalities. I'm not really a detail person. That's why I delegate that sort of thing to you. I can appreciate that this is really a logistics and facilities-management issue but, we're 5 days in to a 6-day project and exploding two-headed donkeys at this stage make me rather nervous."

posted @ 7:44 AM | Feedback (2)

Tuesday, August 22, 2006 #

I last posted about the null coalescing operator in .NET 2.0 and just had to post a follow up. I came accross a post on Born 2 Code .NET (via Dennis van der Stelt) where several examples of ?? syntactic sugar are listed to demonstrate how the null coalescing operator surpasses the ternary conditional operator (?:) and if constructs as far as usefulness and readability.

Here's a great sample from the post:

public Brush BackgroundBrush
{
    get
    {
        return _backgroundBrush ??
        (
            _backgroundBrush = GetBackgroundBrushDefault()
        );
    }
}

Which translates to (using a traditional if construct)

public Brush BackgroundBrush
{
    get
    {
        if (_backgroundBrush == null)
        {
            _backgroundBrush = GetBackgroundBrushDefault();
        }
        return _backgroundBrush;
    }
}

The idea here is that the ?? is evaluated first before the return, causing the assignment to occur in the case when the _backgroundBrush variable is null. That is just plain cool. Make sure you check out the link to the post on Born 2 Code .NET for more examples. Also check out Jon Skeet's post on doing elegant comparisons using the null coalescing operator as well.

posted @ 1:21 PM | Feedback (10)

Thursday, August 10, 2006 #

I blogged two years ago (See Nullable Value Types and the New ? Syntax, and More on Nullable Value Types) about the new nullable operator in .NET 2.0 (wow, was that really 2 whole years ago? Time flies.). Since then, I waited patiently for it's arrival. Ever since .NET 2.0 came out I've been wanting to return and blog about it again.

Here's a recap on the Null-Coalescing operator. It is a cleaner replacement for ternary conditional operator ?: and has some additional uses as well. Think of the SQL Coalesce function (or IsNull). It is a lot like that. It gives you the first non-null between the two as SQL Coalesce does, but it doesn't allow multiple conditions to be checked as SQL Coalesce does (unless you chain them together). If the left-side is null, it gives you the right side. The right side could be considered your “default“ in case the value on the left is null for some cases. I've always been a fan of using ?: but there was something about needing to, at times, repeat variables in the statement. Here's a sample of what I am talking about:

string name = getName();
Console.WriteLine(name == null ? "No name" : name);

For as much as I love using ?: I've just never liked having to specify the variable name twice in that line. Not a huge deal, but things are even better using the null-coalescing operator in this scenario:

string name = getName();
Console.WriteLine(name  ?? "No name");

Much nicer. Gives you the same warm-fuzzy feelings you get from the SQL Coalesce function, doesn't it? It get's even better as you think of the possibilities you have using the new ?? operator. What previously would have been this (with the ?: operator)

Customer customer = Broker.GetCustomer(id);
if (customer == null) customer = new Customer();

Now becomes this:

Customer customer = Broker.GetCustomer(id) ?? new Customer();

I feel the love. But don't forget about nullable types. Nullable types in .NET 2.0 allow you to use a use a value type that can essentially be null. For example, if you have an int, bool, or other value type, it is either uninitialized or a value. Never null. But what if you wanted/needed to indicate null for a value type? A nullable value type is declared with a ? following the type. Let's take a look at a nullable int.

int GetInt()
{
    int? id = null;
    return id ?? -1;
}

Ever since .NET 2.0 came out I've wondered why I don't see more of this syntax around. From everything I come accoss I don't find this very often. Maybe people are still getting used to it, but it sure is some cool stuff IMO.

posted @ 1:52 PM | Feedback (11)

Friday, August 04, 2006 #

If you've written code to work with Outlook before, you'll have met the Object Model Guard's messages about a program trying to access Outlook. This change was a real pain for developers when it was first introduced. Since then we've all made our way around it by writing extended MAPI code or using things like Redemption or Outlook Security Manager. However, I was reading some info on the code security changes in Office 2007 and came accross this:

Security in Outlook 2007 takes advantage of the status of antivirus software installed on a computer. This change represents a major departure from the way the Object Model Guard worked in the past. If Outlook is able to detect that antivirus software is running with an acceptable status, Outlook disables security warnings for the user. This allows external applications that previously had to resort to Extended MAPI or third-party libraries to avoid security prompts under the appropriate conditions. This new behavior helps keep Outlook secure without overwhelming the user with excessive warning messages.

That is some awesome news IMO.

posted @ 11:47 AM | Feedback (6)

Tuesday, June 27, 2006 #

I have a new favorite toy. Scott Hanselman mentioned Colibri on his blog so I thought I would give it a try. I can't tell you how much I am loving this cool tool. Colibri Type Ahead (which is free) is a combination of a quick start/launch and search program you use to quickly start up applications installed on your pc.

Hit a predefined hot-key and then just start typing the name of the application you want to launch. You'll be presented with a list of matches that narrow as you type. The best part is that you don't have to type the whole name, or even a part of it. You can type an abbreviation if you want. If I want to start PowerPoint, for example, I can just type “popnt” and it will match to PowerPoint. If more then one application match that name then I'll be presented with the choices. The coolest thing about Colibri is how it learns from you. If I type “vis” to start Visual Studio, and Visual Studio isn't the top of the list so I arrow down to select it. It knows that next time I type “vis” I probably mean Visual Studio so it will list it first.

Also, Colibri has integration with other various things, such as Google. I can hit the hot key to bring up Colibri, type “goo” then tab and enter my search term to perform a quick search. I can type “vol” and then up or down arrow to turn my pc's volume up or down quickly. It can launch control panel applets, and even has some integration coming for iTunes, Winamp, Firefox, etc.

I always seem to have a billion things installed on my pc at any given moment. While I do try to keep my start menu organized, it feels like such a chore sometimes to dig through the start menu looking for some app I hardly use (and can't remember where it is). Colibri sure makes that all easier. Not to mention Michael, the man behind Colibri, was totally willing to make a change that prevented it from working on my machine. That was just cool.


posted @ 2:42 PM | Feedback (9)

Tuesday, June 06, 2006 #

You may have read it already, but it's working linking to over and over again, Jeff Atwood has an excellent list of warning signs for Code Smells. Be aware of these warning signs. If you are seeing them in your code, then...I'm sorry. I really didn't want you to have to find out like this. Hehe.

A truly excellent list and something every developer should read. I've been guilty of some of those from time to time myself, but live and learn, right? As long as you are aware of those things that make your code downright stinky, then you can at least learn to improve.

posted @ 8:28 PM | Feedback (5)

Tuesday, May 30, 2006 #

I came across this list on CodeProject of SQL Queries to analyze SharePoint details and usage. This is an awesome list. Granted it does bypass the SBS object model so isn't the recommended route, but still a great list of queries you could use to make reporting on your SharePoint sites a breeze.

posted @ 11:45 AM | Feedback (3)

Thursday, May 25, 2006 #

I started this blog in August of 2003, almost 3 years ago. I've made 176 posts in those 3 years. I don't post too often to my blog because I'm not all that big on posting stories about my kids, wife, dog, etc - although those do come in every now and then. Anyway, even when I have lulls where I am not posting as much, my traffic seems to stay pretty consistent. I'm actually amazed at how much traffic I get, especially when I consider how often I get around to posting (big thanks to all the visitors over the years).

Some of my posts have apparently been useful :-), so I thought I would post the top 30 most popular posts I've made over the years (based on total number of unique views to the posts).

1. Set Focus to an ASP.NET Control
Setting focus to controls in your ASP.NET application is a part of giving your end users the feel that they have come to expect. Making your web applications act more like Windows applications is a key to success (IMO). While setting focus to con...
Total views: 371,568 - Posted on: 21-Dec-2004

2. Using the Web Browser Control in your C# Applications
It can be a powerful thing to display dynamic HTML in your C# applications. It can give your applications a modern look and feel and can make displaying data in non-standard ways easy with some simple markup. We have the web browser ActiveX control that wr...
Total views: 232,037 - Posted on: 23-Dec-2004

3. Writing to Your .NET Application's Config File
There's likely been times that you might have thought that it would make things convenient to write back to your .NET application's config file. The framework provides simple methods for reading from the config file, but gives you nothing for writing value...
Total views: 197,345 - Posted on: 13-Jul-2004

4. Tips for SQL Server Identity Columns
Tips on allowing inserts to identity columns and also for reseeding the identity value for a table....
Total views: 117,941 - Posted on: 19-Dec-2004

5. Multiple Monitors rule
I love multiple monitors. I can't even imagine trying to work without multiple monitors and don't think I could ever go back to a single monitor....
Total views: 96,533 - Posted on: 7-Jan-2004

6. Unable to Start Debugging on the Web Server
I hate that, and it seems that every time I (or a co-worker) gets the error “Unable to Start Debugging on the Web Server” on a machine when attempting to debug an ASP.NET project, I have to scramble to remember what to look at. Here's a few things that has...
Total views: 91,037 - Posted on: 23-Aug-2005

7. Stop Hijacking my Browser!
Often in applications you have the need to launch a browser window to a specified URL. I recently evaluated various RSS readers where links to blog posts could be launched in an external browser window. What I found was that most of these applications woul...
Total views: 90,029 - Posted on: 16-May-2004

8. Determining the Control that Caused a PostBack
Many times you might need to perform some action on an ASP.NET postback based on the control that caused the postback to occur. Some scenarios for this might include a form with many regions, each having it's own CustomValidator and the ability to perform...
Total views: 69,089 - Posted on: 11-Mar-2005

9. Solving problems through programming...and why the Skype API sucks
I love to take the approach of solving computing problems through programming. Sometimes it backfires and I over-complicate the problem (I have been known to prematurely generalize from time to time). But usually I bask in the greatness of being a programm...
Total views: 60,149 - Posted on: 14-Jan-2005

10. Enabling XP Themes in your .NET Applications
When you build Windows applications in .NET, by default your application will not have support for XP Themes, or Visual Styles. It is an easy enough task to do, and I think it goes a long way in giving your application a complete and professional look & fe...
Total views: 49,397 - Posted on: 5-May-2004

11. On the Subject of Dates in T-SQL
While we're on the subject of dates in T-SQL, I never liked getting the month and year for a date and sticking an '01' in the middle (then casting it all back to a datetime) to get the first day of the month for a given date value. Then you do the same to...
Total views: 42,317 - Posted on: 15-Feb-2005

12. Determining if a Date is a Weekday in T-SQL
I was reminded of a SQL function to determine if a date was a weekday or a weekend I wrote a while back when I saw the requirements of a project a colleague was working on. You'll see this requirement fairly often in many business applications. A company m...
Total views: 40,265 - Posted on: 14-Feb-2005

13. Awesome web.config Changes in ASP.NET 2.0
There are some really cool changes coming in ASP.NET's web.config files that I am really excited about. I'll just point out a few that I've used (I hate going back to 1.1 because I can't use them). The web.config file in ASP.NET 2.0 allows you to set a lot...
Total views: 40,145 - Posted on: 8-Jun-2004

14. Setting the Value of a TextBox with TextMode=Password
When the TextMode property of an ASP.NET TextBox is set to Password the value set in the Text property will not display at runtime. This can be a pain, however it is actually by design to prevent the unmasked password from being displayed in the HTML sourc...
Total views: 36,984 - Posted on: 18-Dec-2004

15. T-SQL Olympics
OK, there is not an Olympics for T-SQL - but there should be. A friend of mine and I were talking the other day about “gold-medal” T-SQL we've come accross. The one that wins the gold for me is the code I found a long time ago on SQL Server Central from Ma...
Total views: 36,617 - Posted on: 25-Oct-2004

16. T-SQL: SET vs SELECT when assigning variables
Do you know what the difference is between using SET and SELECT when assigning varaibles in T-SQL? Well, there is a difference. I came accross a great article by Narayana Vyas Kondreddi from the UK that describes the difference between the two....
Total views: 36,204 - Posted on: 1-Mar-2004

17. Interacting with the Web Browser Control
In my last post, I outlined some ways to make the Web Browser control more useful in your C# applications, to include things such as printing and setting the text or html of the browser dynamically. That is all good, but in a typical application it does li...
Total views: 35,885 - Posted on: 27-Dec-2004

18. Disabling the Windows Close action
There are times that you'll see a Window that has a close button in the titlebar, but it is disabled. This is often found in applications where the dialog/window changes it's status past a stoppable point so the Windows close action is removed so the user...
Total views: 35,796 - Posted on: 12-Apr-2004

19. Creating a IWin32Window from a Win32 Handle
There are times when you are integrating your .NET applications with other existing applications that you cannot modify and is possibly even non-.NET application. This can often result in problems integrating your .NET application's windows with the other...
Total views: 35,465 - Posted on: 23-Mar-2004

20. In Search of the Perfect RSS Reader
For the last year or two, I've been switching from reader to reader. While each one had features that I loved, they all seemed to fall short on one thing or another and I was never really 100% pleased with any of them. I went from SharpReader, to RSSBandit...
Total views: 33,384 - Posted on: 14-May-2004

21. Flattening Out Data with One of the Coolest SQL Tricks Ever
Not sure why, but I seem to be on a T-SQL kick lately - so here's another T-SQL post. One of my favorite T-SQL hacks ever is one that can flatten out data by taking a value from multiple rows and concatenating the values into a single string....
Total views: 33,281 - Posted on: 17-Feb-2005

22. Dynamically Loading Master Pages in ASP.NET 2.0
One of the cool new things introduced in ASP.NET 2.0 is Master Pages. Master Pages give you the ability to define a master page layout and look that is used throughout a site to give a consistent look & feel to all pages. Any updates or changes to the look...
Total views: 33,156 - Posted on: 16-Jun-2004

23. Communication between applications via Windows Messages
At times I'll build a suite of related, but separate applications. Even though each application is a separate executable, I like to be able to integrate the applications so they can work together. Sending messages between your applications is a great way t...
Total views: 31,548 - Posted on: 10-May-2004

24. Rendering Size (and other things) Correctly in FireFox
One thing that I just can't stand, is when a web page I build looks different in FireFox than how it looks in IE. Well, who doesn't?! The thing that really sucks is that there are things build in to how ASP.NET works that will cause this to happen. So unle...
Total views: 31,325 - Posted on: 6-Sep-2005

25. Returning Objects from Web Services
When I work with web services I want things to work the same way as if I were working with a local layer that returns objects, not data. I don't want my code outside of the service to even see the data, just the objects that represent the data. Who doesn't...
Total views: 27,545 - Posted on: 26-May-2004

26. Disabling Auto-Complete on ASP.NET Forms
Popular browsers, such as Internet Explorer and Firefox support something called Auto-Complete. You've seen this many times. You go to a online form and as you start to type in fields you get a drop-down showing values you've typed in that field before. Th...
Total views: 26,844 - Posted on: 23-Feb-2005

27. Intersection of Date Ranges
A friend of mine called me yesterday about a scheduling application he is working on. His question was so simple, or so it seemed, but it really drove me nuts. Basically he just wanted to find out if two date ranges intersected at all. Simple enough. It wa...
Total views: 24,593 - Posted on: 19-Aug-2004

28. Tricking out the Desktop
Something I have always been a sucker for is tricking out my desktop. I love any kind of tweak or gadget that enhances my pc and the whole user-experience thing. It's one of the many reasons I am looking forward to Vista. I've been a fan of applications th...
Total views: 24,497 - Posted on: 11-Jan-2006

29. Retrieving database independent schema information
Something that I think is often overlooked in the .NET Framework is the cool stuff you can get at using OleDbSchemaGuid to retrieve database schema information. I just thought of this again earlier today when I was reviewing a C# database application where...
Total views: 21,989 - Posted on: 3-Apr-2004

30. Creating Tracking Images for ASP.NET
Often with web applications you want to track traffic statistics to get a general idea of the number of visitors viewing a resource. Whether it be a web page, an RSS feed, an e-mail or whatever, you might want an inconspicuous way to determine that it has...
Total views: 21,725 - Posted on: 10-Jun-2004

Some of these are not as relevant now with .NET 2.0, so I guess I better get back on the bandwagon ;-)

posted @ 11:41 AM | Feedback (9)

Of course, this means I need to be a really good driver now. Hehe.

posted @ 9:50 AM | Feedback (11)

Wednesday, March 29, 2006 #

I came across Sky Software's EZShellExtensions.Net via The Daily Grind and decided to check it out. Wow. I have to say I just love this library. There are so many different kinds of shell extensions you can easily do with hardly any effort at all. Take a look at a few tests I threw together:

There is so much more that you can do this this library for shell extensions (see the link below for a full list of extensions you can do). Support for both VS 2003 and VS 2005, .NET 1.1 and .NET 2.0. Definitely worth checking out!

And no, I am not only posting this to get my free developer license ;-)

posted @ 2:41 PM | Feedback (7)

Saturday, March 25, 2006 #

After my last post on adding items to the page head in ASP.NET 2.0, Karthik Nataraaj asked if there was a way to add meta tags as well. You are in luck Karthik. The HtmlMeta class is provided for just that. You can easily create a HtmlMeta object and add it to the Controls collection in the HtmlHead class exposed via Page.Header. Here's a few samples:

// Render: <meta name="keywords" content="Some words listed here" />
HtmlMeta meta = new HtmlMeta();
meta.Name = "keywords";
meta.Content = "Some words listed here";
this.Header.Controls.Add(meta);

// Render: <meta name="robots" content="noindex" />
meta = new HtmlMeta();
meta.Name = "robots";
meta.Content = "noindex";
this.Header.Controls.Add(meta);

// Render: <meta name="date" content="2006-03-25" scheme="YYYY-MM-DD" />
meta = new HtmlMeta();
meta.Name = "date";
meta.Content = DateTime.Now.ToString("yyyy-MM-dd");
meta.Scheme = "YYYY-MM-DD";
this.Header.Controls.Add(meta);

posted @ 12:05 PM | Feedback (59)

Friday, March 24, 2006 #

I am easy to please when it comes to small and simple things that make my life as a developer easier. For example, I came accross something I had not noticed before in ASP.NET while reading a post from Dave Burke. The HtmlHead class exposed by the Page class as Page.Header. I love this. It makes it so easy to get to, and manipulate the header attributes for a page. A simple act of changing the page's title, style, etc before was a pain. Now it's just setting a few properties.

To change a page's title:

this.Header.Title = "This is the new page title.";

To add a style attribute for the page:

Style style = new Style();
style.ForeColor = System.Drawing.Color.Navy;
style.BackColor = System.Drawing.Color.LightGray;

// Add the style to the header for the body of the page
this.Header.StyleSheet.CreateStyleRule(style, null, "body");

To add a stylesheet to :

HtmlLink link = new HtmlLink();
link.Attributes.Add("type", "text/css");
link.Attributes.Add("rel", "stylesheet");
link.Attributes.Add("href", "~/newstyle.css");
this.Header.Controls.Add(link);

Simple and elegant. I guess I can finally get rid of my helper classes to do all of that and keep things simpler. Sad that I had not noticed that was there in 2.0 earlier.

posted @ 1:28 PM | Feedback (14)

Tuesday, February 28, 2006 #

There's something about the Web 2.0 buzz that's forced itself into the fore front over the last year that's never quite sat right with me. Milan Negovan recently made a post titled “Con 2.0” which summarized my own feelings on the subject perfectly (which Milan seems to do quite often). The problem with the hype around Web 2.0 is that there seems to be a real push to solve a problem I don't have. Sure the bells and whistles are cool and have a lot of “wow-factor” to them, but I seldom come accross a new feature that carries the Web 2.0 banner that provides me with any real, or new, value. Yet somehow, VC's seem to be itching to dump in funding.

Do I really need a shiny new web toy to give me more XMLHttpRequest driven features I really don't need? Russell Beattie really hits the nail on the head when in comes to Web 2.0 IMO:

Let’s go back in history (2004) to the conception of the term “Web 2.0? itself - the shining examples then were Amazon.com and eBay. They didn’t just open up their back ends for developers to use via XML APIs over the web, they made A LOT OF MONEY doing it. That was the key: Every Amazon.com API transaction ends up with a purchase from their site. Every eBay upload ends up with a listing or a purchase or something as well. It was clear, Web 2.0 was about platforms, open APIs enabling real business, not the overhyped traffic generators of the late 90s which did nothing but waste a lot of investor’s money.

But since then Web 2.0 has just mutated. Somehow the focus flipped from “making” platforms to “using” them. Ajax came along, Social Software and Tagging took over, RSS alone was considered an API, a few companies got bought, mobile was forgotten about completely and somewhere along the way the whole part about the “business” stuff went totally out the window. Hey, I’m all about creating useful and innovative software for your users, but if you can’t make a profit, you won’t be around long enough to make any sort of difference, and will probably cause more harm than good.

It's not like anything that helped coined the term Web 2.0 is anything new. Any real techie out there knows there's no real innovation, just the same stuff used in different ways. But I don't need that. What we need is something that revolutionized the web when it comes to getting real value for businesses and consumers. Make the internet more useful and give me more reasons to never leave my house ;-). I just don't think that some fancy client-side scripting is going to do that for me. I just don't get it.

David Ing posted a funny bit of code to sum up his thoughts on the subject. Nice.

posted @ 10:31 AM | Feedback (5)

Monday, February 13, 2006 #

Well. It's been a crazy week and I wanted to post about it. As I've mentioned before, I do try to keep the content here focused on C# or programming topics. However, a personal post does make it's way to my blog from time to time. This week I added another member to the band ;-)

Introducing, on the drums, Turner Farley - born Feb 9 2006!!

Reed - Age 10Trapper - Age 8Tate - Age 5Tess - Age 2Turner - Age 3 days

Speaking of kids, I was talking to my son Tate (5) about how he is cursed to be hairy when he grows up and he told me that when he is “old” he won't work, just play video games all day. So I asked him, if you don't work how will you buy food for your wife and kids. He thought for a second and then said “the wife can do that”!  Doh.

posted @ 2:13 PM | Feedback (13)

Monday, February 06, 2006 #

For anyone interested or those who work with MSCRM, I've decided to put up a new blog dedicated to MS CRM development. It's still just a wee baby, but I plan to post somewhat regular content there.

I do still plan on keeping this blog up to date as well with C# and general development topics.

posted @ 12:08 PM | Feedback (5)

Tuesday, January 31, 2006 #

I was making some changes to a website where I had some PDF files and I wanted to be able to post thumbnail images of the PDF file. There were enough PDF files for me to want to take the lazy route and write some code to do it for me. I didn't want to go out and get some library that might have been able to do this for me, so I started poking around to see what I might already have to get the job done quickly.

Turns out that Adobe Acrobat Professional does expose quite a bit via COM. So I decided to see how far I could get with it to accomplish the task of generating thumbnail images for my PDF files. Well, guess what? It worked. Sort of. I could successfully open the documents and get a reference to a page in the PDF, the problem was then getting an image of the page for the thumbnail. But, the page class does have a CopyToClipboard method where you can copy the currently referenced page to the clipboard (and even specify the rect coordinates you want to copy). While I am not thrilled about using the clipboard, I couldn't find any other route to get the task done, so I decided to go with that. Once you get the page copied to the clioboard, it is easy enough to get the clipboard data as an image and use it however you need.

So I created an app that traversed the PDF images in a directory creating a thumbnail for each one. Pretty easy. Not the fastest thing ever, and it does use the clipboard so that rules out using this from a serviced context, but all in all it got the job done with flying colors. I put together a scaled down version of the app as a demo so I could post about it here. Here's the code in a simple form to generate a thumbnail image for the first page in the PDF file:

// add reference to "Acrobat" COM server defined in "acrobat.tlb" 
// add using directives 
using System.Runtime.InteropServices;
using System.Drawing;
//...


Acrobat.CAcroPDDoc doc = null;
Acrobat.CAcroPDPage page = null;

try
{
    // instanciate adobe acrobat
    doc = (Acrobat.CAcroPDDoc)new Acrobat.AcroPDDocClass();

    if (doc.Open(@"C:\MyFile.pdf"))
    {
        if (doc.GetNumPages() > 0)
        {
            // get reference to page
            // pages use a zero based index so 0 = page1
            page = (Acrobat.CAcroPDPage)doc.AcquirePage(0); 

            // get dimensions of page and create rect to indicate full size
            Acrobat.AcroPoint pt = (Acrobat.AcroPoint)page.GetSize();
            Acrobat.CAcroRect rect = new Acrobat.AcroRectClass();
            rect.Top = 0;
            rect.Left = 0;
            rect.right = pt.x;
            rect.bottom = pt.y;

            // copy current page to clipboard as image 
            page.CopyToClipboard(rect, 0, 0, 100);

            // get image from clipboard as bitmap
            IDataObject data = Clipboard.GetDataObject();
            Bitmap bmp = (System.Drawing.Bitmap)data.GetData(DataFormats.Bitmap);

            // calculate new height and width for thumbnail and maintain aspect ratio
            int h = (int)((double)pt.y * ((double)100 / (double)pt.x));
            int w = 100;

            // create thumbnail
            Image img = bmp.GetThumbnailImage(w, h, null, IntPtr.Zero);
            img.Save(@"C:\MyThumbnail.jpg", System.Drawing.Imaging.ImageFormat.Jpeg);
        }
    }
}
catch
{
    // if we get here and doc is null then we were unable to instanciate Acrobat
    if (doc == null) MessageBox.Show("Acrobat is not installed. Adobe Acrobat is required.");
}
finally
{
    if (page != null) Marshal.ReleaseComObject(page);
    if (doc != null) Marshal.ReleaseComObject(doc);
}

One thing to mention. The CopyToClipboard method does allow you to specify “zoom“, so why not just use that to size the thumbnail? When you specify a smaller zoom ratio, the image copied to the clipboard is still the size of the entire original document but has the image of the page sized smaller in the corner. Not exatly what I wanted. So I get the full image and then size it myself. Also, if you wanted, you don't have to size it smaller if you also wanted a full size image of the page.

I threw together a small sample app using the code above to display and save any page from a PDF file.

Feel free to download the code for your own use (.NET 2.0 required and Acrobat 7.0 Pro is also required. Version 7.0 is only required since that is the version my interop DLL is generated from although this does work with other lower versions as well)

posted @ 1:23 PM | Feedback (18)

Friday, January 27, 2006 #

I was playing around with various ways to launch SQL Reporting Services reports and came across a good tip. If you work with SRS then you'll likely know you can launch a report by simply accessing the Uri to the report. For example, to launch/display a report called MyReport (at the root of the report server) you would launch the following in a browser:

http://MYSERVER/ReportServer?MyReport&rs:Command=Render

BTW, you can also omit the “rs:Command=Render” at the end since that will be the default behavior anyway. But something cool you can also do (and this is the tip part I wanted to share) is that there are also other RS format types available that you can specify to export the report directly. If you wanted to export the same report automatically to Excel you would use the following Uri to the report:

http://MYSERVER/ReportServer?MyReport&rs:Command=Render&rs:Format=Excel

That is pretty cool. If you wanted to export the report to a CSV file (or other formats too) you can specify that as well, and even indicate the delimiter too. For example, to export to CSV and use a Tab (ascii 9) as the delimiter you would use the following:

http://MYSERVER/ReportServer?MyReport&rs:Command=Render&rs:Format=CSV&rc:FieldDelimiter=%09

You can use any of the following: HTMLOWC, MHTML, PDF, IMAGE (for a Tiff file), CSV, and XML.

posted @ 8:44 AM | Feedback (78)

Friday, January 13, 2006 #

I have to say it, I love the new SQL Server 2005 Integration Services (SSIS). Wow. There is some really awesome stuff in there that really just blow me away. There are so many new things in SSIS that I just love - too many to mention. However, it is some of the smaller, less noticed, features that have come to be my favorites. Here are my top 3 small features in SSIS (so far).

The new DTSX extension is now associated to SSIS. When you save a SSIS package as a file (which I find I do quite often now with SQL2005 instead of saving them in the msdb). What this association does is two things; 1) You can double click on a DTSX file and get a dialog to edit the package properties, such as connections, commands, configurations, etc (see dialog below). You can also execute the package from this dialog. Just awesome.


(Click for larger image)

All you need to do is double-click a DTSX file to get this dialog (or right-click and select 'Open'). No need to run dtsrunui and then browse for it like you would have to with DTS files (but that wouldn't give you the same ability to edit properties like you can here, only global vars), although you can still do that if you want to for saved DTSX files (or any SSIS package) by running DTExecUI. If you right-click on a DTSX file you can select 'Edit' which will open the package in Visual Studio's BI designer for editing.

You have complete control over flow. The part where this really hit me is the granularity of control you have over flow for individual column transforms.

You can specify to redirect any rows where a certain column's lengh might be truncated or where there might have been an error for the data in a critical column. The redirect thing just blows my mind. How did we ever survive without that in old-school DTS? (I'll tell you how, with a lot of pain in the butt flow control and failing tasks just because some non-important value would have been truncated. That just sucked). Control is good. More detail the better.

The Package Explorer rules. Not much more you can say there.

You have a complete bird's-eye view of the entire package. But not just for viewing, but also for a quick and easy way to modify properties in the package. No need to go around clicking on tasks or other items in the designer, you just have the hierarchy of items in the package and can easily select one and modify it's properties in an easy to use standard property list. Way too cool.

It's those small things that make me so happy *snif*.

posted @ 3:50 PM | Feedback (10)