Monthly Archives: July 2008

ASP.NET File Upload with *Real-Time* Progress Bar – redux

So, guess who just got the memo …

Dear Matt,

Uploading large files with ASP.NET is difficult.

Sincerely,

Every ASP.NET Developer and their Mother

After sufficiently embarrassing myself with my earlier post, I decided it was high time I spend a little bit more time understanding this problem. And lo and behold Jon Galloway has already written up a nice survey on the topic. So to bone up on the issues I followed all of the links Jon provided as well the ones provided by all of the one-off emails I received in response to my previous post (thanks everyone).

Of all the upload components I checked-out (SWFUpload, FileUp, Flajaxian FileUploader, RadUpload, NeatUpload, ASP.Net File Upload/Download Module, etc…) I was the most interested in the last 2 (NeatUpload and ASP.Net File Upload/Download Module). They are both free, have my kind of licensing and come with the full source code.

So I downloaded both of these components and played around with plugging them into the demo app I blogged about previously. Both components include progress bar web controls, but I already have a progress bar widget that I really like. So my focus was on seeing what it would take to leverage only the HttpModule portion of these components and checking out how I could have the module interface with my progress bar. Like I mentioned previously, I want something that looks like this …

image

image

image

NeatUpload Vs. Darren Johnstone’s ASP.Net File Upload/Download Module

Both NeatUpload and Darren Johnstone’s components seem to have a rather large following, but I chose to see how I could extend Darren’s control because it was already using AJAX plus a custom HttpHandler to communication the upload progress back to the client. And that seems really close to what I wanted. If this doesn’t pan out, NeatUpload actually seems to have a larger following so I will probably go back and revisit this topic using NeatUpload instead.

How it Works

From what I can tell, Darren’s component basically works by injecting a hidden INPUT element into the form that contains the file INPUT(s). The value of the hidden element is a Guid that contains a well-known prefix (Darren uses the token ::DJ_UPLOAD_ID::). Then as his custom HttpModule is processing the request, it looks to see if the form contains this token. If so, he tucks the upload progress information into memory using the id value as the index. Then, if a client wants to query the upload progress, they can query his component using this guid as the look-up value.

Below is a screen capture of the request body. The hidden field is highlighted in yellow.

image

Querying the Upload Status

The second cool thing about Darren’s control is that he has included a custom handler for accessing the progress of an upload. This makes is pretty simple to get at the upload progress using your favorite AJAX library. Below is a small snippet of JavaScript that I am using in my demo app for getting at the status of the current upload.

