int size = (int)FileUpload.PostedFile.InputStream.Length; //Get the the len of the file uploaded
string contentType = FileUpload.PostedFile.ContentType; //Get the MIMEType

//Get the file name
string [] strs = FileUpload.PostedFile.FileName.Split("\\".ToCharArray());
string fileName = strs[strs.Length - 1];

//See if it exceed the uploading quota
if (!IsExceedQuota(size))
{
UploadResult.Text = "\\rUpload failed (File is too large, the quota is " + fileQuota.ToString() + " byte)";
return;
} //put in one object
PostFile post = new PostFile(size);
post.FileKey = FileKey.Text;
post.FileSize = size;
post.MIMEType = contentType;

//Get the file content
FileUpload.PostedFile.InputStream.Read(post.Bs, 0 , size); //Save to database
try
{
SaveToDatabase(post);
}
catch (Exception e1)
{
UploadResult.Text += "\\rUpload failed (" + e1.Message + ")";
}