private static void WriteStream(int fileId, Stream inStream, string fileName, int storageLocation, bool closeInputStream)
 {
     CommonLibrary.Services.FileSystem.FileController objFileController = new CommonLibrary.Services.FileSystem.FileController();
     byte[] arrData = new byte[2048];
     Stream outStream = null;
     try
     {
         switch (storageLocation)
         {
             case (int)CommonLibrary.Services.FileSystem.FolderController.StorageLocationTypes.DatabaseSecure:
                 objFileController.ClearFileContent(fileId);
                 outStream = new MemoryStream();
                 break;
             case (int)CommonLibrary.Services.FileSystem.FolderController.StorageLocationTypes.SecureFileSystem:
                 if (File.Exists(fileName + Globals.glbProtectedExtension) == true)
                 {
                     File.Delete(fileName + Globals.glbProtectedExtension);
                 }
                 outStream = new FileStream(fileName + Globals.glbProtectedExtension, FileMode.Create);
                 break;
             case (int)CommonLibrary.Services.FileSystem.FolderController.StorageLocationTypes.InsecureFileSystem:
                 if (File.Exists(fileName) == true)
                 {
                     File.Delete(fileName);
                 }
                 outStream = new FileStream(fileName, FileMode.Create);
                 break;
         }
     }
     catch (Exception ex)
     {
         if (inStream != null && closeInputStream)
         {
             inStream.Close();
             inStream.Dispose();
         }
         if (outStream != null)
         {
             outStream.Close();
             outStream.Dispose();
         }
         throw ex;
     }
     try
     {
         int intLength;
         intLength = inStream.Read(arrData, 0, arrData.Length);
         while (intLength > 0)
         {
             outStream.Write(arrData, 0, intLength);
             intLength = inStream.Read(arrData, 0, arrData.Length);
         }
         if (storageLocation == (int)CommonLibrary.Services.FileSystem.FolderController.StorageLocationTypes.DatabaseSecure)
         {
             outStream.Seek(0, SeekOrigin.Begin);
             objFileController.UpdateFileContent(fileId, outStream);
         }
     }
     catch (Exception ex)
     {
         Exceptions.LogException(ex);
     }
     finally
     {
         if (inStream != null == false && closeInputStream)
         {
             inStream.Close();
             inStream.Dispose();
         }
         if (outStream != null)
         {
             outStream.Close();
             outStream.Dispose();
         }
     }
 }