0

My problem is a simple on, but I haven't found a solution yet. I have a folder that contains uploaded resumes stored in pdf, doc, and docx formats. The admin backend page shows links to the resumes for each user. If a link to a pdf or doc is clicked the file is downloaded/opened, but if a link to a docx is clicked a 404 error page is shown and if you save the file to your desktop and open word says it is corrupted and cannot be opened. All files can be opened on the web server.

Rather than using code to download files, my links look like: http://www.site.com/test/resume/John_Doe_Resume.docx

I'm sure there is an easy fix. Has anyone else run into this problem?

Robo
  • 45
  • 8
  • 1
    Can you post the code to the function that serves your docx files? – M.Babcock Feb 01 '12 at 00:31
  • Assuming the document is good, do you have MS-Word or (reader) compatible version? Did you try this from IE? – NoChance Feb 01 '12 at 00:34
  • Looks like a configuration issue... Make sure you don't have a special handler configured for the .docx extension in IIS – Thomas Levesque Feb 01 '12 at 00:34
  • Possible duplicate of this: http://stackoverflow.com/questions/2477564/why-are-docx-files-being-corrupted-when-downloading-from-an-asp-net-page Check if it helps. – rikitikitik Feb 01 '12 at 00:35
  • They are merely links to files stored in the folder. I had trouble with certain file types not downloading correctly using a binary write and I was advised that just linking to the files was the easiest way to do it. – Robo Feb 01 '12 at 00:36

2 Answers2

3

Make sure .docx has been set up in IIS's list of MIME-types:

Configure MIME Types (IIS 6.0)

IIS (7 too for that matter) will give a 404 error if it doesn't know the MIME-type that corresponds to the file extension. If it's not there (and it isn't by default in IIS 6), add .docx with a MIME-type of

application/vnd.openxmlformats-officedocument.wordprocessingml.document
JimmiTh
  • 7,389
  • 3
  • 34
  • 50
  • It was in fact not setup in IIS. I added it to the MIME types with application/msword as the type. It still gives a 404. I'm new to IIS and might be missing a step – Robo Feb 01 '12 at 00:43
  • The MIME type shouldn't be causing a 404 error. There is something else wrong. – M.Babcock Feb 01 '12 at 00:45
  • IIS may need to be restarted. Note that this will drop all connections etc., so don't "just do it" on a production server. From MSDN (long time since I've touched IIS 6): In IIS Manager, right click the local computer, point to **All Tasks**, then click **Restart IIS**. In the **What do you want IIS to do** list, click Restart Internet Services on *computername*. – JimmiTh Feb 01 '12 at 00:49
  • Lack of MIME type on IIS *always* causes a 404 error. See [here](http://www.microsoft.com/technet/prodtechnol/WindowsServer2003/Library/IIS/deeac9ef-cf55-4acd-86ce-b46022ff5479.mspx?mfr=true) (well, as it says, except when you turn off "Known extensions", which you shouldn't) – JimmiTh Feb 01 '12 at 00:51
  • I'll try restarting IIS in a bit and see if that does it. I will let you know if it changes things. – Robo Feb 01 '12 at 00:56
  • Mission Success. Added the MIME type and restarted the service. All is well once more. Thanks! – Robo Feb 01 '12 at 02:40
1

I'll bet the framework is treating the .docx extension as a type of executable file; the code or IIS is trying to execute it, which fails.

Check your IIS configuration for file extensions to execute, your web.config and/or your application's routing table, I'll bet the answer is somewhere in there.

eouw0o83hf
  • 9,438
  • 5
  • 53
  • 75