With ASP.NET upload a file on the server is very easy.With FileUpload control we can easily upload a file on the server.Following markup is required.
<form id="form1" runat="server"> <asp:FileUpload id="FileUploadControl" runat="server" /> <asp:Button runat="server" id="btnupload" text="Upload" onclick="btnupload _Click" /> <asp:Label runat="server" id="lblstatus" /> </form>
Here is the CodeBehind code required to handle upload a file on the server.
protected void btnupload_Click(object sender, EventArgs e) { if(FileUploadControl.HasFile) { try { string filename = Path.GetFileName(FileUploadControl.FileName); FileUploadControl.SaveAs(Server.MapPath("~/") + filename); lblstatus.Text = "Upload status: File uploaded!"; } catch(Exception ex) { lblstatus.Text = "The file could not be uploaded." + ex.Message; } } }
Through this you can easily upload a file on the server.
Happy Programming..:)
Comments
Post a Comment