如何在aspx文件上传控件中获取文件的大小? [英] How to get size of a file in aspx file upload control?
本文介绍了如何在aspx文件上传控件中获取文件的大小?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我想获取aspx文件上传控件中文件的大小..任何人都可以帮助我吗?
I want to get the size of a file in aspx file upload control..can anyone help me?
推荐答案
fileUpload1.FileBytes.Length
会给你大小的字节数
例子
will give you size in bytes
Example
int sizeinbytes=fileUpload1.FileBytes.Length;
也
你可以尝试
also
you can try
int sizeinbytes= FileUpload1.PostedFile.ContentLength;
以用户友好的方式更新显示尺寸:
Updated to display size in user friendly manner:
string[] sizes = { "B", "KB", "MB", "GB" };
double sizeinbytes=fileUpload1.FileBytes.Length;
int order = 0;
while (sizeinbytes>= 1024 && order + 1 < sizes.Length) {
order++;
sizeinbytes= sizeinbytes/1024;
}
// Adjust the format string to your preferences. For example "{0:0.#}{1}" would
// show a single decimal place, and no space.
string result = String.Format("{0:0.##} {1}", sizeinbytes, sizes[order]);
如果你想要通过javascript获取文件大小,
然后检查此解决方案
文件大小检测 [ ^ ]
int imageSize = myFileUploadControl.PostedFile.ContentLength;
谢谢
Thanks
内容长度= FileUpload1.PostedFile.ContentLength;
文件名legth = FileUpload1.FileName.Length;
其中 FileUpload1 是文件上传控件名称..
...
content length = FileUpload1.PostedFile.ContentLength;
file name legth = FileUpload1.FileName.Length;
where FileUpload1 is a file upload control name..
...
这篇关于如何在aspx文件上传控件中获取文件的大小?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文