Latest web development tutorials

Kontrol ASP.NET HtmlInputFile

HTML Server Controls server kontrol HTML

Definisi dan Penggunaan

kontrol HtmlInputFile untuk mengendalikan <input type = "file"> elemen, yang digunakan untuk meng-upload file ke server.


milik

属性 描述
Accept 可接受的 MIME 类型的列表。
Attributes 返回该元素的所有属性名称和值对。
Disabled 布尔值,指示是否禁用该控件。默认是 false。
id 元素的唯一 id。
MaxLength 该元素中所允许的最大字符数。
Name 元素的名称。
PostedFile 获取对由客户端指定的上载文件的访问。
runat 规定该控件是一个服务器控件。必须被设置为 "server"。
Size 元素的宽度。
Style 设置或返回被应用到控件的 CSS 属性。
TagName 返回元素的标签名。
Type 元素的类型。
Value 元素的值。
Visible 布尔值,指示该控件是否可见。


contoh

Dalam contoh ini, kita mendeklarasikan kontrol HtmlInputFile di file .aspx, kontrol HtmlInputButton, serta tiga kontrol HtmlGeneric (ingat untuk mengontrol kendali HtmlForm bersarang). Ketika tombol submit dipicu, mengirimkan subroutine. Ketika file diupload ke server itu sendiri c direktori, halaman akan menampilkan nama file dan jenis file:

<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 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 runat="server">
FileName: <span id="fname" runat="server"/><br />
ContentLength: <span id="clength" runat="server"/> bytes
</div>
</p>
</form>

</body>
</html>


HTML Server Controls server kontrol HTML