Asp.net mvc 3 如何在C语言中计算文件大小#
在我的asp mvc 3应用程序中,我有一个允许用户下载给定文件的操作 代码如下:Asp.net mvc 3 如何在C语言中计算文件大小#,asp.net-mvc-3,c#-4.0,Asp.net Mvc 3,C# 4.0,在我的asp mvc 3应用程序中,我有一个允许用户下载给定文件的操作 代码如下: public FilePathResult DownloadFile(string fileName) { try { string uploadsDocumentPath = System.Configuration.ConfigurationManager.AppSettings["uploadsDocumentPath"].ToString()
public FilePathResult DownloadFile(string fileName)
{
try
{
string uploadsDocumentPath = System.Configuration.ConfigurationManager.AppSettings["uploadsDocumentPath"].ToString();
string ext = Path.GetExtension(fileName).ToLower();
Microsoft.Win32.RegistryKey regKey = Microsoft.Win32.Registry.ClassesRoot.OpenSubKey(ext); // henter info fra windows registry
if (regKey != null && regKey.GetValue("Content Type") != null)
{
mimeType = regKey.GetValue("Content Type").ToString();
}
return File(uploadsDocumentPath + fileName, mimeType, fileName);
}
catch (Exception)
{
throw;
}
}
我希望能够只允许下载大小小于150MB的文件。但是我找不到如何计算这种类型文件的大小
有什么想法吗?我想这应该行得通:
FileInfo file = new FileInfo(uploadsDocumentPath + fileName);
if(file.Length > 157286400)
{
// Return error here.
}
我想这应该行得通:
FileInfo file = new FileInfo(uploadsDocumentPath + fileName);
if(file.Length > 157286400)
{
// Return error here.
}
没问题!很高兴我能帮忙:)150000000不是150MB。157286400为150MB=1024x1024x150@JeffYates我做了一个估计;)没问题!很高兴我能帮忙:)150000000不是150MB。157286400为150MB=1024x1024x150@JeffYates我做了一个估计;)