INPUT tag will not let me upload PDFs

I am using the INPUT tag to allow the user to upload a file to the web server.    When I upload an image file, it uploads fine.  However, when I try upload a pdf, i get the message "[FILENAME] not found as file or resource."   Does anyone have any idea how I can upload a pdf through the INPUT tag on a webpage?    I don't think it's the file size because the one I am trying to upload is about 100KB and I am able to upload images that are around 750KB.

Below is a snippet of the code I am using.   AliasFileName is simply a randomly generated file name with the same extension of the file that the user is trying to upload.   Any help would be greatly appreciated!!!
[HTML CODE]
<asp:label id="Label1" runat="server"><span style="COLOR: red">* </span>Document: </asp:label>
<input id="txtNewDocument" style="FONT-SIZE: 9pt; WIDTH: 470px" type="file" name="txtNewDocument" runat="server">
<br>
<asp:button id="btnUploadDocument" Runat="server" Text="Upload Document"></asp:button>
 
[VB CODE]
Dim Document As System.Web.UI.HtmlControls.HtmlInputFile = Me.FindControl("txtNewDocument")
Document.PostedFile.SaveAs(Server.MapPath(AliasFileName))

Open in new window

amb1313Asked:
Who is Participating?
 
amb1313Connect With a Mentor Author Commented:
I figured out the problem.    I was using itextsharp right after the upload to see how many pages were in the PDF.  The web server did not have Acrobat Reader installed which in turn made it so that the API wouldn't work correctly.   The error message was not very informative and appeared to be erroring out on the upload which is why I didn't realize it was because of itextsharp.dll reading the pdf.

I figured this out by reading some of the messages that were getting written to the web server's event viewer because they were referencing itextsharp.    I couldn't figure this out when I was debugging locally beacuse I did have Acrobat Reader installed and therefore I couldn't re-create the problem
0
 
amb1313Author Commented:
Did some more testing and it's letting me upload things other than images such as Word Docs and Excel Spreadsheets.   However, for some reason, it keeps giving me the message "[FILENAME] not found as file or resource." when I try to upload any PDF.    Any ideas why I'm getting this for PDF files?
0
 
Muhammad Ousama GhazaliSolution Analyst & ArchitectCommented:
Try anyone of the following:
  • Reduce the path and name of the file on the server side.
  • Make sure Server.MapPath is pointing to a local server path or a path which has local mapping such as network paths mapped as local map drive.
  • Try using FileUpload control of ASP.NET rather than HTML INPUT element.
0
Cloud Class® Course: Microsoft Office 2010

This course will introduce you to the interfaces and features of Microsoft Office 2010 Word, Excel, PowerPoint, Outlook, and Access. You will learn about the features that are shared between all products in the Office suite, as well as the new features that are product specific.

 
amb1313Author Commented:
Also, to add to this some more.   If I run this website locally on my machine, it allows me to upload the PDF just fine.   Don't know if it's because the my machine is acting as the web server and it's allowing it because the website is running on the same machine that the PDF lives on.   However, when I push the site out to a web server, it gives me that error when I try to upload PDFs after browsing for the PDF on my client machine.

Someone please help with this, it's needed ASAP!
0
 
Muhammad Ousama GhazaliSolution Analyst & ArchitectCommented:
One more thing, try uploading some other PDF that gets opened correctly in Adobe Reader.
0
 
amb1313Author Commented:
I don't see a FileUpload control for ASP.NET.   This website is running on the 1.1 framework.    Could that be why?

The Server.MapPath is pointing to the directory where the .aspx file lives.   When I upload Images, Documents, Spreadsheets, etc...they get uploaded right into this directory just fine.

The file I am trying to upload is C:\test.pdf on my local machine.   I kept the path short and without spaces or special characters to eliminate that as a possible issue.
0
 
amb1313Author Commented:
The file I am trying to upload (C:\test.pdf) opens up fine on my machine in Acrobat Reader.   I've  also tried other pdfs just to make sure it's nothing specific to that file.
0
 
Muhammad Ousama GhazaliSolution Analyst & ArchitectCommented:
Can you please check with your remote server if the path that is returned by the AliasFileName is a local path or a network path? I have just gone through some information on web that it may be a cause but not sure of that. If possible, try making a small test and try storing the PDF using Server.MapPath("./myDocument.pdf").
0
 
Muhammad Ousama GhazaliSolution Analyst & ArchitectCommented:
There are some hosts which may prohibit uploading specific files in specific hosted-space. If youre remote server is hosted on a web server which utilizes network disks as primary storage of websites and related data even though it presents the path as a locally mapped path, due to upload restrictions the problem you are facing may occur. Apart from restrictions, make sure you are using some user account for executing ASP.NET code other than the Network Service which is by default the user account under which ASP.NET code is executed. I know other files are being copied/uploaded correctly, but see if this is the case.
Fore more information and a possible solution to overcome user account problem and use impersonation in ASP.NET, see this link (check the last three posts especially): http://forums.asp.net/p/1385010/2948151.aspx#2948151
0
 
amb1313Author Commented:
I get the same exact behavior.    If I upload an image, it uploads it to the directory where the .aspx file is and names it "myDocument.pdf".    If I then browse to a PDF (I tried 3 different ones), it gives me the "[FILENAME] not found as file or resource." error message.
0
 
amb1313Author Commented:
This is a work related issue and I have access to the web server.  I looked around but don't see anything that would indicated certain file types being restricted.   The site is running as a user that has basically admin rights.
0
 
amb1313Author Commented:
If I rename "test.pdf" to "test.jpg" it uploads fine.  Any ideas on that?
0
 
Muhammad Ousama GhazaliSolution Analyst & ArchitectCommented:
It looks to me some sort of OS/PDF error rather than the code logic. For the time being, I have run out of options, will come back to it later.
0
 
amb1313Author Commented:
Even if I rename it to something that's completely invalid like "test.pdx" it lets me upload that.    Seems I can upload pretty much anything that doesn't end in .PDF
0
 
Muhammad Ousama GhazaliSolution Analyst & ArchitectCommented:
Please take a little more time reading the last post on this page:
http://forums.asp.net/p/1418774/3138948.aspx
Hope this might lead to some fruitful results.
0
 
ajollyCommented:
See this page:
http://forums.asp.net/p/1418774/3138948.aspx

Notice the last post.
The person had the same issue, and resolved as well.
0
 
ajollyCommented:
Congratulations.
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.