如何在上传时检查文件大小 [英] How to check file size on upload

查看:78
本文介绍了如何在上传时检查文件大小的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

使用asp.net和C#在上传过程中检查文件大小的最佳方法是什么?我可以通过更改web.config来上传大文件,而不会出现任何问题.当文件上传超过我允许的最大文件大小时,就会出现我的问题.

Whats the best way to check the size of a file during upload using asp.net and C#? I can upload large files by altering my web.config without any problems. My issues arises when a file is uploaded which is more than my allowed max file size.

我已经研究过使用Activex对象,但这与跨浏览器不兼容,也不是解决方案的最佳答案.我需要它尽可能与跨浏览器兼容并支持IE6(我知道您在想什么!但是我的应用程序用户中有80%是IE6,不幸的是这不会很快改变).

I have looked into using activex objects but that is not cross browser compatible and not the best answer to the solution. I need it to be cross browser compatible if possible and to support IE6 (i know what you are thinking!! However 80% of my apps users are IE6 and this is not going to change anytime soon unfortunately).

是否有开发人员遇到相同的问题?如果是这样,您如何解决呢?

Has any dev out there come across the same problem? And if so how did you solve it?

推荐答案

如果使用的是 System.Web.UI.WebControls.FileUpload 控件:

MyFileUploadControl.PostedFile.ContentLength;

返回已发布文件的大小(以字节为单位).

Returns the size of the posted file, in bytes.

这篇关于如何在上传时检查文件大小的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