Solved

INPUT tag will not let me upload PDFs

Posted on 2009-05-14
17
336 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
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
Live: Real-Time Solutions, Start Here

Receive instant 1:1 support from technology experts, using our real-time conversation and whiteboard interface. Your first 5 minutes are always free.

 
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

Gigs: Get Your Project Delivered by an Expert

Select from freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely and get projects done right.

Question has a verified solution.

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

Suggested Solutions

Building a website can seem like a daunting task to the uninitiated but it really only requires knowledge of two basic languages: HTML and CSS.
This article explains how to prepare an HTML email signature template file containing dynamic placeholders for users' Azure AD data. Furthermore, it explains how to use this file to remotely set up a department-wide email signature policy in Office …
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 receive an overview of the basics of CSS showing inline styles. In the head tags set up your style tags: (CODE) Reference the nav tag and set your properties.: (CODE) Set the reference for the UL element and styles for it to ensu…

786 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