Tuesday, January 6, 2009

Function for set UploadMaximum image file size

//Function for set UploadMaximum image file size
private void SetUploadSize()
{
decimal sizeInBytes = 0;

if (hdnOrderID.Value != string.Empty)
{
string directory = Server.MapPath("PhotoPrintImages/" + hdnOrderID.Value);

DirectoryInfo dir = new DirectoryInfo(directory);


foreach (FileInfo f in dir.GetFiles())
{
sizeInBytes += f.Length;
}
imageSize = (sizeInBytes / 1048576);
if (imageSize > 0)
{
lblSize.Text = imageSize.ToString("n2");
}
else
{
lblSize.Text = "0";
}
decimal maximumSize = Decimal.Parse(Constants.CONST_PRINT_MAXIMUM_SIZE);

decimal progressSize = Math.Round((imageSize / maximumSize) * 300, 0);
if (progressSize < 1)
{
imgProgressBar.Width = 0;
}
else
{
imgProgressBar.Width = (int)progressSize;

}

}

No comments: