如何在Asp.net中上传文件(任何类型的文件)
问题描述:
plz帮助我解决紧急情况.如何在asp.net中上传文件
plz help me its urgent..how to upload a file in asp.net
答
使用以下任何文章
http://www.codeproject.com/search.aspx?q=file+upload+asp.net&x=0&y=0&sbo=kw&usfc=false [
Use any of these articles
http://www.codeproject.com/search.aspx?q=file+upload+asp.net&x=0&y=0&sbo=kw&usfc=false[^]
尝试此模板
try this template
<pre lang="xml"><%@ Page Language="C#" %>
<script runat="server">
void SubmitButton_Click(Object sender, EventArgs e) {
if (File1.PostedFile != null) {
try {
File1.PostedFile.SaveAs("C:\\Uploads\\uploadedfile.txt");
Span1.InnerHtml = "Upload Successful!";
}
catch (Exception ex) {
Span1.InnerHtml = "Error saving file <b>C:\\" +
File1.Value + "</b><br>" + ex.ToString();
}
}
}
</script>
<html>
<head>
</head>
<body>
<form runat="server" enctype="multipart/form-data">
Select a file to upload:<br />
<input type="file" id="File1" runat="Server">
<p>
<input type="submit" id="Submit1" runat="Server"
value="Upload File" OnServerClick="SubmitButton_Click">
<p>
<span id="Span1" runat="Server" />
</form>
</body>
</html>