intervalID = window.setInterval(function(){       var request = new Sys.Net.WebRequest();     request.set_url('UploadProgress.ashx?DJUploadStatus=' + token + '&ts=' + new Date().getTime());     request.set_httpVerb('GET');                     request.add_completed(function(executor){              //  the progress is returned as xml         var e = executor.get_xml().documentElement;                            var empty = e.getAttribute('empty');              if(!empty){                      //  extract the attributes I am interested in             var percent = e.getAttribute('progress');             var file = e.getAttribute('file');             var kbs = Math.round(parseInt(e.getAttribute('bytes')) / 1024);                 var size = Math.round(parseInt(e.getAttribute('size')) / 1024);                                              //  update the progressbar to the new value             progressBar.set_percentage(percent);             //  upadte the message             updateMessage('info', 'Uploading ' + file + ' ... ' + kbs + ' of ' + size + ' KB');                          if(percent == 100){                 //  clear the interval                 window.clearInterval(intervalID);                                     }                                }                         });            //  invoke the request     request.invoke();      }, 1000);

Sample App

No live demo this time, but I do have a sample application. You can download it here.

Conclusion

Well, that’s about it. I am curious, how have you handled file uploads in the web apps you have worked on? 3rd party component? Something home-grown? One of the components I mentioned above?

That’s it. Enjoy!

SSH-Agent Saves Time During Remote Logins [Command Line]

If you’re constantly logging into a remote server using SSH and you’re sick of typing your password every time, tech site Webmonkey details how to save time without sacrificing security. Using SSH-Agent, a utility that acts as a broker between your local machine and remote machine, you can log in without typing your password every time (but also securing your private key from attackers). Hit up Webmonkey to get the rundown on using SSH-Agent on Linux, Mac, and Windows. This one could have done well on yesterday’s list of top 10 command line tools.


Top 10 Command Line Tools [Lifehacker Top 10]


When you need something done quickly, efficiently, and without any software overhead, the command line is where it’s at. It was the first way humans told computers what to do, but as graphics became increasingly important, the command line, or terminal, became an insiders’ secret weapon. But with the right commands and a little bit of know-how, anyone can get things done from a text-only interface. Let’s take a look at 10 commands and tricks that make the terminal more accessible, and more powerful, on any system. Photo by blakepost.

Note: Mac OS X and Linux users have robust command line interfaces baked right into their systems. To get to them, head to Applications->Utilities->Terminal in Finder. It varies in Linux, depending on your distro and interface, but a "terminal" can usually be found in an "Accessories" or "Utilities" menu panel. Windows users are best served by installing and configuring Cygwin, a Unix emulator, which we’ve detailed in a three part series.

10. Customize your prompt

term_customized.jpgIf you’re going to spend any time at the terminal, or want to start doing so, it should be a welcoming place. To go beyond green or white on black, check out this Ask Lifehacker response, in which Gina runs through a few simple ways to change the colors, and the greeting message, on your prompt for Windows, Mac, or Linux systems.

9. Force an action with sudo !! (“bang bang”)

sudo_bang_bang.jpg You already know that prefixing a command with sudo makes your system execute it with superuser privileges. But when you forget to sudo, the !! or "bang bang" comes to the rescue. When you've perfectly crafted a long command that does exactly what you need, hit Enter, and d'oh—you don't have sufficient access privileges—you can sudo !! to repeat the last command with superuser privileges. It’s the ultimate nerd triumph: “Oh, you didn’t like that command? Well, then sudo !!

8. Create whole directory trees with mkdir

When it comes to organizing music, pictures, documents, or other media, nested folders become a necessary annoyance—as in right-clicking, choosing "New Folder" and then naming and clicking through each of "The Beatles->White Album->Disc 1." It's far easier from the terminal, as the Codejacked blog points out:

mkdir The BeatlesWhite AlbumDisc 1

Some terminal users have to add a before spaces, but you get the idea. If you’re a Vista user who’s just not down with Cygwin, you can still pull this off with the md tool in command line.

7. Filter huge lists with grep

Some terminal commands spit back a bit too much information, and that’s where grep comes in. Need to manually kill a faltering Thunderbird? Punch in ps aux | grep bird, and you’ll get back the specific number to kill. Need to know which files don’t have your company name in them? grep -v DataCorp *.doc. Programmer Eric Wendelin explains grep more in-depth.

6. RTFM with man (and more)

man_cropped.pngLet’s say a program, or web site, has just asked you to run a command to unlock or enable something, but you’d like to know just a little more before jumping in. Add man before the command (as in man ssh) and you’ll get manual-style pages detailing how to use the command. Bit too much material to process? Try whatis for a brief description, --help after the command for basic usage, or any of these other command-line learning tools.

5. Manage processes with top

Most systems have a tool to view “tasks” or “running programs,” but they usually hide the true guts of what your system’s doing from you. The Hackszine blog points out that Mac and Linux users can harness the power of the built-in top command to track and kill runaway processes making your system unstable. There’s also ps -aux for a single-screen, non-updating look at what’s bugging your computer.

4. Master wget for powerful file-grabbing

wget_cropped.jpgThe wget command has been around since before there was all that much stuff to actually yank from the net, but this extensible, multi-purpose tool has lots of great uses these days. You can mirror entire web sites locally, resume huge downloads on the flakiest of connections, download the same file every hour to keep tabs on a project, and do much, much more with wget. It’s one of those elegantly simple tools that’s only as powerful as your creativity.

3. Get way beyond system searching with find

Once again, programmer Eric Wendelin offers real-world examples of how powerful a command line tool like find can be in, well, finding files and directories that match the smallest criteria you can imagine. Want a list of every HTML file that references the hexidecimal color #FF0000 (red)? find can totally do that for you. As Wendelin points out, find, by itself, is about as convenient and powerful as a total-system searcher like Google Desktop or Quicksilver, but piped into and out of other tools like grep, it’s a powerhouse. For a more pared-down look at some of find‘s powers, check out this tutorial at Debian/Ubuntu Tips & Tricks.

2. Set up powerful backups with rsync

rsync_cropped.jpgYou can spend a lot of money and time hunting down a perfect backup app that works with all your systems just the way you want. Or you can spend a few minutes learning the basics of rsync, the flexible, powerful command that makes one folder (on your system) look like another (where you back up). To put it simply, rsync is a cross-platform, completely free Time Machine, if you use it right. Luckily, Gina’s already shown us how to do that.

1. See your most-used commands with history, make aliases for them

awk_cropped.jpgOnce you're comfortable with the terminal and getting good use from it, you might notice some of the more useful commands require an astute memory and typo-free typing—unless you make them shorter and easier. Start off by copying and pasting this command (on one line):

history|awk '{print $2}'|awk 'BEGIN {FS="|"} {print $1}'|sort|uniq -c|sort -r

It will return a ranked list of your most commonly-entered commands using your command history—and you can start creating aliases to shorten them and make them easy to remember. Or you could search through your recently-used commands with as-you-type results for quick-fire repeats.

While these 10 commands are generic and applicable on all systems with a Unix-like terminal, Mac OS X offers a few Mac-specific tools. Here are useful command line tricks for Mac users.

We're love to have some CLI fun around here, and we know our savvier readers have tons of cool terminal hacks and tricks that are new to us. So, please—share the knowledge and spread the wealth in the comments.


How to Sync Any Desktop Calendar with Google Calendar [Google Calendar]


As of yesterday’s announcement of CalDAV support in Google Calendar, you can now sync your Google Calendar with virtually any popular desktop calendar for free. Not only can you enjoy your favorite desktop calendar software and still get the benefit of the web interface, but you can also sync any desktop calendar with any other across platforms using GCal as a go-between. Let's take a comprehensive look at how to set up bidirectional syncing between Google Calendar and your favorite desktop calendar—from Outlook and iCal to Sunbird and Thunderbird—for free.

Remember, this doesn't mean that you can sync Google Calendar with just one desktop calendar. It means that no matter what you're using—Outlook at work and iCal at home, for example—you can always stick to desktop calendars if that's what you prefer. Google Calendar now works as both a great web application and a dedicated syncing tool. It’s the cloud, and once it’s set up, you don’t ever have to access your calendar through the web again if you don’t feel like it. But when you’re not at a desktop, you can fire up GCal from any web browser, make changes, and still be confident your desktop is completely in sync next time you fire it up. Let’s get started.

Sync Microsoft Outlook with Google Calendar

Syncing calendar events between Outlook and Google Calendar has been a cinch ever since Google came out with Google Calendar Sync, a free application that provides bidirectional syncing between the two. (It also supports one-way sync in either direction, if for some reason you don’t want two-way syncing.) Assuming you’re using a supported setup (Outlook 2003 or 2007 and either Vista or XP), here’s how to get it working.

  1. Download and install Google Calendar Sync.
  2. Enter your Google account email address and password.
  3. Select your sync method (most likely you want two-way syncing) and the sync frequency you prefer. It defaults to syncing every 120 minutes, which seems a little long for most.
  4. Hit Save and you’re done. Easy, right?

sync-now-gcal-outlook.pngIf you’ve added a new item to your calendar and you want to force a new sync rather than waiting for Google Calendar Sync to run its next sync, just right-click the system tray app and choose Sync. It doesn’t get much simpler than that.

Sync iCal with Google Calendar

As of yesterday, Google Calendar supports two-way synchronization with iCal through the CalDAV remote calendar standard. Setting up iCal with GCal varies slightly based on whether or not you’re using your default GCal calendar or a secondary calendar. First, here’s how to set up your Google Calendar default with iCal:

  1. gcal-to-ical-setup.pngOpen iCal, then fire up your iCal Preferences (iCal -> Preferences or Cmd-,).
  2. Click on the Accounts tab, and then click the ‘+’ button to add a new remote calendar to iCal.
  3. Call the calendar whatever you want (I went with ‘Personal’ for my main calendar), then enter the Google account username (which is normally your Gmail address) and password.
  4. Click on Server options to display the Account URL text box. For your default calendar, enter the following URL:

    …replacing youremail@gmail.com with your actual email address.

  5. Once you’ve done that, just hit Add and you’re finished. Give iCal a few minutes to download all your events and you’re good to go.

calendar-settings.pngIf you want to add a secondary calendar, the steps are exactly the same as above with one small difference. Instead of inserting your email address in the Account URL as described in step 4, you need to grab the calendar ID for that specific calendar. You can find it by opening GCal, clicking the arrow next to the calendar you want to sync, and selecting Calendar settings. In the settings, find the Calendar Address section near the bottom of the window, then just copy and paste the Calendar ID (which is formatted like an email address) in place of youremail@gmail.com in the URL above.


You can refresh iCal to make sure you've synced the latest-and-greatest at any time by selecting Calendar -> Refresh or hitting Cmd-R. (Original post)

Sync Mozilla Sunbird or Thunderbird with Google Calendar

thunderbird-with-lightning.pngWhether your using Mozilla’s standalone calendar application Sunbird or Thunderbird with the Lightning extension installed (Lightning integrates Sunbird into Thunderbird), bidirectional calendar syncing between either application and Google Calendar is a breeze. The special sauce in this sync is the Provider for Google Calendar extension. Installing Provider in either Sunbird or Thunderbird is basically the same procedure, and here’s how it works:

  1. Download and install the Provider extension by saving it to your desktop, opening the Add-ons dialog in either Sunbird or Thunderbird, and dragging the file you just downloaded into the Add-ons dialog. Once installed, make sure to restart the application.
  2. Now that Provider is installed, you have to add your new Google Calendar. In Sunbird, go to File -> New Calendar; in Thunderbird, it's File -> New -> Calendar when you're in the calendar view.
  3. You’re now looking at the Create new calendar wizard. Select “On the Network” and hit Continue.
  4. new-calendar-t-bird.pngChoose Google Calendar as the calendar type. The Location field requires the XML flavor of your calendar’s Private Address, which you can get by opening GCal and choosing Calendar settings from the drop-down next to the calendar you want to access. At the bottom of the settings page you’ll see the Private Address section. Copy the XML link and paste it into the Location field in Sunbird or T-bird.
  5. When you hit Continue, you’ll be asked for your Google Calendar username (again, your Gmail address) and password. Enter it, give your new calendar a name, and hit Continue. You’re done.

From now on, any event you add to that calendar will automatically sync to GCal and vice versa. You can reload the calendar to get the most up-to-date information at any time by clicking the Reload button in your toolbar. (The button is installed in the toolbar by default in Thunderbird, but you may have to customize your Sunbird calendar to add it to the toolbar.)

Sync Your Mobile Device with Google Calendar

If you’re interested in syncing your mobile device with Google Calendar, you’ve also got a ton of great and free options. BlackBerry users can check out Google Sync, a BlackBerry app made by Google specifically for Gcal-to-BlackBerry syncing.

gcalsync.pngAlternatively, the free, open-source application GCalSync does bidirectional syncing between Gcal and tons of supported phones. (Original post)

If you’re an iPhone or iPod touch user, you can set up automatic, two-way syncing between your Google Calendar (and Gmail contacts) with web site NuevaSync. (Original post)

Finally, if your phone supports SyncML, web application GooSync can handle Gcal syncing without installing anything.

Other Options

If you're not happy with the methods detailed above—which I selected because each represents the easiest and cheapest (read: free) option—there are still tons of other tools to sync Google Calendar with your desktop calendar. First, we've covered how to sync Google Calendar and Gmail contacts with the more technical GCALDaemon. Also, the cross-platform Calgoo just went free, with both Outlook and iCal syncing capabilities.

On a somewhat unrelated but still useful note, you can also now sync Google contacts with your Mac OS X Address Book.

How do you like to get your GCal on your desktop? Let us know in the comments.

Adam Pash is a senior editor for Lifehacker who isn’t happy until everything syncs. His special feature Hack Attack appears every Tuesday on Lifehacker. Subscribe to the Hack Attack RSS feed to get new installments in your newsreader.


Web application hotkeys with Javascript

It’s unfortunate, but there are only a few sites that have done a good job of enhancing the user experience with hotkey support. In searching for the easiest way to do this in my own applications, I stumbled across the Hotkeys plugin for jQuery. In typical jQuery form it lets you do something moderately complicated, like capturing keyboard events, with a single line of Javascript code. You use the hotkeys.add method to bind a keyboard event to a callback function and the hotkeys.remove method to remove the handler.

Here’s an example that will create an alert box when you press control-c:

$.hotkeys.add('Ctrl+c', function(){ alert('ctrl-c pressed');});

You remove the handler like this:

$.hotkeys.remove('Ctrl+c');

hotkeys.add can also has a 3 parameter evocation: hotkeys.add(key, options, handler). The options parameter is just an associative array which you can use to pass options such as the target DOM path or the type of key press event (keyup or keydown). The key parameter is a string representing the key combination. Instead of using scan codes, you send in the names of the key combination, such as “a”, “Shift+b”, “f9″, or “pageup”. It’s really that easy.

Javascript jQuery Hotkeys Plugin
Using jQuery Hotkeys

Wine @ Work: Running MS Office and IE on Linux

Let the Bacchanalia begin! Getting your Windows apps installed and running on Linux the Wine way.

Weblog Tools Collection: WordPress Plugin Releases for 07/28

WineX

WineX is a lightweight script that will import the listing contents of your CellarTracker wine cellar into your WordPress website.

Hidden Content

Some blocks of the text can be shown/hidden for bots, logged-in users or all visitors (in posts, pages and comments) (Page in Russian)

GD Star Rating

Star Rating plugin allows you to set up rating system for pages and/or posts in your blog. Also includes the widget for displaying votes and rating statistics for all posts and pages with votes.

GD LinkedIn Badge

This widget displays badge with a link to a LinkedIn profile page. It can also display some additional custom information above the picture and link.

GD Pages Navigator

Standard display of pages in WordPress can be a problem if you have a lot of pages with subpages causing the widget with list of pages to take a lot of space on the page.

Silverlight Content

Add Silverlight objects (XAP-files) to the post and manage default values. Like location, width, height and necessary Silverlight version.

Show Active Category

With Worpress it is only possible to show the active category when you browsing the category archive. But when you are on a single post page you have a possibility to show to which category other categories the current blogpost belongs to. This small plugin adds the CSS class “active_category” to all categories the active post belongs to. (Page in German)

WP-Slimstat-Ex

Track your blog stats. Based on Mr. Coolmann’s Wp-SlimStat

Power Up Windows Explorer with Free Add-ons [Windows Explorer]


When moving, copying, pasting, browsing, and getting information about your files feels like tedious work—and it can in the feature-sparse Windows Explorer—you need some power add-ons that can help. Instead of completely replacing Windows Explorer with an alternative file manager, you can pick and choose the extra features you want and add them piecemeal. Let's take a look at some free power add-ons for Windows Explorer that make dealing with your growing file collection faster and easier.

Note: Installing every single one of these toolbars and add-ons may slow down Windows Explorer, so pick and choose the ones that give you the features you need.

qttabbar.pngQTTabBar Adds Tabs to Windows Explorer: Get the tabbed browsing experience in Windows Explorer with the QuickTimeTabBar add-on. Once installed, right-click on the Explorer toolbar and select the QTTabBar toolbars, which add both tabbing and other features, like access to recent tabs and file previews. QTTabBar works in Vista and XP with .Net Framework 2.0 or later. QTTabBar homepage, original post.

explorer breadcrumbs.png
Explorer Breadcrumbs Adds “Breadcrumb” Folder Trail: Move up and down your folder hierarchy with ease by adding a "breadcrumb" folder trail to Windows Explorer. This little ditty is a a bit buggy—it didn't work for Adam in his original tests, but it has worked for me—so proceed with that in mind. Explorer Breadcrumbs is a free download for Windows 2000 and XP, donations requested. Explorer Breadcrumbs homepage, original post.

Xentient Thumbnails Offers Actual File Preview: Replace Windows Explorer’s boring default image icon with a preview of the actual image itself as shown above. Xentient Thumbnails is a free download for Windows XP only. Xentient Thumbnails homepage, original post.

filebox-extender.jpg FileBox eXtender Keeps Oft-Used Folders Always In Reach: Add favorite folders you’re always reaching for to every Explorer window with FileBox eXtender, which adds two small buttons that drop down a file menu, and a quick keyboard shortcut to get to those folders as well. Set up your preferred key combo (Adam suggests Ctrl+Shift+F) and type the first letter of the folder you want to select it. FileBox eXtender works in Open and Save dialogs as well, in Windows XP and Vista. FileBox eXtender homepage, original post.

teracopy.pngTeraCopy Speeds Up Big File Copy Jobs: Get greater control of file copy operations—especially ones that involve several gigs—with TeraCopy, a simple utility that offers pause, resume, and error recovery to your file copy jobs, as well as speeds them up overall. TeraCopy homepage, original post.

openwide.pngOpenWide Customizes the Open/Save Dialog File View: Set your Open/Save dialog to always list your files in details view, automatically focus your keyboard where you choose, and even place the box’s exact location on your screen using OpenWide for Windows XP and 2000. OpenWide homepage, original post.

foldersize.pngFolder Size Sorts Folders by the Size of Their Contents: Add a column to Windows Explorer that displays how much space a folder's taking up with Folder Size, a small utility that also lets you sort by folder size as well—making quick cleanup of empty or space-hogging folders a snap. FolderSize is a free download for Windows XP only. Folder Size homepage, original post.

placesbareditor.pngPlacesBar Editor Adds Frequently-Used Locations to the Open/Save Dialog Box: Save and open files straight to your most frequently used files by adding them to Windows’ Places bar using the PlacesBar Editor. Unlike PlacesBar Tweaker, PlacesBar Editor works for Microsoft Office dialog boxes, too. PlacesBar Editor is a free download for XP and Vista, donations requested. PlacesBar Editor homepage, original post.

infotag-magic.pngInfoTag Magic Displays File Details on Mouse Hover: Peek inside a file with InfoTag Magic, a small utility that displays a file’s metadata (like MP3 tags) in a tooltip when you hover your mouse pointer over the file. Windows XP only. InfoTag Magic homepage, original post.

If this list of add-ons doesn’t cover what you want or need in Windows Explorer, check out our recent Five Best Alternative File Managers post, as nominated by Lifehacker readers.

What are your favorite add-ons for Windows Explorer? Let us know in the comments.

Gina Trapani, the editor of Lifehacker, likes a more powerful Windows Explorer. Her weekly feature, Geek to Live, appears every Monday on Lifehacker. Subscribe to the Geek to Live feed to get new installments in your newsreader.


Know Your Stuff Inventories Your Home [Featured Download]

Windows and Mac OS X: Offered as a free download from the Insurance Information Institute, the Know Your Stuff Home Inventory software is a full-featured tool for cataloging your possessions in case disaster should strike. Wizards guide you through the basic setup of your inventory, then using Know Your Stuff’s simple interface you can add rooms and items to the inventory. For each item you enter you can assign photos, receipts or appraisals, make/model/serial number, quantity, and replacement cost.

There are guides to help you get started on the Know Your Stuff web site, very helpful if you’ve never done a home inventory before and aren’t sure where to start or what to include in it. Obviously if you invest the time and energy to create a home inventory you’ll want to make sure the it’s is secure. From the Know Your Stuff application you can export the file you’ve created and save it to external media or to a remote location, upload the file to Vault 24 (a remote backup solution integrated into the software, which unfortunately costs $15 a year) , or you can go the old fashioned route and print the inventory off and store it in a safe location. The Know Your Stuff Home Inventory software is a free download for Windows or Mac.


Download That Ikea Manual [Furniture]

ikea-thumb.pngSo you’ve taken apart that Ikea desk, moved it into your new place, and now have no idea how to get it back together. When the paper manual is long lost, hit up the IKEAFANS’ site instructions area to download the instructions you need (registration required). [via]


WP Like Button Plugin by Free WordPress Templates