HtmlInputFile.Size-Eigenschaft
Ruft die Breite des Textfelds ab, in das der Dateipfad eingegeben wird, oder legt diese fest.
Namespace: System.Web.UI.HtmlControls
Assembly: System.Web (in system.web.dll)
Syntax
'Declaration
Public Property Size As Integer
'Usage
Dim instance As HtmlInputFile
Dim value As Integer
value = instance.Size
instance.Size = value
public int Size { get; set; }
public:
property int Size {
int get ();
void set (int value);
}
/** @property */
public int get_Size ()
/** @property */
public void set_Size (int value)
public function get Size () : int
public function set Size (value : int)
Eigenschaftenwert
Die Breite des Textfelds für den Dateipfad. Der Standardwert ist -1 und gibt an, dass die Eigenschaft nicht festgelegt wurde.
Hinweise
Geben Sie mit dieser Eigenschaft die Breite des Textfelds an, in das der Dateipfad eingegeben werden soll.
Beispiel
Im folgenden Codebeispiel wird veranschaulicht, wie mithilfe der Size-Eigenschaft die Breite des Textfelds angegeben wird, in das der Benutzer den Dateipfad eingibt. Damit dieses Beispiel ordnungsgemäß ausgeführt werden kann, müssen Sie auf dem Laufwerk C des Computers ein Verzeichnis mit der Bezeichnung Temp
erstellen.
<%@ Page Language="VB" AutoEventWireup="True" %>
<script runat="server">
Sub Button1_Click(ByVal Source As Object, ByVal e As EventArgs)
' Make sure a file was submitted.
If Text1.Value = "" Then
Span1.InnerHtml = "Error: You must enter a file name."
Return
End If
' Save the file.
If Not (File1.PostedFile Is Nothing) Then
Try
File1.PostedFile.SaveAs(("c:\temp\" & Text1.Value))
Span1.InnerHtml = "File uploaded successfully to <b>c:\temp\" & _
Text1.Value & "</b> on the Web server."
Catch exc As Exception
Span1.InnerHtml = "Error saving file <b>c:\temp\" & _
Text1.Value & "</b><br>" & exc.ToString() & "."
End Try
End If
End Sub
</script>
<html>
<head>
<title>HtmlInputFile Example</title>
</head>
<body>
<h3>HtmlInputFile Example</h3>
<form enctype="multipart/form-data"
runat="server">
Select File to Upload:
<input id="File1"
type="file"
size="15"
runat="server"/>
<p>
Save as file name (no path):
<input id="Text1"
type="text"
runat="server"/>
</p>
<p>
<span id=Span1
style="font: 8pt verdana;"
runat="server" />
</p>
<p>
<input type=button
id="Button1"
value="Upload"
onserverclick="Button1_Click"
runat="server">
</p>
</form>
</body>
</html>
<%@ Page Language="C#" AutoEventWireup="True" %>
<script runat="server">
void Button1_Click(object Source, EventArgs e)
{
// Make sure a file was submitted.
if (Text1.Value == "")
{
Span1.InnerHtml = "Error: You must enter a file name.";
return;
}
// Save the file.
if (File1.PostedFile != null)
{
try
{
File1.PostedFile.SaveAs("c:\\temp\\" + Text1.Value);
Span1.InnerHtml = "File uploaded successfully to <b>c:\\temp\\" +
Text1.Value + "</b> on the Web server.";
}
catch (Exception exc)
{
Span1.InnerHtml = "Error saving file <b>c:\\temp\\" +
Text1.Value + "</b><br>" + exc.ToString() + ".";
}
}
}
</script>
<html>
<head>
<title>HtmlInputFile Example</title>
</head>
<body>
<h3>HtmlInputFile Example</h3>
<form enctype="multipart/form-data"
runat="server">
Select File to Upload:
<input id="File1"
type="file"
size="15"
runat="server" />
<p>
Save as file name (no path):
<input id="Text1"
type="text"
runat="server"/>
</p>
<p>
<span id=Span1
style="font: 8pt verdana;"
runat="server" />
</p>
<p>
<input type=button
id="Button1"
value="Upload"
onserverclick="Button1_Click"
runat="server">
</p>
</form>
</body>
</html>
<%@ Page Language="JScript" AutoEventWireup="True" %>
<script runat="server">
function Button1_Click(source : Object, e : EventArgs){
// Make sure a file was submitted.
if(Text1.Value == "")
{
Span1.InnerHtml = "Error: You must enter a file name."
return
}
// Save the file.
if(File1.PostedFile != null)
{
try
{
File1.PostedFile.SaveAs(("c:\\temp\\" + Text1.Value))
Span1.InnerHtml = "File uploaded successfully to <b>c:\\temp\\"
+ Text1.Value + "</b> on the Web server."
}
catch(exc : Exception)
{
Span1.InnerHtml = "Error saving file <b>c:\\temp\\"
+ Text1.Value + "</b><br>" + exc.ToString() + "."
}
}
}
</script>
<html>
<head>
<title>HtmlInputFile Example</title>
</head>
<body>
<h3>HtmlInputFile Example</h3>
<form enctype="multipart/form-data"
runat="server">
Select File to Upload:
<input id="File1"
type="file"
size="15"
runat="server"/>
<p>
Save as file name (no path):
<input id="Text1"
type="text"
runat="server"/>
</p>
<p>
<span id=Span1
style="font: 8pt verdana;"
runat="server" />
</p>
<p>
<input type=button
id="Button1"
value="Upload"
onserverclick="Button1_Click"
runat="server">
</p>
</form>
</body>
</html>
Plattformen
Windows 98, Windows 2000 SP4, Windows Server 2003, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP SP2, Windows XP Starter Edition
.NET Framework unterstützt nicht alle Versionen sämtlicher Plattformen. Eine Liste der unterstützten Versionen finden Sie unter Systemanforderungen.
Versionsinformationen
.NET Framework
Unterstützt in: 2.0, 1.1, 1.0
Siehe auch
Referenz
HtmlInputFile-Klasse
HtmlInputFile-Member
System.Web.UI.HtmlControls-Namespace