如何在c#上传之前获取文件大小 [英] how to get file size before upload in c#

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

问题描述

大家好,我正在构建一个 Web应用程序

i希望在我的应用程序中上传图像,但是

我的程序有一个限量

i希望在上传之前获取文件大小,

如果文件大小大于金额, 程序将失败

那么,如何在上传C#之前获取文件大小?

:) tnx所有

hi all , I am building a web application
i want to upload image in my application , but
My program has a limited volume
i want to get file size before upload ,
If file size is greater than the amount,the program will fail
So , How can i get file size before upload in C# ?
:) tnx All

推荐答案





上传前我们无法获得服务器端的值。

我们必须使用插件或客户端代码。



如果您使用的是IIS 7.0,请参阅以下链接。



http: //msdn.microsoft.com/en-us/library/ms689462%28VS.90%29.aspx [ ^ ]


如果您使用 Asp文件上传控件比您可以使用文件上传控件的 PostedFile.ContentLength 属性。





如需详细信息,请查看以下内容。



MSDN--FileUploadControl.PostedFile.ContentLength Property



希望它会有所帮助。 :)
If you are using Asp File Upload Control than You can use PostedFile.ContentLength property of File Upload Control.


For detailed info, Kindly have a look at following.

MSDN--FileUploadControl.PostedFile.ContentLength Property

Hope it will help. :)


你需要javascript代码。你可以在javascript上编写一个函数,如果上传文件,它将在上传文件后发送文件大小。



< asp:fileupload id =fu_Uploadrunat =serveronchange =javascript:getFileSize(this);的xmlns:ASP = #未知 >



函数getFileSize(输入){

var file = input.files [0];

返回文件.size;

}
You will need javascript code for that .You can write a function on javascript which will send the file size after uploading a file if file upload .

<asp:fileupload id="fu_Upload" runat="server" onchange="javascript:getFileSize(this);" xmlns:asp="#unknown">

function getFileSize(input) {
var file = input.files[0];
return file.size;
}


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

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