By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
443,750 Members | 1,367 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 443,750 IT Pros & Developers. It's quick & easy.

HtmlInputFile to get filename only without upload

P: n/a
Can I use HtmlInputFile to only get the selected file name but not actually
upload the file?

Clicking the control's Browse button let's the user select a file. All I
need is the HtmlInputFile Value property. However, any button clicked on the
Html page results in uploading the selected file. Is there a way to avoid
the actual uploading?

Alternatively, is there any other way to let a user select a file name from
his local disk?

Thanks,
Ariel
--
==================================================
Ariel Dolan
ar******@netvision.net.il

Artificial Life and other Experiments
http://www.aridolan.com
http://www.arieldolan.com
==================================================
Nov 18 '05 #1
Share this Question
Share on Google+
5 Replies


P: n/a
Never tried this but if you use the usual enctype instead
multipart/form-data, I believe the file will not be uploaded....

Another option would be to copy the file name into an hidden textbox and to
prevent posting of this particular field (by clearing this node for a
radical solution to just clearing the name attribute or disabling the
control).

Let us know.

Patrice

--

"Ariel Dolan" <ar******@netvision.net.il> a écrit dans le message de
news:%2****************@tk2msftngp13.phx.gbl...
Can I use HtmlInputFile to only get the selected file name but not actually upload the file?

Clicking the control's Browse button let's the user select a file. All I
need is the HtmlInputFile Value property. However, any button clicked on the Html page results in uploading the selected file. Is there a way to avoid
the actual uploading?

Alternatively, is there any other way to let a user select a file name from his local disk?

Thanks,
Ariel
--
==================================================
Ariel Dolan
ar******@netvision.net.il

Artificial Life and other Experiments
http://www.aridolan.com
http://www.arieldolan.com
==================================================


Nov 18 '05 #2

P: n/a
Thank you for your answer.

I removed the enctype attribute but it did not help. The file is still uploaded.

Can you explain the second option you suggested. How do I prevent the HtmlInputFile control from uploading the file? The file name is displayed in the control's text box, but as soon as I activate any button, the file gets uploaded. I can copy the file name to a textbox, but this can be carried out only after uploading is complete. The uploading seems to be activated before any action initiated by the code.

Thanks again,
Ariel
--
================================================== =============
Ariel Dolan
ar******@netvision.net.il

Artificial Life and other Experiments
http://www.aridolan.com
http://www.arieldolan.com
================================================== =============
"Patrice Scribe" <no****@nowhere.com> wrote in message news:u2*************@TK2MSFTNGP10.phx.gbl...
Never tried this but if you use the usual enctype instead
multipart/form-data, I believe the file will not be uploaded....

Another option would be to copy the file name into an hidden textbox and to
prevent posting of this particular field (by clearing this node for a
radical solution to just clearing the name attribute or disabling the
control).

Let us know.

Patrice

--

"Ariel Dolan" <ar******@netvision.net.il> a écrit dans le message de
news:%2****************@tk2msftngp13.phx.gbl...
Can I use HtmlInputFile to only get the selected file name but not actually upload the file?

Clicking the control's Browse button let's the user select a file. All I
need is the HtmlInputFile Value property. However, any button clicked on the Html page results in uploading the selected file. Is there a way to avoid
the actual uploading?

Alternatively, is there any other way to let a user select a file name from his local disk?

Thanks,
Ariel
--
==================================================
Ariel Dolan
ar******@netvision.net.il

Artificial Life and other Experiments
http://www.aridolan.com
http://www.arieldolan.com
==================================================

Nov 18 '05 #3

P: n/a
My first thought would be :
- don't include the "name" attribute. Controls without the name attribute
shouldn't post their values. This way the file shoudn't be uploaded either.
- on the onsubmit event, copy the value of the htmlInputFile to an hidden
text box so that the name is still posted...

In the worst case you could try also to use this event to clear totally the
input type=file tag from the HTML form so that it is not posted (it should
hopefully really prevent the file from being uploaded)...

Hope it helps....

