在网上找了半天做文件上传的,都是VB版的,没有找到C#的,就用C#翻译了一下!
还是用,<INPUT TYPE=FILE RUNAT=SERVER>做的.
下面是aspx文件代码:
<form id="Form1" method="post" runat="server">
<INPUT id="UpFiles" runat="server" type="file">
<asp:Button id="upFileBtn" runat="server" Text="UpDate"></asp:Button><BR>
<BR>
<asp:Label id="Label1" runat="server" Width="288px" Height="144px">Label</asp:Label>
</form>
<INPUT id="UpFiles" runat="server" type="file">
<asp:Button id="upFileBtn" runat="server" Text="UpDate"></asp:Button><BR>
<BR>
<asp:Label id="Label1" runat="server" Width="288px" Height="144px">Label</asp:Label>
</form>
aspx.cs CODE:
private void upFileBtn_Click(object sender, System.EventArgs e)
{
if(this.UpFiles.PostedFile.ContentLength==0)
Label1.Text="上传文件不成功或者发生错误";
else
{
//获取上传文件名
string temp=this.UpFiles.PostedFile.FileName;
int intT=temp.LastIndexOf("\\");
temp=temp.Substring(intT+1);
//保存文件
this.UpFiles.PostedFile.SaveAs(Server.MapPath(".")+"\\Files\\"+temp);
Label1.Text="文件上传成功!上传文件名"+temp;
}
}
{
if(this.UpFiles.PostedFile.ContentLength==0)
Label1.Text="上传文件不成功或者发生错误";
else
{
//获取上传文件名
string temp=this.UpFiles.PostedFile.FileName;
int intT=temp.LastIndexOf("\\");
temp=temp.Substring(intT+1);
//保存文件
this.UpFiles.PostedFile.SaveAs(Server.MapPath(".")+"\\Files\\"+temp);
Label1.Text="文件上传成功!上传文件名"+temp;
}
}