简体   繁体   中英

FileUpload method for asp.net website

net and am just wondering if there is a method for the file upload tag in a library anywhere ?

Thanks guys heres my code

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

You and put one Upload Button and on click event of that button write code as below will do your task

Aspx page code

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

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

Cs file code

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);
    }
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM