A Minute Saved...

While everyone seems to be talking about the Amazing and new Features of 2.0 like Membership, Generics, Code Snippets, Partial Classes... (the list continues), let me be the guy who blogs about a tiny little new function in 2.0 that will save a developer 1.5 minutes (give or take a minute) of development time and some 3 odd lines of code :).

For A Recent Project I had to extract BLOBS stored in DB and write them in the file system. Turns out, there is a cool file system function which just lets you write an entire byte array to disk!!

byte[] bFile = new byte[filesize];
bFile = (byte[])ds.Tables[0].Rows[nCounter]["FILE_DATA"];
System.IO.File.WriteAllBytes(fileURL, bFile);

The WriteAllBytes is an out of the box function that just takes the file path and name along with the byte arrary and just creates the file for you IF the directories specified in the path exist. I know this is not going to change the world but what the heck... it's kind cool! One lesser loop to write!

(Moved From http://rajivpopat.blogspot.com)

This article is part of the GWB Archives. Original Author: Rajiv Popat

New on Geeks with Blogs

  • We Won The One Award I Actually Care About

    Full Scale made the Inc. 5000 for the fifth year straight, the 12th listing across my three companies. Here is why the one award you cannot buy is worth stopping for.

  • Your Customers Build the Features Now

    I let a tool I liked sit dead for a year rather than build the features I wanted. An MCP server meant I never had to, and your customers can do the same to your product.

  • Get the Size of a Directory in Linux the Easy Way

    du -sh for the quick answer, ncdu for the cleanup, df for the disk itself: every command for checking directory size in Linux, plus why du and df never agree.

  • Vim Search and Replace: The Ultimate Guide

    One :%s command replaces every match in a file before a find dialog would even open. The Vim substitute patterns worth the muscle memory: flags, ranges, capture groups, and multi-file edits.