获取文件大小 [英] Get File Size
问题描述
我必须将文档以varBinary(max)格式的列保存在MS SQL Server数据库中.我的问题是,在保存文档之前,我必须检查文件的大小,因为每个用户的大小限制为2MB.如何从ASP.NET FileUpload中获取文件大小.
I have to save a document in MS SQL server database in column of varBinary(max) format. My Problem is that before saving the document I have to check the size of the file because each user has a 2MB size limit. How can take file size from ASP.NET FileUpload.
Thanks in advance!
推荐答案
您可以通过修改httpRunTime元素来设置web.config中允许的最大文件大小.
http://programming.top54u.com/post/ASP-Net-FileUpload- Size-Limit-Example.aspx [ ^ ]
例如
You can set the maximum file size allowed in your web.config by modifying the httpRunTime element
http://programming.top54u.com/post/ASP-Net-FileUpload-Size-Limit-Example.aspx[^]
e.g
<httpRuntime maxRequestLength="2048" />
您也可以在此线程中查看类似的内容
http://bytes.com/topic/asp-net/answer/446834-how-check-filesize-using-fileupload-control [
You can also have a look at something like in this thread
http://bytes.com/topic/asp-net/answers/446834-how-check-filesize-using-fileupload-control[^]
Protected Sub Upload_Click () Handles As Upload.Click
If FileUpload1.PostedFile.ContentLength > 10240 then
lblMessage.Text = "File is too large."
Else
FileUpload1.PostedFile.SaveAs(Location)
End If
End Sub
您无法从任何客户端脚本语言可靠地获取文件大小,客户端上的文件操作将是一个很大的安全漏洞.
You can''t reliably get the file size from any client scripting languages, file manipulation on the client would be a large security hole.
除了Dylan所说的那样,
您可以为此使用第三方控件.其中一些是:
Ajax上传器
SWFUpload
RAD上传
希望有帮助!
Apart from what Dylan already said,
You can use third party controls for this purpose. Some of them are:
Ajax Uploader
SWFUpload
RAD Upload
Hope that helps!
这篇关于获取文件大小的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!