Programmatic access to HtmlInputFile value it is a runat server

G

Guest

I have a System.Web.UI.HtmlControls.HtmlInputFile control that I use to
submit files. Before the file is successfully submitted I validate another
field on the form, it is the description of the file must be 500 characters.
I am adding the file to a site server library programmatically so if the
field is too long I want to return the user to the form with file still
selected in the HtmlInputFile control. I am using an error label to inform
the user to shorten the description. I do not want the user to have to
browse again to the same file after he has shortened the description. Right
now the file does not upload but the control is empty. ASP.NET does not let
me programmatically put the full filename and path back into the Value
property of the HtmlInputFile control. How can I do this? I have version
asp.net 1.1
If there is a better thread to post this in please tell me where. I have
searched on Google and cannot find anything. Can I “override†the value
property to add the set? Please help. Cindy
 
G

Guest

I found this but I don't know enough where to start
.............
these controls do not save their viewstate. LoadPostData always returns
false, and the Value property is readonly. You can inherit from the class and
override LoadPostData to return true and try to restore the value, but value
is readonly.

Example to inherit from HtmlInputFile class and override LoadPostData to
return true I am using C# and this is challenging me bad. cindy
 
M

msdn

This looks like a security issue here. you are not allowed to do this.
What happens if I pre-populate your email address book or some important
file on your machine and upload it.
Other options may be an activex, java, or .NET control. again they must be
trusted.

Sa
 
G

Guest

no not security violation I just want to reload original file so user does
not have to reselect to try upload again. I do not want to change readonly
of the value just the default behavior of LoadPostData to return false--
cindy
 
M

msdn

If you can populate the File-Path then what prevents somebody else from
putting what ever they want in it and upload any file from the client
machine.
The limitations on the HtmlInputFile are for security reasons and by design,

You should punish the user for not following the rules and ask them to
select the file again. I know this is a hassle but life if tuff.
If you find a solution please let us know.

Otherwise deal with it using ActiveX, Java Applet, or DotNet Compontents
that need security permissions anyway to run on the client side.

I like to see the hack.

Sa
 
M

msdn

One thought comes to mind,

Why not keep the file that has been uploaded already in a temporary place
and just get back from the user the shortened description.
Tell them you must shorten your description. After the description
satisfies the max length then you deal with the tempsaved file.

use a GUID or something to keep tack of the files and descriptions and
expire them also.

Sa
 
W

Walter Wang [MSFT]

Hi cindy,

Thank you for post.

The HtmlInputFile's content will be automatically cleared when the page is
posted. It's one of the controls that will not preserve values. And yes
it's due to security reason and by design.

Besides other community members' suggestions, I think you can check the
description field length in javascript before submitting the form, thus not
causing a postback.


Regards,
Walter Wang
Microsoft Online Community Support

==================================================
When responding to posts, please "Reply to Group" via your newsreader so
that others may learn and benefit from your issue.
==================================================

This posting is provided "AS IS" with no warranties, and confers no rights.
 

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,580
Members
45,055
Latest member
SlimSparkKetoACVReview

Latest Threads

Top