[2 days left] What’s wrong with your cloud strategy? Learn why multicloud solutions matter with Nimble Storage.Register Now


Pdf upload issues on asp.net website hosting on iis 6.0

Posted on 2009-05-04
Medium Priority
Last Modified: 2013-12-14
I have a form on my site that allows users to upload files to a specified folder. Everything works fine in development, but on the production site im having some trouble with pdf files. Some files are working and others are showing as 0kb in the uploaded files folder, i am also receiving errors such as "File does not begin with '%PDF-. i have checked a lot of thing including the framework versions, ive ensured that there is no difference in the code and have even checked the AspMaxRequestEntityAllowed value in iis 6.0(thinking it may be a size issue). any ideas???
Question by:I_S_F_C_O
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
  • 2
  • 2
LVL 11

Expert Comment

ID: 24296907
Well quite hard to tell as i don't know what method or module you use for the upload, but it sounds like you programmed it yourself in asp (?) and that it allows you to upload different types and sizes of files.

Actually when i hear "Sometimes works, sometimes not" my first thought is "Virus scanner". Did you try to disable it and see if the upload works then? maybe it scans the file for too long or something similar. Did you check IIS logs? For the 0 byte files i would expect some error like "connection reset" or similar in the log.

Author Comment

ID: 24297105
Im sorry for the lack of information. Yes this was programmed in asp.net using c# and some javascript. I found nothing in the logfiles  i didnt find any kind of helpful error. i disabed avast with the same result. The server is running server 2003 attached is some of the code. i hope this helps you help me
<%@ Page Language="C#" MasterPageFile="~/Themes/MissionToMars/site.master" AutoEventWireup="true" CodeFile="PostNewDocument.aspx.cs" Inherits="Users_Administrator_PostNewDocument" Title="Untitled Page" %>
<asp:Content ID="Content1" ContentPlaceHolderID="CPH_Head" Runat="Server">
<asp:Content ID="Content2" ContentPlaceHolderID="CPH_Navigation" Runat="Server">
<asp:Content ID="Content3" ContentPlaceHolderID="CPH_Main" Runat="Server">
	<script language="javascript" type="text/javascript">
