Wednesday, November 16, 2005

Cool File Functions in .NET 2.0

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. Cool huh?

0 Comments:

Post a Comment

<< Home