views:

36

answers:

1

I'm having a weird error which is related to an earlier post. I am checking if a file exists before downloading. This works for PDFs, but not for any other type of document.

Here is my controller action and the typical path for a PDF and a PowerPoint file, the PowerPoint does not work, the File.Exists always returns false. Both files physically exist. This is quite baffling, as it results in a FileNotFoundException for non-PDFs.

/Documents//FID//TestDoc//27a835a5-bf70-4599-8606-6af64b33945d/FIDClasses.pdf

~/Documents//FID//pptest//ce36e7a0-14de-41f3-8eb7-0d543c7146fe/PPttest.ppt

The joke is that copying and pasting the file path into explorer leads to the file, so what could be the problem?

[UnitOfWork]
public ActionResult Download(int id)
{
    Document doc = _documentRepository.GetById(id);

    if (doc != null)
    {
        if (System.IO.File.Exists(Server.MapPath(doc.filepath)))
        {
            _downloadService.AddDownloadsForDocument(doc.document_id, _UserService.CurrentUser().user_id);
            return File(doc.filepath, doc.mimetype, doc.title);
        }
    }
    return RedirectToAction("Index");
}
A: 

Check the permissions on the PPT file and the directory, check the file doesn't have some 'zone' information attached to it because you downloaded it from somewhere else.

Hightechrider
Thanks, ive looked at the permissions and it seems fine, the weird thing is that it happens to all the files apart from the pdfs.
bongoo