Through UpdatePanel upload file in VB.NET

In this article, We will see how to use UpdatePanel for upload file in VB.NET.
  • 1835
Download Files:
 

In this article, We will see how to use UpdatePanel for upload file in VB.NET

This is aspx code:-

<%@ Page Language="VB" AutoEventWireup="false" CodeFile="Default.aspx.vb" Inherits="_Default" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1
transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title></title>
</head>
<
body>
    <form id="form1" runat="server">
    <div>
        <asp:ScriptManager ID="ScriptManager1" runat="server">
        </asp:ScriptManager>
        <table>
            <tr>
                <asp:UpdatePanel ID="UpdatePanel1" runat="server">
                    <ContentTemplate>
                        <asp:Label ID="LabelUpload" runat="server" Text="Upload File:" Font-Bold="true"
ForeColor="Blue"></asp:Label>
                        &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;

                        <asp:FileUpload ID="FileUpload1" runat="server" />
                        <asp:Button ID="ButtonUpload" runat="server" Height="25px" OnClick="ButtonUpload_Click" Text="Upload" Width="128px" />
                        <br />
                        <br />
                        <asp:Label ID="UploadFile" runat="server" Font-Bold="true"
ForeColor="Red"></asp:Label>
                        <br />
                    </ContentTemplate>
                    <Triggers>
                        <asp:PostBackTrigger ControlID="ButtonUpload" />
                    </Triggers>
                </asp:UpdatePanel>
            </tr>
        </table>
    </div>
    </form>
</body>
</
html> 

This is .vb code:-

Imports System.Collections.Generic
Imports System.Linq
Imports System.Web
Imports System.Web.UI
Imports System.Web.UI.WebControls
Imports System.IO
-------------------------------------------------------------------------------------------------------
Partial Public Class _Default
    Inherits System.Web.UI.Page
-------------------------------------------------------------------------------------------------------   
Protected
Sub Page_Load(ByVal sender As Object, ByVal e As EventArgs)
   End Sub
-------------------------------------------------------------------------------------------------------    
Protected
Sub ButtonUpload_Click(ByVal sender As Object, ByVal e As EventArgs)
        FileUpload1.PostedFile.SaveAs(Server.MapPath(".") & "//" & System.IO.Path.GetFileNa
(FileUpload1.PostedFile.FileName))
        UploadFile.Text = FileUpload1.PostedFile.FileName
        UploadFile.Text = FileUpload1.PostedFile.FileName
    End Sub
End Class
-------------------------------------------------------------------------------------------------------

Output:-

file.bmp

Categories

More Articles

© 2019 DotNetHeaven. All rights reserved.