inputfile.postedfile.contentlength وحدات القياس
-
02-10-2019 - |
سؤال
من فضلك هل يمكن أن تخبرني الوحدات التي تم قياسها بواسطة inputFile.postedFile.ContentLength. أحتاج إلى التأكد من أن الملف أقل من 500 ألف.
شكرًا.
المحلول
وحدة القياس = بايت.
1 Kilobyte (kB) = 2ˆ10 Byte = 1024 Bytes
نموذج اختبار رمز لحجم ملف 15 كيلو بايت:
const int maxFileLength = 15360; // 15KB = 1024 * 15
if(PictureFile.PostedFile.ContentLength > maxFileLength)
{
MyResult.Text = String.Format("Your post has a size of {0:#,##0} bytes which
exceeded the limit of {0:#,##0} bytes. Please upload a smaller file.",
PictureFile.ContentLength, maxFileLength);
}
else
{
// Save the file here
MyResult.Text = "Thank you for posting."
}
في حالتك ، كما تريد أن يكون الملف أقل من 500 كيلو بايت ، يجب أن يكون لديك هذا:
const int maxFileLength = 512000; // 500KB = 500 * 1024
نصائح أخرى
انها بايت.
http://msdn.microsoft.com/en-us/library/system.web.htpostedfile.contentLength.aspx
httppostedfile.contentLength
يحصل على حجم ملف تم تحميله ، بالبايت.
عندما أقوم بتحميل ملف قالب لأكثر من 1 ميغابايت ، يتم تحميله لفترة طويلة. رمز my أدناه ----
if (checkImagecount())
{
//string imgFolder = Server.MapPath("/Userimages/" + emp_id.ToString().Trim() + "/Images/Browseimage/");
string destinationImage = Server.MapPath("/master/" + emp_id.ToString().Trim() + "/Images/");
string destination1 = Server.MapPath("/master/" + emp_id.ToString().Trim() + "/Images/");
string imgFilename, fileExt = String.Empty;
Response.Write(fileTemplateimage.PostedFile.ContentLength+"<br/>");
Response.Write(fileTemplateimage.FileBytes.Length);
Response.End();
if (fileTemplateimage.PostedFile.ContentLength > 0 && fileTemplateimage.FileBytes.Length <= 1048576)
{
System.Drawing.Image uploadImage = System.Drawing.Image.FromStream(fileTemplateimage.PostedFile.InputStream);
float uploadImagewidth = uploadImage.PhysicalDimension.Width;
float uploadImageheight = uploadImage.PhysicalDimension.Height;
else
{
Page.ClientScript.RegisterStartupScript(this.GetType(), "failure", "alert('अपलोड फ़ाइल आकार 1 एमबी से अधिक नहीं होना चाहिए.');", true);
divhide.Style.Add("display", "block");
divUploadpanel.Style.Add("display", "block");
fileTemplateimage.Focus();
لا تنتمي إلى StackOverflow