Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/csharp-4.0/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Asp.net mvc 3 如何在C语言中计算文件大小#_Asp.net Mvc 3_C# 4.0 - Fatal编程技术网

Asp.net mvc 3 如何在C语言中计算文件大小#

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()

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


有什么想法吗?

我想这应该行得通:

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我做了一个估计;)