Please visit our sponsors !
HtmlInputFile Control
Definition and Usage
The HtmlInputFile control is used to control an <input type="file"> element. In HTML, this
element is used to upload a file to the server.
Properties
Property |
Description |
Accept |
List of acceptable MIME types |
id |
A unique id for the control |
MaxLength |
The maximum number of characters allowed in this element |
PostedFile |
Gets access to the posted file |
runat |
Specifies that the control is a server control. Must
be set to "server" |
Size |
The width of the element |
Example 1
In the following example we declare one HtmlInputFile
control, one HtmlInputButton
control, and three HtmlGeneric controls in an .aspx file (remember to embed the controls
inside an HtmlForm control). When the submit button is triggered, the submit subroutine is executed. The
file name and file type are displayed on the page, while the file itself is
uploaded to the c directory on the server:
<script runat="server">
Sub submit(Sender as Object, e as EventArgs)
fname.InnerHtml=MyFile.PostedFile.FileName
clength.InnerHtml=MyFile.PostedFile.ContentLength
MyFile.PostedFile.SaveAs("c:\uploadfile.txt")
End Sub
</script>
<html>
<body>
<form action="ex_htmlinputfile.aspx" method="post"
enctype="multipart/form-data" runat="server">
<p>
Select file to upload to server:
<input id="MyFile" type="file" size="40" runat="server">
</p>
<p>
<input type="submit" value="Upload!" OnServerclick="submit"
runat="server">
</p>
<p>
<div id="FileDetails" runat="server">
FileName: <span id="fname" runat="server"/><br />
ContentLength: <span id="clength" runat="server"/> bytes
</div>
</p>
</form>
</body>
</html>
|
Jump to: Top of Page
or HOME or
Printer friendly page
Search W3Schools:
What Others Say About Us
Does the world know about us? Check out these places:
Dogpile
Alta Vista
MSN
Google
Excite
Lycos
Yahoo
Ask Jeeves
We Help You For Free. You Can Help Us!
W3Schools is for training only. We do not warrant its correctness or its fitness for use.
The risk of using it remains entirely with the user. While using this site, you agree to have read and accepted our
terms of use and
privacy policy.
Copyright 1999-2002 by Refsnes Data. All Rights Reserved
|