Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Losing values with multipart/form-data

Status
Not open for further replies.

harmmeijer

Programmer
Mar 1, 2001
869
CN
This seems to be a problem with some folders but I can't find out any differences between the folders.
I have 3 files: web.config test.aspx and test.htm, test.htm contains a form with 3 text fields and a file, this is submitted to test.aspx which will list the contents of the form submitted by test.htm.
When I put the 3 files in inetpub/scripts I loose all form values after submit, the output of test.aspx is:
files count is: 0
requestform count is: 0

The request headers allso indicate that there is no content:
CONTENT_LENGTH 0

When I put the files in another folder it does work, I get the file and the form values. This only seems to be on a server where .net runtime v1.1.4322 is installed.

Here are the 3 files:

test.htm
Code:
<form  name="frmDocument" id="frmDocument" enctype="multipart/form-data" method="post" onsubmit="doPost();" action="test.aspx">
<input type="file" name="myFile" id="myFile" />
<input type="text" value="this will be gone after submit" name="stupidName" id="stupidName" />
<input type="text" value="Xhtml has depreciated name but if I want to see any of this value in aspx (latest technology) I have to give this a name" name="sillyHa" id="sillyHa" />
<input type="text" name="uniqueURL" id="uniqueURL" />
<input type="submit" />
</form>
<script>
function doPost(){
	var dte = new Date();
	document.getElementById("uniqueURL").value = dte.getTime();
}
</script>

test.aspx
Code:
<%@ Page Language="vb" AutoEventWireup="true" %>
<script runat="server">
    Private Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs)
	dim i as int32 = 0
        Dim strDestPath As String = ""
        Dim sbResponse As New System.text.StringBuilder()
	sbResponse.append("files count is: ")
	sbResponse.append(Request.Files.count)
        Do While i < Request.Files.Count
            ' check if the file allready exsist in the destination directory
            Dim arrfileName() As String = Request.Files(i).FileName().Split("\")
            Dim strFilename As String = arrfileName(arrfileName.Length - 1)
            Dim arrfileExtention As String() = strFilename.Split(".")
            Dim strFileExtention As String = ""
            Dim strFileWithExtention As String = ""
            Dim intUniqueFile As Int16 = 0
            If arrfileExtention.Length > 1 Then
                strFileExtention = "." & arrfileExtention(arrfileExtention.Length - 1)
                ReDim Preserve arrfileExtention(arrfileExtention.Length - 2)
                strFilename = Join(arrfileExtention, ".")
                strFileWithExtention = strFilename & strFileExtention
            Else
                strFileExtention = ""
                strFileWithExtention = strFilename
            End If
            Dim strFilepath As String = strDestPath
            If strFileWithExtention = "" Then
                GoTo EndOfLoop
            End If
            ' generate the file inputs
            sbResponse.Append("<br>Filename: ")
            sbResponse.Append(strFilename)
            sbResponse.Append("<br>filepath: ")
            sbResponse.Append(strFilepath)
            sbResponse.Append("<br>fileExtention: ")
            sbResponse.Append(strFileExtention)
            sbResponse.Append("<br>filesize: ")
            sbResponse.Append(Request.Files(i).ContentLength)
EndOfLoop:
            i = i + 1
        Loop
        ' generate the rest of the inputs
	sbResponse.append("<br>requestform count is: ")
	sbResponse.append(Request.Form.count)
	sbResponse.append("<br>")
        i = 0
        While i < Request.Form.Count
            sbResponse.Append(Request.Form.Keys(i))
            sbResponse.Append(": ")
            sbResponse.Append(Request.Form.Item(i))
            sbResponse.Append("<BR>")
            sbResponse.Append(vbCrLf)
            i = i + 1
        End While
	' TODO: should do something with the request.querystring if any is there
        Response.Write(sbResponse.ToString)
    End Sub
</script>

web.config
Code:
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
  <system.web>
    <httpRuntime 
            maxRequestLength="65104"
    />
    <compilation defaultLanguage="vb" debug="true" />
    <customErrors mode="Off" />
	<identity impersonate="false" />
	<authentication mode="Windows" />
    <authorization>
        <allow users="*" />
    </authorization>
    <trace enabled="true" requestLimit="10" pageOutput="true" traceMode="SortByTime" localOnly="false" />
    <sessionState 
            mode="InProc"
            stateConnectionString="tcpip=127.0.0.1:42424"
            sqlConnectionString="data source=127.0.0.1;user id=sa;password="
            cookieless="false" 
            timeout="20" 
    />
    <globalization requestEncoding="utf-8" responseEncoding="utf-8" />
  </system.web>
</configuration>




Greetings, Harm Meijer
 
I'm interested to know why you're choosing this way as a solution...

As far as I know, the .NET framework was developed to use post backs, not form posting (like your solution above). Is there a reason that you're not dealing with the file uploading on the same page (or in the page's code-behind) as the form?



-----------------------------------------------
"The night sky over the planet Krikkit is the least interesting sight in the entire universe."
-Hitch Hiker's Guide To The Galaxy
 
Thank you for your response.

> I'm interested to know why you're choosing this way as a solution
Used to use cpshost.dll as an upload module for the asp/com+ apps. After some patch this didn't work anymore.

Asp and com+ don't have viewstate so using using input of type file runnig at server is not an option. Information is posted by asp/com+ applications and the upload module is just that, a module.

It is supposed to save the file in a location indicated with form value targetURL and then go to redirectURL with all the form values, file name(s),location(s),extention(s) and size so the redirectURL can finish the request.

Problem is that when test.htm submits its form to the uploader module the uploader module has a content lenth of 0 (= no form values, no file). This has been the case since maintanance has installed 2 MS kb fixes.



Greetings, Harm Meijer
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top