1

下面是我的代码,因为我正在读取文件中的内容,然后我可以显示和下载 txt 文件中的内容。但是当我打开 txt 文件时,标题看起来像 filename.txt[1]。我想要文件名仅作为标题。我不知道它 [1] 是什么意思。

public FileResult Download(string id)
    {
        int rowId = Convert.ToInt32(id);
        LoadFileInfoCache();
        var fileDetails = from ff in _currentFileDetails
                          where ff.FileId == rowId
                          select new
                          {
                              name = ff.FileName,
                              location = ff.FileLocation
                          };
        var fileDetailsList = fileDetails.ToList();
        string fileLocation = fileDetailsList[0].location;
        string fileName = fileDetailsList[0].name + ".txt";
        string contentType = "application/txt";
        var file = System.IO.File.Open(fileLocation, FileMode.Open, FileAccess.Read, FileShare.ReadWrite);
        var stream = (Stream)(file);

        return File(stream, contentType, fileName);
    } 

谁能帮忙,我的代码哪里出了问题。

4

1 回答 1

1

出现“[1]”是因为客户端计算机已有同名文件。SO 在其前面放置一个 [1] 以避免冲突或覆盖。这不是错误,这是默认行为,无法更改。但是,正在下载文件的用户可以根据需要更改文件名。

于 2012-08-07T11:24:57.970 回答