<html>
<head>
<title>HtmlInputFile Control Example</title>
<link rel="stylesheet" href="/shared/netdemos.css">
<script language="C#" runat="server">
void uploadFile ( object src, EventArgs e ) {
if ( fileName.Value == "" ) {
details.InnerHtml = "<p>You must enter a file name</p>";
details.Visible = true;
return;
}
if ( fileToUpload.PostedFile != null ) {
try {
fileToUpload.PostedFile.SaveAs ( "c:\\temp\\"+fileName.Value );
string html = "<p>File uploaded successfully on the web server</p>";
html +="<p>FileName: c:\\temp\\" + fileName.Value + "<br>";
html +="ContentType: " + fileToUpload.PostedFile.ContentType + "<br>";
html +="ContentLength: " + fileToUpload.PostedFile.ContentLength + "</p>";
details.InnerHtml = html;
}
catch ( Exception exc ) {
details.InnerHtml = "Error saving file <b>c:\\temp\\" +
fileName.Value + "</b><br>" + exc.ToString ( );
}
finally {
details.Visible = true;
}
}
}
</script>
</head>
<body>
<!-- #include virtual="~/shared/top.inc -->
<div class="header"><h2><span class="hilite">HtmlInputFile Control</span> Example</h2></div>
<hr size=1 width=92%>
<div align="center">
<form enctype="multipart/form-data" runat="server">
<p>File to Upload:
<input id="fileToUpload" type=file runat="server"></p>
<p>Save as filename ( no path ) :
<input id="fileName" type=text runat="server"></p>
<p><input type=button runat="server" id="Button1"
value="Upload" onServerClick="uploadFile" ></p>
<p><div id="details" runat="server" visible=false
style="background:#def; border:1px inset" /></p>
</form>
</div>
<hr size=1 width=92%>
<!-- #include virtual="~/shared/viewsrc.inc" -->
</body>
</html>