Actually I finally made quick client side test using ASP. My web browser is
IE 6:
- with the default enctype, the file is NOT posted (make sure you don't have
a browser cache problem or whatever).

If I'm using enctype="multipart/form-data" the file is posted.

I can still avoid to send its content by not using the name attribute on the
input type=file tag. My final code is (ASP). Note though that the file part
file is still here (Request.Files.count will still return a file) but there
is no content in beetween (no content sent, you'll seee an empty file server
side).

The final HTML code is (you may want to test other browsers) :

<%@ Language=VBScript %>
<HTML>
<HEAD>
<META NAME="GENERATOR" Content="Microsoft Visual Studio 6.0">
</HEAD>
<BODY>
<%
Response.BinaryWrite Request.BinaryRead(Request.TotalBytes)
%>
<FORM action="tst.asp" method="post"
onSubmit="hiddenfilename.value=filename.value"
enctype="multipart/form-data">
<INPUT type="file" id="filename">
<INPUT type="textbox" id="hiddenfilename" name="hiddenfilename">
<INPUT Type="submit">
</FORM>
</BODY>
</HTML>

--

"Ariel Dolan" <ar******@netvision.net.il> a écrit dans le message de
news:c1**********@news2.netvision.net.il...
Thank you for your answer.

I removed the enctype attribute but it did not help. The file is still uploaded.
Can you explain the second option you suggested. How do I prevent the HtmlInputFile control from uploading the file? The file name is displayed in
the control's text box, but as soon as I activate any button, the file gets
uploaded. I can copy the file name to a textbox, but this can be carried out
only after uploading is complete. The uploading seems to be activated before
any action initiated by the code.
Thanks again,
Ariel
--
================================================== =============
Ariel Dolan
ar******@netvision.net.il

Artificial Life and other Experiments
http://www.aridolan.com
http://www.arieldolan.com
================================================== =============
"Patrice Scribe" <no****@nowhere.com> wrote in message news:u2*************@TK2MSFTNGP10.phx.gbl... Never tried this but if you use the usual enctype instead
multipart/form-data, I believe the file will not be uploaded....

Another option would be to copy the file name into an hidden textbox and to prevent posting of this particular field (by clearing this node for a
radical solution to just clearing the name attribute or disabling the
control).

Let us know.

Patrice

--

"Ariel Dolan" <ar******@netvision.net.il> a écrit dans le message de
news:%2****************@tk2msftngp13.phx.gbl...
Can I use HtmlInputFile to only get the selected file name but not

actually
upload the file?

Clicking the control's Browse button let's the user select a file. All I
need is the HtmlInputFile Value property. However, any button clicked on

the
Html page results in uploading the selected file. Is there a way to avoid the actual uploading?

Alternatively, is there any other way to let a user select a file name

from
his local disk?

Thanks,
Ariel
--
==================================================
Ariel Dolan
ar******@netvision.net.il

Artificial Life and other Experiments
http://www.aridolan.com
http://www.arieldolan.com
==================================================



Nov 18 '05 #4

P: n/a
I now see why are experiences differ. I use the server side control
(type="file" runat="server" i.e. HtmlInputFile) while you use the Html
control. It is true that the Html control does not upload the file when it
does not have a name attribute or when the enctype is set to default. The
server side control, however, always uploads the file before anything else.

My form is server side and contains several web controls. Can I place in
this form a plain Html control of type="file" and still get the control
value into server code?

Thanks,
Ariel
--
================================================== =============
Ariel Dolan
ar******@netvision.net.il

Artificial Life and other Experiments
http://www.aridolan.com
http://www.arieldolan.com
================================================== =============
"Patrice Scribe" <no****@nowhere.com> wrote in message
news:%2******************@TK2MSFTNGP11.phx.gbl...
My first thought would be :
- don't include the "name" attribute. Controls without the name attribute
shouldn't post their values. This way the file shoudn't be uploaded either. - on the onsubmit event, copy the value of the htmlInputFile to an hidden
text box so that the name is still posted...

