Solved

INPUT tag will not let me upload PDFs

Posted on 2009-05-14
17
334 Views
Last Modified: 2012-05-07
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

0
Comment
Question by:amb1313
  • 9
  • 6
  • 2
17 Comments
 

Author Comment

by:amb1313
Comment Utility
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
 
LVL 11

Expert Comment

by:Muhammad Ousama Ghazali
Comment Utility
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
 

Author Comment

by:amb1313
Comment Utility
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
 
LVL 11

Expert Comment

by:Muhammad Ousama Ghazali
Comment Utility
One more thing, try uploading some other PDF that gets opened correctly in Adobe Reader.
0
 

Author Comment

by:amb1313
Comment Utility
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
 

Author Comment

by:amb1313
Comment Utility
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
 
LVL 11

Expert Comment

by:Muhammad Ousama Ghazali
Comment Utility
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
 
LVL 11

Expert Comment

by:Muhammad Ousama Ghazali
Comment Utility
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
How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

 

Author Comment

by:amb1313
Comment Utility
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
 

Author Comment

by:amb1313
Comment Utility
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
 

Author Comment

by:amb1313
Comment Utility
If I rename "test.pdf" to "test.jpg" it uploads fine.  Any ideas on that?
0
 
LVL 11

Expert Comment

by:Muhammad Ousama Ghazali
Comment Utility
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
 

Author Comment

by:amb1313
Comment Utility
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
 
LVL 11

Expert Comment

by:Muhammad Ousama Ghazali
Comment Utility
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
 
LVL 7

Expert Comment

by:ajolly
Comment Utility
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
 

Accepted Solution

by:
amb1313 earned 0 total points
Comment Utility
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
 
LVL 7

Expert Comment

by:ajolly
Comment Utility
Congratulations.
0

Featured Post

How to improve team productivity

Quip adds documents, spreadsheets, and tasklists to your Slack experience
- Elevate ideas to Quip docs
- Share Quip docs in Slack
- Get notified of changes to your docs
- Available on iOS/Android/Desktop/Web
- Online/Offline

Join & Write a Comment

Suggested Solutions

Do you want to insert HTML5 video into your site? This is the tutorial how to do so. What are the main advantages of HTML5 video? 1) Have good compression, good image quality, and low decode processor use. 2) It is royalty-free 3) It is easi…
It was really hard time for me to get the understanding of Delegates in C#. I went through many websites and articles but I found them very clumsy. After going through those sites, I noted down the points in a easy way so here I am sharing that unde…
In this tutorial viewers will learn how to embed Flash content in a webpage using HTML5. Ensure your DOCTYPE declaration is set to HTML5: "<!DOCTYPE html>": Use the <object> tag to embed Flash content.: To specify that the object is Flash content, d…
The viewer will learn the basics of jQuery including how to code hide show and toggles. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery…

772 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

13 Experts available now in Live!

Get 1:1 Help Now