function UploadFolderFiles() {
function checkFile() {
    var found = 0;
    var foldobj = new ActiveXObject("Scripting.FileSystemObject");
    if ((navigator.userAgent.indexOf('Win') != -1)) {
        //Collect the data
        var docform = document.getElementById("<%=fuFile.ClientID%>").value;
        var parentNodeID = document.getElementById("<%=hidSelectedNode.ClientID%>").value;
        //Get the Location Type checked in the UI 
        var list = document.getElementById("<%=chkBxListLocationTypes.ClientID%>");
        var options = list.getElementsByTagName("input");
        var locationType;
        for (x = 0; x < options.length; ++x) {
            if (options[x].type == "radio" && options[x].checked) {
                locationType = options[x].value; 
        //Get the Roles checked in the UI
        var elementRef = document.getElementById("<%=chkBxListSecurity.ClientID%>");
        var checkBoxArray = elementRef.getElementsByTagName('input');
        var checkedRoleValues = '';
        //loop through all the checke boxes 
        for (var i = 0; i < checkBoxArray.length; i++) {
            var checkBoxRef = checkBoxArray[i];
            //get the values of checked roles and concatenate as comma seperated string
            if (checkBoxRef.checked == true) {
                var labelArray = checkBoxRef.parentNode.getElementsByTagName('label');
                if (labelArray.length > 0) {
                    if (checkedRoleValues.length > 0)
                        checkedRoleValues += ', ';
                    checkedRoleValues += labelArray[0].innerHTML;
        //Validation to check a file is selected and parent node id is selected
        if ((docform == "") || (parentNodeID == "")) {
            alert("Please select");
        else {
            //loop the path to get the folder 
            var strFilePath = docform.split("\\");
            var strFolder = ""
            var i = 0;
            for (i = 0; i <= strFilePath.length - 2; i++) {
                if (strFolder == "") {
                    strFolder = strFilePath[i];
                else {
                    strFolder = strFolder + "\\\\" + strFilePath[i];
            var myfolder = foldobj.GetFolder(strFolder);
            var z = myfolder.Files.Count;
            var fil_col = myfolder.Files;
            var en = new Enumerator(fil_col);
            var strFilePath = strFolder + "\\\\";
            //loop through all the files in the folder and call web service for each file in the folder
            for (; !en.atEnd(); en.moveNext()) {
                var objFileIO = foldobj.GetFile(strFilePath + en.item().Name);
                var textStreamObject = objFileIO.OpenAsTextStream(1, 0);
                var strFileContent = textStreamObject.ReadAll();
                var StrPath, StrFile, byteStream;
                StrPath = "\\Users\\UploadedFiles\\";
                //Read Binary File
//                                var binData = new ActiveXObject("ADODB.Stream");
//                                binData.Mode = 3; //read write 
//                                binData.Open();
//                                binData.Type = 1; //adTypeBinary
//                               binData.LoadFromFile(strFilePath + en.item().Name);
//                                var binstream = binData.Read(-1);
//                                streamIO;
                StrFile = en.item().Name;
                //need to change the webservice call once published to the server
//                service.useService("http://localhost:62225/ISUploadService.asmx?wsdl", "UploadDocumentService");
//                service.UploadDocumentService.callService("UploadDocument", StrPath, StrFile, parentNodeID, locationType, checkedRoleValues, strFileContent);
                //service.UploadDocumentService.callService("UploadDocument", StrPath, StrFile, parentNodeID, locationType, checkedRoleValues, binstream);                
        }//End of IF
    return found;
function ShowResult() {
//    alert(event.result.value);
<div id="service" style="behavior:url(webservice.htc)"   onresult="ShowResult()" >
<div id="outputDiv" style="width: 100px; height: 100px">
	<div style="padding:10px; border:solid 1px #CCCCCC; width:90%; background-color:#EEEEEE; font-size:12px;">
		<h2>Add A New Document</h2>
		Upload a document to the intranet. You can control who can download the document by selecting the roles of users that should be able to download the document.
		<br /><br />
		<div style="background-color:White; padding:20px;">
		Begin by selecting the folder where the document will be located.<br /><br />
			<ASP:Literal id="TreeView" EnableViewState="false" runat="server" />
				<asp:HiddenField ID="hidSelectedNode" runat="server" />
		<br /><br />
		Attachment <asp:FileUpload ID="fuFile" runat="Server" ></asp:FileUpload>
		<asp:Button ID="btnAttach" runat="server" Height="20px" Text="Attach" 
			Width="71px" onclick="btnAttach_Click" OnClientClick="" />
		<br />
		<asp:Label ID="lblError" runat="server" Visible="false"></asp:Label>
		<br />
		Description <asp:TextBox ID="txtTitle" runat="server" Width="336px"></asp:TextBox> 
		<br />
		<asp:ListBox ID="lstFiles" runat="server" Width="342px" 
			style="margin-left: 64px"></asp:ListBox>
		<asp:Button ID="btnRemove" runat="server" onclick="btnRemove_Click" 
			Text="Remove" />
		<br />
		<div id="divSecure" style="border:solid 1px #777777; background-color:#cccccc; padding:10px;">
			<b>Select locations that should have access to the document.</b>
			<asp:RadioButtonList ID="chkBxListLocationTypes" runat="server" DataTextField="CompanyLocationType" DataValueField="CompanyLocationTypeId"></asp:RadioButtonList>
			<br /><br />
			<b>Select user roles that should have access to the document.</b>
			<asp:CheckBoxList ID="chkBxListSecurity" runat="server" RepeatColumns="2"></asp:CheckBoxList>
		<br />
		<div style="width:100%; text-align:right;">
			<asp:Button ID="btnUploadFolder" runat="server" onclick="btnUploadFolder_Click" 
				Text="Upload Folder" OnClientClick="" />
			<asp:Button ID="btnSubmit" runat="server" Text=" Upload Document " OnClick="btnSubmit_Click" />
		<br />
	<script language="javascript" type="text/javascript">
		function ob_OnNodeSelect(id)
			document.getElementById("<%=hidSelectedNode.ClientID%>").value = id;
protected void btnSubmit_Click(object sender, EventArgs e)
		string sParentNodeId = hidSelectedNode.Value;
		if (!String.IsNullOrEmpty(sParentNodeId))
			string fileName = string.Empty;
            foreach (System.Web.UI.WebControls.FileUpload upLoadFile in alFilesUpload)
                if (upLoadFile.PostedFile != null && !String.IsNullOrEmpty(upLoadFile.PostedFile.FileName))
                    //Upload File . TODO :Modify to call UploadFiles if multiple file attached
                    //fileName = UploadFile();
                    fileName =  Path.GetFileName(upLoadFile.PostedFile.FileName);
                    if (!String.IsNullOrEmpty(fileName.Trim()))
                        //Add to folder tree.
                        DocumentFolders documentFolders = new DocumentFolders();
                        string newNodeId = documentFolders.GetNewNodeId();
                        AddDocumentToTree(fileName, sParentNodeId, newNodeId);
                        if (alFilesUpload.Count ==1)
                            string redirectURL = ResolveUrl("~/Users/DownloadDocument.aspx");
                            Response.Redirect(redirectURL + "?id=" + newNodeId);
            //Clear all the storage
			//No folder selected.
			lblError.Text = "No folder was selected.";
	protected void SecureDocument(string newNodeId)
		DocumentFolders documentFolders = new DocumentFolders();
		if (chkBxListLocationTypes.SelectedValue != null)
			string locationType = chkBxListLocationTypes.SelectedValue;
			documentFolders.InsertDocumentCompanyLocationType(newNodeId, locationType);
			//Add entry for location type and node id
		ISF isf = new ISF();
		//Add entries for roles and node id.
		foreach (ListItem li in chkBxListSecurity.Items)
			if (li.Selected)
				string roleId = isf.GetRoleId(li.Value);
				documentFolders.InsertDocumentRoles(newNodeId, roleId);
	protected void AddDocumentToTree(string fileName, string sParentNodeId, string newNodeId)
		//Add the node info to the folder.
		TreeDB oTreeDB = new TreeDB();
		BaseData baseData = new BaseData();
		oTreeDB.ConnectionString = baseData.ISF_Operations_ConnectionString;
		// declaring the table name:			
		oTreeDB.TableName = "treeview";
		oTreeDB.ProviderName = "System.Data.SqlClient";
		oTreeDB.Fields[TreeDB.StandardFields.ParentID].Value = sParentNodeId;
		oTreeDB.Fields[TreeDB.StandardFields.ID].Value = newNodeId;
		oTreeDB.Fields[TreeDB.StandardFields.HTMLValue].Value = fileName;
		oTreeDB.Fields[TreeDB.StandardFields.Icon].Value = "page.gif";
		oTreeDB.Fields[TreeDB.StandardFields.Expanded].Value = "0";
		// process the information and returning the result:
		string sResult = oTreeDB.ExecuteEvent(TreeDB.EventTypes.Add);

Open in new window

LVL 11

Expert Comment

ID: 24370544
Well the code you provided looks fine, nothing specific to pdf files i can see here, very rudimentary file upload which can barely go wrong. The error can't be in the code as you say you use it and it works fine in development. Can you pin it down to some specific files/users/clients? that would be a hint for rather a client based problem, at least if it can be reproduced or nailed down to a few "suspicious subjects". if there is nothing like this the problem is very likely in the installation. Try to compare services, registry, permissions and so on. heck if you can't find anything I'd go so far to suggest putting a clone of the development machines were it works fine in production to see if the behaviour can be reproduced on these as well, if that is not the case and you really cant find anything, I'd suggest to set up the production machine again from scratch, 100% modeled after the development ones. But i really wish you that you find the missing piece of the puzzle.

Accepted Solution

I_S_F_C_O earned 0 total points
ID: 24472977
Ok thanks for pointing me in the right direction guys. This is what i found.,,,Everything i tested said that it either had to be a time limit or a size limit. i adjusted the executionTimeout to "1200" and maxRequestLength to "102400" in the web.config file.That allowed me to consistently upload files up to 70kb. Then , being almost certain it was a time issue, i found this information


After adjusting the requestLenghtDiskThreshold several times it appears that everything is working ok. Here is my current settings in the web.config file.


 I also had to adjust the AspMaxRequestEntityAllowed value in the iis metabase. I set it to maximum



Featured Post

Learn how to optimize MySQL for your business need

With the increasing importance of apps & networks in both business & personal interconnections, perfor. has become one of the key metrics of successful communication. This ebook is a hands-on business-case-driven guide to understanding MySQL query parameter tuning & database perf

Question has a verified solution.

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

This program is used to assist in finding and resolving common problems with wireless connections.
This article explains the fundamentals of industrial networking which ultimately is the backbone network which is providing communications for process devices like robots and other not so interesting stuff.
Monitoring a network: how to monitor network services and why? Michael Kulchisky, MCSE, MCSA, MCP, VTSP, VSP, CCSP outlines the philosophy behind service monitoring and why a handshake validation is critical in network monitoring. Software utilized …
Monitoring a network: why having a policy is the best policy? Michael Kulchisky, MCSE, MCSA, MCP, VTSP, VSP, CCSP outlines the enormous benefits of having a policy-based approach when monitoring medium and large networks. Software utilized in this v…

649 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