?
Solved

INPUT tag will not let me upload PDFs

Posted on 2009-05-14
17
Medium Priority
?
342 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 9
  • 6
  • 2
17 Comments
 

Author Comment

by:amb1313
ID: 24391378
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
ID: 24391393
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
ID: 24391403
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
Are You Using the Best Web Development Editor?

The worlds of web hosting and web development are constantly evolving. Every year we see design trends change, coding standards adapt and new frameworks/CMS created. With such a quick pace of change it’s easy to get lost trying to keep up.

See if your editor made the list.

 
LVL 11

Expert Comment

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

Author Comment

by:amb1313
ID: 24391426
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
ID: 24391429
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
ID: 24391431
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
ID: 24391495
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
 

Author Comment

by:amb1313
ID: 24391506
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
ID: 24391526
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
ID: 24391560
If I rename "test.pdf" to "test.jpg" it uploads fine.  Any ideas on that?
0
 
LVL 11

Expert Comment

by:Muhammad Ousama Ghazali
ID: 24391600
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
ID: 24391608
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
ID: 24391685
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
ID: 24391686
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
ID: 24391909
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
ID: 24392420
Congratulations.
0

Featured Post

Video: Liquid Web Managed WordPress Comparisons

If you run run a WordPress, you understand the potential headaches you may face when updating your plugins and themes. Do you choose to update on the fly and risk taking down your site; or do you set up a staging, keep it in sync with your live site and use that to test updates?

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

When it comes to write a Context Sensitive Help (an online help that is obtained from a specific point in state of software to provide help with that state) ,  first we need to make the file that contains all topics, which are given exclusive IDs. …
Originally, this post was published on Monitis Blog, you can check it here . In business circles, we sometimes hear that today is the “age of the customer.” And so it is. Thanks to the enormous advances over the past few years in consumer techno…
In this tutorial viewers will learn how to position items using CSS's three positioning types Create a new HTML document with an internal stylesheet.: Create another div in CSS and name it Absolute : Type "position:absolute;" and "top:10px; left:50p…
In this tutorial viewers will learn how to style a corner ribbon overlay for an image using CSS Create a new class by typing ".Ribbon":  Define the class' "display:" as "inline-block": Define its "position:" as "relative": Define its "overflow:" as …
Suggested Courses

752 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