Displaying posts categorized under

File management

File to bytearray

Useful function to binary read the content from a file into a byte array – which might be useful in scenarios for storing BLOBS in database etc

public byte[] FileToArray(string sFilePath)
{
[...]

Getting mimetype Windows

This code needs permission to read from registry – so it might not be suited in a web scenario. However it’s useful so here it is:

private string MimeType(string Filename)
{
[...]

Ensure directory exists

This code snippet lets you specify a path – and the function then ensure it exists - i.e creates all folders if necessery.

public static void EnsureDirectory(System.IO.DirectoryInfo oDirInfo)
{
if (oDirInfo.Parent != [...]

Deleting temporary files

In a project I recently was part of I needed to (dynamically) create *A LOT* of PDF-files and other files as well for viewing. The thing was that these files were not supposed to saved on the webserver, they were supposed to be temporary only.
My solution was to simply delete them after a while, [...]