0

用户上传一个文件,然后由医生审查。然后医生上传他的文件,说明他们的评论,然后用户可以阅读文件。至少,他们应该能够。当医生上传文件时,会在用户文件夹中创建一个新目录,并将项目上传到该文件夹​​中。

现在的错误。在详细信息页面上,用户看到有一个文件链接可供下载,以便他们可以阅读医生的笔记。但是当他们单击链接时,链接返回 404。我们发现,如果我们从 Review 文件夹中删除文件并将其放在主用户目录中,则链接现在可以正常工作。显然链接没有指向正确的位置,但由于我不知道 .NET 或 C#,这已被证明是相当烦人的。

以下是 Details.cshtml 页面的部分原始代码:

<table>
      <tr>
           <th colspan="4" class="display-label">Uploaded Documents</th>

      </tr>
           <tr>
                <th>FileName</th>
                <th>Download Files</th>
           </tr>
           @foreach (var file in ((IEnumerable<MyCombinedQueryModel>)ViewBag.Files))
           {<tr>
                 <td>
                      @Html.ActionLink("Download", "Download", new { id = Model.PatientsId, name = file.FileName })
                 </td>
                 <td>
                      @file.FileName
                 </td>
            </tr>

           }<tr>
            <th colspan="4" class="display-label">Download reviewer suggestion document</th></tr>
      <tr>
           <th>FileName</th>
           <th>Download Files</th>
      </tr>
           @if(Model.reviewed)
           {
                foreach (var file in ((IEnumerable<MyCombinedQueryModel>) ViewBag.Path))
                {
                     <tr>
                          <td>
                               @Html.ActionLink("Download", "Download", new {id = Model.PatientsId, name = file.FileName})
                          </td>
                          <td>
                               @file.FileName
                          </td>
                     </tr>
                }
           }

 </table>

以及来自 DoctorsController.cs 的部分

 //Download files string names
     public ActionResult Download(int? id, string name)
          {


               string fileName = name;


               var uploads = (from u in _db.Patients
                             where u.PatientsId == id
                             select u.FilesUrl).FirstOrDefault();


               if (uploads != null)
               {

                    string folder = Path.GetFullPath(uploads);
                    //HttpContext.Response.AddHeader("content-dispostion", "attachment; filename=" + fileName);
                    return File(new FileStream(folder +"/" + fileName, FileMode.Open), "content-dispostion", fileName);
               }

               throw new ArgumentException("Invalid file name of file not exist");
          }

现在在我们的数据库中,我们有两个字段,FilesUrl 和 PathUrl。PathUrl 保存 Review 文件夹中已审阅文件的 URL。如果我是正确的,我认为正在发生的事情是它们都在调用仅链接到 FileUrl 的相同函数(下载)。我尝试在详细信息页面中将审核部分中的 actionLink 更改为“DownloadR”,然后复制并粘贴下载功能(将其重命名为 DownloadR 并将其更改为查找 PathUrl),但它仍然无法正常工作。

有没有人在这里看到任何问题或关于如何解决它的任何建议?提前感谢您的宝贵时间!

4

1 回答 1

1

看起来 FilesUrl 与 PathUrl 的问题。如果患者上传的文件和 Dr 上传的文件位于不同的目录中,则此控制器方法不适用于两者。

我将向 Download 方法添加第三个参数,该参数指定要下载的文件是来自 Dr 还是患者。

public ActionResult Download(int? id, string name, bool reviewDirectory)
...
var uploads = (from u in _db.Patients
               where u.PatientsId == id
               select (reviewDirectory ? u.PathUrl : u.FilesUrl)).FirstOrDefault();
于 2012-10-18T19:40:04.923 回答