Solved

INPUT tag will not let me upload PDFs

Posted on 2009-05-14
17
335 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
 
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
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 

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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

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…
Use these top 10 tips to master the art of email signature design. Create an email signature design that will easily wow recipients, promote your brand and highlight your professionalism.
In this tutorial viewers will learn how to position overlapping items using z-index in CSS. They will also learn the restrictions on the z-index property.  Create a new HTML document with an internal stylesheet.: Create a div in CSS and name it Red.…
Learn how to create flexible layouts using relative units in CSS.  New relative units added in CSS3 include vw(viewports width), vh(viewports height), vmin(minimum of viewports height and width), and vmax (maximum of viewports height and width).

911 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

19 Experts available now in Live!

Get 1:1 Help Now