File1.PostedFile.SaveAs(uploadPath + fileName);未将对象引用设置到对象的实例
using System;using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Collections;
using System.Web.UI.HtmlControls;
namespace HtmlInputFile
{
public partial class Default : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
this.Button1.ServerClick+=new EventHandler(Button1_OnClick);
}
protected void Button1_OnClick(object sender, EventArgs e)
{
ArrayList arrayList = new ArrayList();
arrayList.AddRange(File1.Value.Split('\\'));
string fileName = arrayList[arrayList.Count - 1].ToString();
string uploadPath = Page.Request.PhysicalApplicationPath + "UpLoadFile\\";
try
{
File1.PostedFile.SaveAs(uploadPath + fileName);
Response.Write("文件上传成功!");
}
catch (Exception ex)
{
Response.Write(ex.Message);
}
}
}
} --------------------编程问答-------------------- <form id="form1" runat="server" method="post" enctype="multipart/form-data">
--------------------编程问答-------------------- 另外,FileUpload控件就是很方便的啊 --------------------编程问答-------------------- 参考
补充:.NET技术 , ASP.NET