ASP.NET
示例
第一个示例演示如何创建 FileUpload 控件,该控件将文件保存到代码中指定的路径。
<%@ Page Language="C#" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<script runat="server">
protected void UploadButton_Click(object sender, EventArgs e)
{
// Specify the path on the server to
// save the uploaded file to.
String savePath = @"c:\temp\uploads\";
// Before attempting to perform operations
// on the file, verify that the FileUpload
// control contains a file.
if (FileUpload1.HasFile)
{
// Get the name of the file to upload.
String fileName = FileUpload1.FileName;
// Append the name of the file to upload to the path.
savePath += fileName;
// Call the SaveAs method to save the
// uploaded file to the specified path.
// This example does not perform all
// the necessary error checking.
// If a file with the same name
// already exists in the specified path,
// the uploaded file overwrites it.
FileUpload1.SaveAs(savePath);
// Notify the user of the name of the file
// was saved under.
UploadStatusLabel.Text = "Your file was saved as " + fileName;
}
相关文档:
<%=%>绑定CS文件中的变量,有值的属性,或者有返回值的方法,
<%#%>一般式放在数据控件中绑定数据源表中的字段
<%=%><%#%>区别:
前者 是在页面之中使用.属于一段代码.有=号的就相当于response.write()这功能.和asp一样.
后者 是在页面中的服务器数据控件中绑定数据源的字段 ......
这段时间一直在做一个的项目,先前build项目时,一直是正常的,没有任何问题。昨天,在将完成的部分文件签入服务器后,重新生成解决方案
时,build失败,总是提示不允许循环文件引用,和用户控件相关的一些错误--未知服务器标记。接着再生成解决方案,还是失败,但是多生几次之后,尽然
又生成成功了,问题很是怪异。由于 ......
OnClientClick="this.disabled=true;this.form.submit();" UseSubmitBehavior="False"在按钮属性中加入这段代码
this.btnSubmit.Attributes["onclick"] = this.GetPostBackEventReference(this.btnSubmit) + ";this.disabled=true;";
如果是提交是一个Button,可以使用javascript,设置为en ......
使用 FileUpload 控件,可以为用户提供一种将文件从其计算机发送到服务器的方法。
一、功能
可使用 FileUpload 控件执行下列操作:
·使用户能够上载存储在服务器上的特定位置的文件。
·限制可上载的文件的大小。
·在存储上载的文件之前检查其属性。
二 ......