18
  public ActionResult MyFile(string MetaValue,int OrganizationId=0)
    {          
            OrganizationUsersDataContext OrgMeta = new OrganizationUsersDataContext();
            JobsRepository JobsRespository = new JobsRepository();
            string CvPath = JobsRespository.GetCvPath();
            var FilePathForOrganization = OrgMeta.OrganizationMetas.FirstOrDefault(m => m.bit_IsDeletable == true && m.int_OrganizationId == OrganizationId && m.vcr_MetaKey == "PhysicalPath");
            string CompletePhysicalPath = FilePathForOrganization.vcr_MetaValue + CvPath +  MetaValue ;
            return File(@CompletePhysicalPath,"");

    }

My File can return doc,docx or pdf , what to have in content type . which is giving problem.

0

2 Answers 2

27

Here's a list of ContentTypes that you can use to pass back to your View

http://www.wiley.com/legacy/compbooks/graham/html4ed/appb/mimetype.html

Word (.doc)

application/msword

Word (.docx)

application/vnd.openxmlformats-officedocument.wordprocessingml.document

PDF (.pdf)

application/pdf

20

I made this method some time ago:

public static string GetMimeType(string fileName)
{
    string mimeType = "application/unknown";
    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();
    }
    else if (ext == ".png") // a couple of extra info, due to missing information on the server
    {
        mimeType = "image/png";
    }
    else if (ext == ".flv")
    {
        mimeType = "video/x-flv";
    }
    return mimeType;
}

You can use that to set the mimetype, like this:

Response.ContentType = GetMimeType(@CompletePhysicalPath);

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.