In the worst case you could try also to use this event to clear totally the input type=file tag from the HTML form so that it is not posted (it should
hopefully really prevent the file from being uploaded)...

Hope it helps....

Actually I finally made quick client side test using ASP. My web browser is IE 6:
- with the default enctype, the file is NOT posted (make sure you don't have a browser cache problem or whatever).

If I'm using enctype="multipart/form-data" the file is posted.

I can still avoid to send its content by not using the name attribute on the input type=file tag. My final code is (ASP). Note though that the file part file is still here (Request.Files.count will still return a file) but there is no content in beetween (no content sent, you'll seee an empty file server side).

The final HTML code is (you may want to test other browsers) :

<%@ Language=VBScript %>
<HTML>
<HEAD>
<META NAME="GENERATOR" Content="Microsoft Visual Studio 6.0">
</HEAD>
<BODY>
<%
Response.BinaryWrite Request.BinaryRead(Request.TotalBytes)
%>
<FORM action="tst.asp" method="post"
onSubmit="hiddenfilename.value=filename.value"
enctype="multipart/form-data">
<INPUT type="file" id="filename">
<INPUT type="textbox" id="hiddenfilename" name="hiddenfilename">
<INPUT Type="submit">
</FORM>
</BODY>
</HTML>

--

"Ariel Dolan" <ar******@netvision.net.il> a écrit dans le message de
news:c1**********@news2.netvision.net.il...
Thank you for your answer.

I removed the enctype attribute but it did not help. The file is still uploaded.

Can you explain the second option you suggested. How do I prevent the

HtmlInputFile control from uploading the file? The file name is displayed

in the control's text box, but as soon as I activate any button, the file gets uploaded. I can copy the file name to a textbox, but this can be carried out only after uploading is complete. The uploading seems to be activated before any action initiated by the code.

Thanks again,
Ariel
--
================================================== =============
Ariel Dolan
ar******@netvision.net.il

Artificial Life and other Experiments
http://www.aridolan.com
http://www.arieldolan.com
================================================== =============
"Patrice Scribe" <no****@nowhere.com> wrote in message

news:u2*************@TK2MSFTNGP10.phx.gbl...
Never tried this but if you use the usual enctype instead
multipart/form-data, I believe the file will not be uploaded....

Another option would be to copy the file name into an hidden textbox and

to
prevent posting of this particular field (by clearing this node for a
radical solution to just clearing the name attribute or disabling the
control).

Let us know.

Patrice

--

"Ariel Dolan" <ar******@netvision.net.il> a écrit dans le message de
news:%2****************@tk2msftngp13.phx.gbl...
Can I use HtmlInputFile to only get the selected file name but not

actually
upload the file?

Clicking the control's Browse button let's the user select a file. All I need is the HtmlInputFile Value property. However, any button clicked
on
the
Html page results in uploading the selected file. Is there a way to

avoid the actual uploading?

Alternatively, is there any other way to let a user select a file name

from
his local disk?

Thanks,
Ariel
--
==================================================
Ariel Dolan
ar******@netvision.net.il

Artificial Life and other Experiments
http://www.aridolan.com
http://www.arieldolan.com
==================================================


Nov 18 '05 #5

P: n/a
A "server control" is just a way to be able to easily control HTML
generation. Does it creates the appropriate HTML code client side ?

If the server control prevents generating the proper HTML code, you could
anyway use just literal text for this input type="file" tag as it is to
ignore anyway server side (you'll get the filename through an hidden
textbox).

Patrice

--

"Ariel Dolan" <ar******@netvision.net.il> a écrit dans le message de
news:c1**********@news2.netvision.net.il...
I now see why are experiences differ. I use the server side control
(type="file" runat="server" i.e. HtmlInputFile) while you use the Html
control. It is true that the Html control does not upload the file when it
does not have a name attribute or when the enctype is set to default. The
server side control, however, always uploads the file before anything else.
My form is server side and contains several web controls. Can I place in
this form a plain Html control of type="file" and still get the control
value into server code?

Thanks,
Ariel
--
================================================== =============
Ariel Dolan
ar******@netvision.net.il

Artificial Life and other Experiments
http://www.aridolan.com
http://www.arieldolan.com
================================================== =============
"Patrice Scribe" <no****@nowhere.com> wrote in message
news:%2******************@TK2MSFTNGP11.phx.gbl...
My first thought would be :
- don't include the "name" attribute. Controls without the name attribute
shouldn't post their values. This way the file shoudn't be uploaded either.
- on the onsubmit event, copy the value of the htmlInputFile to an hidden text box so that the name is still posted...

In the worst case you could try also to use this event to clear totally

the
input type=file tag from the HTML form so that it is not posted (it should hopefully really prevent the file from being uploaded)...

Hope it helps....

Actually I finally made quick client side test using ASP. My web browser

is
IE 6:
- with the default enctype, the file is NOT posted (make sure you don't

have
a browser cache problem or whatever).

If I'm using enctype="multipart/form-data" the file is posted.

I can still avoid to send its content by not using the name attribute on

the
input type=file tag. My final code is (ASP). Note though that the file

part
file is still here (Request.Files.count will still return a file) but

there
is no content in beetween (no content sent, you'll seee an empty file

server
side).

The final HTML code is (you may want to test other browsers) :

<%@ Language=VBScript %>
<HTML>
<HEAD>
<META NAME="GENERATOR" Content="Microsoft Visual Studio 6.0">
</HEAD>
<BODY>
<%
Response.BinaryWrite Request.BinaryRead(Request.TotalBytes)
%>
<FORM action="tst.asp" method="post"
onSubmit="hiddenfilename.value=filename.value"
enctype="multipart/form-data">
<INPUT type="file" id="filename">
<INPUT type="textbox" id="hiddenfilename" name="hiddenfilename">
<INPUT Type="submit">
</FORM>
</BODY>
</HTML>

--

"Ariel Dolan" <ar******@netvision.net.il> a écrit dans le message de
news:c1**********@news2.netvision.net.il...
Thank you for your answer.

I removed the enctype attribute but it did not help. The file is still

uploaded.

Can you explain the second option you suggested. How do I prevent the

HtmlInputFile control from uploading the file? The file name is displayed in
the control's text box, but as soon as I activate any button, the file gets
uploaded. I can copy the file name to a textbox, but this can be carried

out
only after uploading is complete. The uploading seems to be activated

before
any action initiated by the code.

Thanks again,
Ariel
--
================================================== =============
Ariel Dolan
ar******@netvision.net.il

Artificial Life and other Experiments
http://www.aridolan.com
http://www.arieldolan.com
================================================== =============
"Patrice Scribe" <no****@nowhere.com> wrote in message

news:u2*************@TK2MSFTNGP10.phx.gbl...
Never tried this but if you use the usual enctype instead
multipart/form-data, I believe the file will not be uploaded....

Another option would be to copy the file name into an hidden textbox and to
prevent posting of this particular field (by clearing this node for a
radical solution to just clearing the name attribute or disabling the
control).

Let us know.

Patrice

--

"Ariel Dolan" <ar******@netvision.net.il> a écrit dans le message de
news:%2****************@tk2msftngp13.phx.gbl...
> Can I use HtmlInputFile to only get the selected file name but not
actually
> upload the file?
>
> Clicking the control's Browse button let's the user select a file.

All I > need is the HtmlInputFile Value property. However, any button
clicked
on the
> Html page results in uploading the selected file. Is there a way to

avoid
> the actual uploading?
>
> Alternatively, is there any other way to let a user select a file

name from
> his local disk?
>
> Thanks,
> Ariel
> --
> ==================================================
> Ariel Dolan
> ar******@netvision.net.il
>
> Artificial Life and other Experiments
> http://www.aridolan.com
> http://www.arieldolan.com
> ==================================================
>
>



Nov 18 '05 #6

This discussion thread is closed

Replies have been disabled for this discussion.