Solved

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

Posted on 2009-05-04
4
927 Views
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???
0
Comment
Question by:I_S_F_C_O
  • 2
  • 2
4 Comments
 
LVL 11

Expert Comment

by:kyodai
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.
0
 

Author Comment

by:I_S_F_C_O
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
ASPX PAGE

<%@ 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>

<asp:Content ID="Content2" ContentPlaceHolderID="CPH_Navigation" Runat="Server">

</asp:Content>

<asp:Content ID="Content3" ContentPlaceHolderID="CPH_Main" Runat="Server">
 

	<script language="javascript" type="text/javascript">

function UploadFolderFiles() {

    checkFile();

}

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; 

                break;

            }

        }
 

        //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];

                }

            }

            //end
 
 

            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;

                //'End

                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);

}
 

</script>
 

<div id="service" style="behavior:url(webservice.htc)"   onresult="ShowResult()" >

<div id="outputDiv" style="width: 100px; height: 100px">

        </div>

	<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" />

			</div>

		<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>

		</div>

		<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" />

		</div>

		<br />

	</div>

	

  </div>

	<script language="javascript" type="text/javascript">

		function ob_OnNodeSelect(id)

		{

			document.getElementById("<%=hidSelectedNode.ClientID%>").value = id;

		}

	</script>

</asp:Content>
 
 

The CS PAGE

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);

                    UploadFiles(upLoadFile);

                    if (!String.IsNullOrEmpty(fileName.Trim()))

                    {

                        //Add to folder tree.

                        DocumentFolders documentFolders = new DocumentFolders();

                        string newNodeId = documentFolders.GetNewNodeId();

                        AddDocumentToTree(fileName, sParentNodeId, newNodeId);

                        SecureDocument(newNodeId);

                        if (alFilesUpload.Count ==1)

                        {

                            string redirectURL = ResolveUrl("~/Users/DownloadDocument.aspx");

                            Response.Redirect(redirectURL + "?id=" + newNodeId);

                        }

                    }

                }

            }

            //Clear all the storage

            alFilesUpload.Clear();

            alDescription.Clear();

            lstFiles.Items.Clear();

		}

		else

		{

			//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

0
 
LVL 11

Expert Comment

by:kyodai
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.
0
 

Accepted Solution

by:
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

http://msdn.microsoft.com/en-us/library/system.web.configuration.httpruntimesection.requestlengthdiskthreshold.aspx


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

 <httpRuntime
 executionTimeout="1200"
  maxRequestLength="102400"
   requestLengthDiskThreshold="2400"/>

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

http://www.infoqu.com/175262-1-aspmaxrequestentityallowed--increasing-the-value-in-iis-60.html


0

Featured Post

Threat Intelligence Starter Resources

Integrating threat intelligence can be challenging, and not all companies are ready. These resources can help you build awareness and prepare for defense.

Join & Write a Comment

Lets look at the default installation and configuration of FreeProxy 4.10 REQUIREMENTS 1. FreeProxy 4.10 Application - Can be downloaded here (http://www.handcraftedsoftware.org/index.php?page=download) 2. Ensure that you disable the windows fi…
Some time ago I was asked to set up a web portal PC to put at our entrance. When customers arrive, they could see a webpage 'promoting' our company. So I tried to set up a windows 7 PC as a kiosk PC.......... I will spare you all the annoyances I…
Viewers will learn how to connect to a wireless network using the network security key. They will also learn how to access the IP address and DNS server for connections that must be done manually. After setting up a router, find the network security…
This video gives you a great overview about bandwidth monitoring with SNMP and WMI with our network monitoring solution PRTG Network Monitor (https://www.paessler.com/prtg). If you're looking for how to monitor bandwidth using netflow or packet s…

758 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

22 Experts available now in Live!

Get 1:1 Help Now