/// <summary>
        /// Writes a Stream to the appropriate File Storage
        /// </summary>
        /// <param name="fileId">The Id of the File</param>
        /// <param name="inStream">The Input Stream</param>
        /// <param name="fileName">The name of the file</param>
        /// <param name="storageLocation">The type of storage location</param>
        /// <param name="closeInputStream">A flag that dermines if the Input Stream should be closed.</param>
        /// <remarks>
        /// </remarks>
        private static void WriteStream( int fileId, Stream inStream, string fileName, int storageLocation, bool closeInputStream )
        {
            FileController objFileController = new FileController();

            // Buffer to read 2K bytes in chunk:
            byte[] arrData = new byte[2049];
            Stream outStream = null;
            if( storageLocation == (int)FolderController.StorageLocationTypes.DatabaseSecure )
            {
                objFileController.ClearFileContent( fileId );
                outStream = new MemoryStream();
            }
            else if( storageLocation == (int)FolderController.StorageLocationTypes.SecureFileSystem )
            {
                if( File.Exists( fileName + Globals.glbProtectedExtension ) == true )
                {
                    File.Delete( fileName + Globals.glbProtectedExtension );
                }
                outStream = new FileStream( fileName + Globals.glbProtectedExtension, FileMode.Create );
            }
            else if( storageLocation == (int)FolderController.StorageLocationTypes.InsecureFileSystem )
            {
                if( File.Exists( fileName ) == true )
                {
                    File.Delete( fileName );
                }
                outStream = new FileStream( fileName, FileMode.Create );
            }

            try
            {
                // Total bytes to read:
                // Read the data in buffer
                int intLength = inStream.Read( arrData, 0, arrData.Length );
                while( intLength > 0 )
                {
                    // Write the data to the current output stream.
                    if( outStream != null )
                    {
                        outStream.Write( arrData, 0, intLength );
                    }

                    //Read the next chunk
                    intLength = inStream.Read( arrData, 0, arrData.Length );
                }

                if( storageLocation == (int)FolderController.StorageLocationTypes.DatabaseSecure )
                {
                    if( outStream != null )
                    {
                        outStream.Seek( 0, SeekOrigin.Begin );
                    }
                    objFileController.UpdateFileContent( fileId, outStream );
                }
            }
            catch( Exception )
            {
            }
            finally
            {
                if( inStream != null && closeInputStream )
                {
                    // Close the file.
                    inStream.Close();
                }
                if( outStream != null )
                {
                    // Close the file.
                    outStream.Close();
                }
            }
        }