Uploading files using ASP.NET problem

D

darin dimitrov

Hello,

I have the following Html form:

<form name="submitForProcess"
action="http://localhost/xml/process.aspx" method="post"
enctype="multipart/form-data">

<input type="text" name="customerId" value="5" /><br />
<input type="text" name="customerName" value="Johnson" /><br />
<input type="file" name="customerPhoto"><br />

<input type="submit" value="OK" />

</form>


In the ASP.NET page which is supposed to process this request I can
get the uploaded file name, length and content using the Request.Files
collection. Using the Request.Form collection I can get the
"customerId" and "customerName" parameters with their values.

My problem is that I cannot get the name attribute of my input file
tag which in this case is "customerPhoto". The Request.Form collection
doesn't contain this parameter. I am desperate, please help me, is it
possible to get this value using .NET classes ?


Here is the the dialog between the client and the server:
---------------------------------------------------------------------------
POST /xml/process.aspx HTTP/1.1
Accept: image/gif, image/x-xbitmap, image/jpeg, image/pjpeg,
application/x-shockwave-flash, */*
Accept-Language: fr
Content-Type: multipart/form-data;
boundary=---------------------------7d4ea18310688
Accept-Encoding: gzip, deflate
User-Agent: Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.0; .NET
CLR 1.1.4322)
Host: localhost
Content-Length: 1067
Connection: Keep-Alive
Cache-Control: no-cache
Cookie: ASP.NET_SessionId=iwqfb3ju33u05cfx5jfajsys

-----------------------------7d4ea18310688
Content-Disposition: form-data; name="customerId"

5
-----------------------------7d4ea18310688
Content-Disposition: form-data; name="customerName"

Johnson
-----------------------------7d4ea18310688
Content-Disposition: form-data; name="customerPhoto";
filename="C:\Inetpub\wwwroot\xml\config.xml"
Content-Type: text/xml

<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<parameters>
<BizTalkListenLocationParameter>BizTalkListenLocation</BizTalkListenLocationParameter>
<MainNamespaceParameter>xmlns</MainNamespaceParameter>
</parameters>
<options>
<Debug>True</Debug>
</options>

<!--
Following are the network credential attributes for the
BizTalkListenerLocation application

If they are not explicitly set then the application
will use the currently connected user credentials.
-->

<credentials>
<Username></Username>
<Password></Password>
<Domain></Domain>
</credentials>

</configuration>
-----------------------------7d4ea18310688--
 
H

Hans Kesting

darin dimitrov said:
Hello,

I have the following Html form:

<form name="submitForProcess"
action="http://localhost/xml/process.aspx" method="post"
enctype="multipart/form-data">

<input type="text" name="customerId" value="5" /><br />
<input type="text" name="customerName" value="Johnson" /><br />
<input type="file" name="customerPhoto"><br />

<input type="submit" value="OK" />

</form>


In the ASP.NET page which is supposed to process this request I can
get the uploaded file name, length and content using the Request.Files
collection. Using the Request.Form collection I can get the
"customerId" and "customerName" parameters with their values.

My problem is that I cannot get the name attribute of my input file
tag which in this case is "customerPhoto". The Request.Form collection
doesn't contain this parameter. I am desperate, please help me, is it
possible to get this value using .NET classes ?

see the Request.Files collection

Hans Kesting
 
S

Steven Spits

Hi,
My problem is that I cannot get the name attribute of my
input file tag which in this case is "customerPhoto".

Put this in your codebehind:

protected System.Web.UI.HtmlControls.HtmlInputFile customerPhoto;

when the user uploads a file, you can use this to get the name:

customerPhoto.PostedFile.FileName

Beware: it will return the full name on the client computer. You should use
Path.GetFileName(customerPhoto.PostedFile.FileName) to extract only the
filename.

Steven

- - -
 
D

darin dimitrov

Hans Kesting said:
see the Request.Files collection

Hans Kesting



Thanks very much for your post Hans,

I used the Request.Files.GetKey method to obtain the name of the attribute
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,769
Messages
2,569,576
Members
45,054
Latest member
LucyCarper

Latest Threads

Top