asp.net文件大小 [英] asp.net file size

查看:82
本文介绍了asp.net文件大小的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我要上传到服务器之前,获取文件大小。我用下面的code

I want to get the file size before uploading to server. I used following code

Dim fileDetails As IO.FileInfo
fileDetails = My.Computer.FileSystem.GetFileInfo(filePath)
Dim fileSize As Integer = fileDetails.Length

在本地端的code工作的要求,但是,它的IIS不工作。

On local side the code works as required but on IIS it not working.

我关心的是有没有其他的方法来找到文件浏览器窗口中选择文件的文件大小(我使用的HTML控件类型的文件,如果不是在ASP中控制fileuploader)。

My concern is that is there any other method to find the file size of selected file from file browser window (I am using html control type file instead if fileuploader in asp control).

推荐答案

可惜你不能检查客户最终文件大小。它不应该是一个大问题,我有几个目前生产的实现,允许多文件上传的检查服务器端的文件大小。这并不是说长的延迟,我不相信你会找到解决的办法。

Unfortunately you cannot check the file size on the client end. It shouldn't be that big of a deal, I have a few current production implementations allowing multiple file uploads that check the file size on server-side. It is not that long of a delay and I don't believe you will find a way around this.

有得记下,在web.config已单个请求范围内设置决定了最大长度(千字节)。默认情况下,该值设置为4MB。所以,如果你的用户正在尝试上传超过此金额,他将获得一个服务器错误。这里是你如何改变这样的:

Something to make note of, the web.config has setting within that determines the maximum length (in kilobytes) of a single request. By default, this is set to 4MB. So if your user is trying to upload more than this amount, he will receive a server error. Here is how you change this:

<system.web>
  <httpRuntime maxRequestLength="4096"/>
</system.web>

这篇关于asp.net文件大小的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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