File uploading has been a hot topic during my time as an internet programmer. In the classic ASP days this was a bit of a task to build and get correct. Nowadays both Adobe’s Coldfusion and Microsoft’s ASP.NET both have built in file uploader tags ( server controls ) that handle this with ease.
This is great, but what happens when you have a mixed bag of clients that all need to upload to the same location? Sometimes I work with completely ASP.NET or CF web apps, but more often than not I’m dealing with Flash clients as well as HTML clients.
Recently I ran into this upload scenario and built this simple ASP.NET uploader script. This feels a bit old school since it uses .NET’s built in Request.Files collection, instead of a fancy new ‘all in one’ server control, but I actually prefer this method.
Here’s all you need :
// Check for posted files
for (int xx = 0; xx < Request.Files.Count; xx++)
{
// UPLOAD FILE
HttpPostedFile _file = Request.Files[xx];
// create full save path for uploaded file
var full_file_path = Server.MapPath( UP_FOLDER ) + "\\" + _file.FileName;
try
{
// save file to server
_file.SaveAs(full_file_path);
}
catch (Exception exc)
{
var emsg = "Unable to upload file : " + exc.Message;
Response.Write( emsg );
Response.Flush();
Response.End();
}
// show result
Response.Write( _file.FileName + " uploaded! <br>" );
}
That’s all there is to it codewise. Before using this code you will need to give the NETWORK SERVICES user write permissions to your upload folder. Other than that, that’s all she wrote!
Here is a zip of all the code for you to download.
Inside this zip you will find :
- flashclient.fla – Flash upload client ( *be sure to update the upload path before building )
- flexclient.mxml – Flex upload client ( *also update upload path before building )
- uploader.aspx - ASP.NET file upload handler
- uploadform.html - sample HTML upload form ( again, update path )
Hope somebody finds this useful.
Tags: asp.net upload, flash upload, flex upload, html upload, NETWORK SERVICE, Request.Files, upload, upload handler, uploader
Posted in .net, C#, actionscript, adobe, coldfusion, development, flash, flex, microsoft | No Comments »
I’ve been using Visual Studio since forever, yet it always takes me a while to remember how to show line numbers. It’s especially hard to remember after a fresh install of Visual Studio. Assuming you have it installed and open, here’s how to display line numbers in your code.
- Click Tools in the menu bar
- Options
- Expand Text Editor ( in the popup window )
- Click ‘All Languages’
- Check the ‘Line numbers’ box under the Display heading ( on the right )
- Click OK
- Happy Happy Joy Joy!

Tags: display, line numbers, text editor, Visual Studio, visual studio options
Posted in .net, C#, Visual Studio, development, microsoft, tips and tricks | No Comments »
One of my favorite features of the Eclipse IDE is ‘Open Resource’ ( Ctrl + Shift + R ).

Don't point and click to your files, just type their name
If you’re unfamiliar with this, it’s a File Open dialog that let’s you type the name of the file you’re looking for, instead of requiring you to point and click your way to the file. This is one of the few features I still can’t believe Visual Studio doesn’t have built in. Now I’ve had other MS experts show me similar “quick find” features of Visual Studio, but it’s still not as easy as Ctrl+Shift+R > type the filename.
When I was using Visual Studio 2008 I came across the Sonic File Finder plugin and I was hooked. Then I upgraded to Visual Studio 2010 and my plugin went away. Today I solved my quick open plugin issue by browsing the Visual Studio Gallery and installing Quick Open File. This quick open plugin does exactly what Eclipse’ Open Resource does, and it’s a good bit simpler than Sonic File Finder. Now that I’ve got the plugin installed, the next step is to configure Visual Studio to open this plugin when I hit the Ctrl + Shirt + R keyboard combination.
Add Ctrl+Shift+R to Visual Studio
- Fire up Visual Studio
- Click Tools > Options > Environment > Keyboard
- You should now be at the window for assigning keyboard shortcuts

- Type “Quick” into the Show commands containing box
- Click inside the “Press shortcut keys” box, and then press Ctrl + Shift + R on your keyboard
- Assuming you’ve set this to Global, you are now good to go.
**NOTE : When assigning a keyboard shortcut in Visual Studio, you want to make sure your new shortcut isn’t already assigned to a different command. If this is the case, you should remove your shortcut assignment from the other command before assigning to your new command. This dialog will show you what is already assigned to a keyboard combination like so.

Assuming you made it this far, pressing Ctrl + Shift + R in Visual Studio should now show you this Quick File Open dialog.

There you go, quick open in Eclipse and Visual Studio!
Tags: eclipse, msdn, open resource, plugin, quick open file, visual studio 2010, visual studio gallery, vs gallery, vs plugin
Posted in .net, Visual Studio, cool, microsoft, tips and tricks, windows | 2 Comments »
Here’s a clever little solution I would like to add to the book of ‘get it done’. While this particular example uses ASP.NET controls, this concept really applies to any language that supports DataBinding to a control.
The base concept is using your knowledge of SQL’s UNION operator to add a temp value to the beginning of a list of data from a sql query. In the past I’ve done this countless times via code, and recently I didn’t have the time to do this, so I updated the query to a UNION, and I was good to go.
Now I’m not selling this as a ‘best practice’, but I do consider this one more reason why it’s good to know SQL.
Problem : Using a SQLDataSource to populate a DropDown component, how do you inject a spacer value in position 0? EX : “- select value -”
Solution : Inject your spacer value in your SelectCommand via sql’s UNION operator
ComboBox
<asp:DropDownList runat="server" ID="meter_manufacturer_dd" DataSourceID="sql_meterManufacturer" DataTextField="Manufacturer" />
DataSource
<asp:SqlDataSource runat="server" ID="sql_meterManufacturer"
SelectCommand="
SELECT '- Choose Manufacturer -' as Manufacturer
UNION
SELECT DISTINCT Manufacturer FROM Smart_Meter_DEF"
/>
What this solution gets you.
1. Your spacer value shows up in position 0 ( because the first character is – and not alphanumeric )

2. Auto ViewState caching ( EG : going straight .NET solution, .NET handles persisting your dropdown selection between postbacks )

* in this sample, the connectionString for the SqlDataSource is set in code.
Tags: combobox, DataBind, DataBound, sql, union, viewstate
Posted in .net, database, random, sql, tips and tricks | No Comments »