0

Users upload a file which then gets reviewed by a doctor. The doctor then uploads his file stating their remarks and then the user can read the file. At least, they SHOULD be able to. When the doctor uploads a file a new directory is created inside the user's folder and the item is uploaded into that folder.

Now the bug. On the details page users see that there is a file link to be downloaded so they can read the doctor's notes. But when they click the link, the link comes back a 404. We found that if we remove the file from the Review folder and put it in the main user directory the link now works. Obviously the link is not pointing to the correct place, but as I do not know .NET or C# this has proven to be quite an annoyance.

Here is part of the original code from the Details.cshtml page:

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

And the part from 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");
          }

Now in our database we have two fields, FilesUrl and PathUrl. PathUrl holds the URL for the Reviewed file in the Review folder. I think what's going on, if I'm correct, is that they are both calling the same function (Download) which ONLY links to FileUrl. I tried changing the actionLink in the reviewed part to "DownloadR" in the details page and then copied and pasted the Download function (renamed it to DownloadR and changed it to look for PathUrl) but it still didn't work correctly.

Is there anything anyone sees here that is a problem or any advice as to how to fix it? Thank you in advance for your time!

1 Answers1

1

It looks like an issue with FilesUrl vs PathUrl. If the patient uploaded files and Dr uploaded files are in different directories this controller method will not work with both.

I would add a third argument to the Download method that specified if the file to download was from the Dr or patient.

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();
Justin
  • 839
  • 1
  • 16
  • 24
  • Thank you for your response. I'm a bit confused as to what I put for reviewDirectory? Do I actually write out the path? C:/inetpub/wwwroot etc? Sorry if this is a super newbie question but I am not a programmer in the slightest! – user1686221 Oct 22 '12 at 14:53