1. ASP.NET 如何获得文件夹大小
例如可以用以下方法:其中参数path所传递的值是所要查看的文件夹的绝对路径!首先要导入System.IOC#//获取某个文件夹的大小(stringpath){DirectoryInfodirInfo=newDirectoryInfo(path);longsumSize=0;FileSystemInfofsInfo;foreach(fsInfoindirInfo.GetFileSystemInfos()){if(fsInfo.Attributes.ToString().ToLower()==directory){sumSize+=getDirectorySize(fsInfo.FullName);}else{FileInfofiInfo=newFileInfo(fsInfo.FullName);sumSize+=fiInfo.Length;}}returnsumSize;}VB.NET'获取某个文件夹的大小FunctiongetDirectorySize(ByValpathAsString)AsLongDimdirInfoAsNewDirectoryInfo(path)DimsumSizeAsLong=0DimfsInfoAsFileSystemInfoForEachfsInfoIndirInfo.GetFileSystemInfos()If(fsInfo.Attributes.ToString.ToLower=directory)ThensumSize+=getDirectorySize(fsInfo.FullName)ElseDimfiInfoAsNewFileInfo(fsInfo.FullName)sumSize+=fiInfo.LengthEndIfNext
2. C# ASP.NET 使用 FileUpload如何判断要上传文件大小
try public static long GetRemoteHTTPFileSize(string sURL) { long size = 0L; try { System.Net.HttpWebRequest request = (System.Net.HttpWebRequest)System.Net.WebRequest.Create(sURL); request.Method = "HEAD"; System.Net.HttpWebResponse response = (System.Net.HttpWebResponse)request.GetResponse(); size = response.ContentLength; //size = System.Convert.ToInt64(response.Headers["Content-Length"]); response.Close(); } catch { size = 0L; } return size; }
3. vb.net怎么获取mp3文件的大小
Dimmp3FileAsNewSystem.IO.FileInfo("C:示例代码.mp3")MsgBox("文件大小为:"&mp3File.Length&"字节(Byte)")
如果需要其他单位,比如KB、MB之类的,除以1024就可以了。
4. vbnet 如何获取文件大小
Dim fi As New System.IO.FileInfo("C:\1.txt")MsgBox(fi.Length)
5. ASP.NET里的文件大小判别
这是在服务器端判断的,但.NET 默认限制的大小是4M,超过了就会出现问题可以在web.config里的system.web内增加这个限制,比如加到200M,这样200M内的文件就能判断了<system.web><httpRuntime executionTimeout="600" maxRequestLength="2048000" useFullyQualifiedRedirectUrl="true" minFreeThreads="8" minLocalRequestFreeThreads="4" appRequestQueueLimit="100" enableVersionHeader="true"/></system.web>
6. .net中如何通过用js来获取上传文件的大小,判断大小…
下面是方法和问题。JS客户端判断filesize <script language="JavaScript"> function ShowSize(files) { var fso,f; fso=new ActiveXObject("Scripting.FileSystemObject"); f=fso.GetFile(files); if(f.Size >1024*5){ alert("文件尺寸"+Math.round(f.size/1024,2)+" K,照片尺寸不能超过5K!"); } } </script> 这种方式必专须打开:“属对没有标记为安全的ActiveX控件进行初始化和脚本运行 ->启用” 否则就提示错误 所以建议你,不光js要判断,后台还是要配置和判断。
7. 用wininet的InternetReadFile如何得知文件大小
Visual C++如何:读取二进制文件下面的代码示例演示如何从文件中读取二进制数据。使用了 System.IO 命名空间中的两个类:FileStream 和 BinaryReader。FileStream 表示实际的文件。BinaryReader 为允许二进制访问的流提供接口。下面的代码示例使用由如何:编写二进制文件中的代码创建的称为 data.bin 的文件。示例// binary_read.cpp// compile with: /clr#using<system.dll>using namespace System;using namespace System::IO;int main() { String^ fileName = "data.bin"; try { FileStream^ fs = gcnew FileStream(fileName, FileMode::Open); BinaryReader^ br = gcnew BinaryReader(fs); Console::WriteLine("contents of :", fileName); while (br->BaseStream->Position < br->BaseStream->Length) Console::WriteLine(br->ReadInt32().ToString()); fs->Close( ); } catch (Exception^ e) { if (dynamic_cast<FileNotFoundException^>(e)) Console::WriteLine("File '' not found", fileName); else Console::WriteLine("Exception: ()", e); return -1; } return 0;}★★补充★★手上的一个VB项目(过程中发现,.Net果然是好啊),需要在一个ActiveX中实现HTTP下载功能,我是采用InternetreadFile这个API来实现,一开始的代码我是这么写的 Function Gethttpdownload(sUrl As String) As boolen Dim s As StringDim hOpen As LongDim hOpenUrl As LongDim bDoLoop As BooleanDim bRet As BooleanDim sReadBuffer As String * 2048Dim lNumberOfBytesRead As LonghOpen = InternetOpen(scUserAgent, INTERNET_OPEN_TYPE_PRECONFIG, vbNullString, vbNullString, 0)hOpenUrl = InternetOpenUrl(hOpen, sUrl, vbNullString, 0, INTERNET_FLAG_RELOAD, 0) bDoLoop = True Do While bDoLoop sReadBuffer = vbNullString bRet = InternetReadFile(hOpenUrl, sReadBuffer, Len(sReadBuffer), lNumberOfBytesRead) s = s & Left$(sReadBuffer, lNumberOfBytesRead) If Not CBool(lNumberOfBytesRead) Then bDoLoop = False LoopFileName = "E:\BitSpirit\Torrent\121212.torrent"F1 = FreeFileOpen FileName For Binary As F1Put F1, , sClose F1 If hOpen <> 0 Then InternetCloseHandle (hOpen) Gethttpdownload = true End Function 上面方法,用来获取服务器上的文本类型的文件一点问题,都没有,但是用来下载二进制文件的时候 就出现问题了,里面的数据怎么也不对,研究了下载下来的文件后发现,问题外话应该是在接收数据的变量是个STRING的定长字符串上。但是在网上查了好久,甚至M$ MSDN上的一个用VB来实现下载的程也是用 string类型来接收数据的而且网上的代码写法,基本上也都是这个样,好来才好现,都是从MSDN上的哪个例程上演变过来的. 我想如果能用一个byte数组来代替定长字符串,哪可能就没有问题了,但是查看了一个VB 对Internetreadfile的申明Public Declare Function InternetReadFile Lib "wininet.dll" (ByVal hFile As Long, ByVal sBuffer As String, ByVal lNumBytesToRead As Long, lNumberOfBytesRead As Long) As Integer发现其定义ByVal sBuffer As String 看来只能用String了,在网上查找过程中,发现人家用VC写的程序中这人参数可以是其它的,所以查看了一下Internetreadfile的原型。发现的确可以, 所以我把internetreadfile的定义修改了一下,为了通用,我为新的internetreadfile定义了一个别名。Internetreadfilebyte申明如下:Public Declare Function InternetReadFileByte Lib "wininet.dll" Alias "InternetReadFile" (ByVal hFile As Long, ByRef sBuffer As Byte, ByVal lNumBytesToRead As Long, lNumberOfBytesRead As Long) As Integer试了一下的确可以,重新修改函数,(在这过程中发现,如果要取到正确数据,还必须取得文件大小。所以增加了HttpQueryInfo的定义)最后完整的函数Function FileDownload(sUrl As Variant) As Boolean Dim b(99) As Byte Dim EndByte() As Byte Dim s As String Dim hOpen As Long Dim hOpenUrl As Long Dim bDoLoop As Boolean Dim bRet As Boolean Dim bbuffer As Byte Dim sReadBuffer As String Dim FileName As String Dim lNumberOfBytesRead As Long Dim F1 As Integer Dim strsize As String Dim size As Long strsize = String$(1024, " ") F1 = FreeFile stTotal = vbNullString FileName = "E:\BitSpirit\Torrent\121212.torrent" Open FileName For Binary As F1 hOpen = InternetOpen(scUserAgent, INTERNET_OPEN_TYPE_PRECONFIG, vbNullString, vbNullString, 0) hOpenUrl = InternetOpenUrl(hOpen, sUrl, vbNullString, 0, INTERNET_FLAG_RELOAD, 0) bDoLoop = True HttpQueryInfo hOpenUrl, HTTP_QUERY_CONTENT_LENGTH Or HTTP_QUERY_FLAG_NUMBER, ByVal strsize, Len(strsize), 0 size = CLng(Trim(strsize)) For j = 1 To size \ 100 bDoLoop = InternetReadFileByte(hOpenUrl, b(0), 100, lNumberOfBytesRead) Put F1, , b If Not CBool(lNumberOfBytesRead) Then Exit For Next If size Mod 100 <> 0 Then tmp = (size Mod 100) – 1 ReDim EndByte(tmp) bDoLoop = InternetReadFileByte(hOpenUrl, EndByte(0), tmp + 1, lNumberOfBytesRead) Put F1, , EndByte End If If hOpenUrl <> 0 Then InternetCloseHandle (hOpenUrl) If hOpen <> 0 Then InternetCloseHandle (hOpen) Close #1 FileDownload = TrueEnd Function测试了一下,完全成功:)