0

在我的 asp mvc 3 应用程序中,我有一个允许用户下载给定文件的操作。

这是代码:

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 的文件。但我找不到如何计算这种文件的大小。

有任何想法吗 ?

4

1 回答 1

3

我想这应该可行:

FileInfo file = new FileInfo(uploadsDocumentPath + fileName);
if(file.Length > 157286400)
{
      // Return error here.
}
于 2012-07-30T13:15:59.457 回答