asp.net网站的FileUpload方法

时间:2012-02-21 15:44:15

标签: c# asp.net

net,我只是想知道是否有方法 文件上传标签在任何地方的库中?

谢谢大家继承我的代码

<asp:FileUpload ID="FileUpload1" runat="server" ForeColor="white" />

1 个答案:

答案 0 :(得分:1)

您并将一个上传按钮和该按钮的点击事件写入如下代码将执行您的任务

Aspx页码

 <asp:FileUpload ID="fpManualCostActual" runat="server" />

   <asp:LinkButton ID="btnUpload" runat="server" OnClick="btnUpload_Click" 
              Upload</asp:LinkButton>

Cs文件代码

protected void btnUpload_Click(object sender, EventArgs e)
{
    try
    {
        if (fpManualCostActual.HasFile)
        {

                string filePath = Server.MapPath("~/Upload/" + 
                       SessionManager.UID.ToString() + "/MonthlyActual" + 
                       DateTime.Now.ToString("MMddyyyyHHmmss") + fileExt);
                fpManualCostActual.SaveAs(filePath);

        }
     }
    catch (Exception ex)
    {
        CustomException(ex, CommonHelper.ExceptionType.DBExceptionPolicy);
    }
}