asp.net - InputFile.PostedFile.ContentLength 测量单位

标签 asp.net vb.net file-upload filesize maxstringcontentlength

请告诉我 InputFile.PostedFile.ContentLength 测量的单位。我需要确保文件小于 500k。

谢谢。

最佳答案

测量单位 = 字节。

1 Kilobyte (kB) = 2ˆ10 Byte = 1024 Bytes

文件大小为 15 KB 的示例代码测试:

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 KB,因此您应该这样:

const int maxFileLength = 512000; // 500KB = 500 * 1024

关于asp.net - InputFile.PostedFile.ContentLength 测量单位,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3698122/

相关文章:

asp.net - 我应该创建几个小型应用程序数据库还是一个大型应用程序数据库?

c# - 如何将字符串传递给 C# 网站引用的 VB.NET 项目函数?

c# - 用wmd上传图片?

php - 图片的有效文件扩展名的完整列表是什么?

html - 如何减少 HTML 表中被字符串生成器扭曲的行空间

asp.net - 更新 : Copy file from serverA to serverB

c# - 动态添加的 ASP.NET 控件在后面的代码中不可见

c# - 判断是否在IDE中执行的方法?

vb.net - 如何使用我的应用程序复制 Access 数据库文件?

java - 用户文件保存在哪里?