Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Set the value to the Input type='file' in code behind
Message
 
 
To
All
General information
Forum:
ASP.NET
Category:
Coding, syntax and commands
Title:
Set the value to the Input type='file' in code behind
Miscellaneous
Thread ID:
01685421
Message ID:
01685421
Views:
38
Hi,

Simplified.
The page has the following code:
<input type="file" name="file" id="file" />
A user selects a file using the input control (above).

The page is posted back to the server. Maybe to check a value in another field. Or for whatever other reason.

In the code behind, the code gets the value of the chosen/selected file, as follows:
 foreach (string file in Request.Files)
                {
                    HttpPostedFile hpf = Request.Files[file] as HttpPostedFile;
                    if (hpf.ContentLength == 0)
                        continue;
                    // This is the file name user selected.
                    string cFileName = System.IO.Path.GetFileName(hpf.FileName);
                }
And I would like the value cFileName to be set to the input control. Otherwise, the input control becomes empty, after post back.

I can't figure out how to set the value in the Input control type='file' to this file name. Anyone can help?

TIA
"The creative process is nothing but a series of crises." Isaac Bashevis Singer
"My experience is that as soon as people are old enough to know better, they don't know anything at all." Oscar Wilde
"If a nation values anything more than freedom, it will lose its freedom; and the irony of it is that if it is comfort or money that it values more, it will lose that too." W.Somerset Maugham
Reply
Map
View

Click here to load this message in the networking platform