Uploads to a special upload folder : FileUpload « Asp Control « ASP.Net

Home
ASP.Net
1.ADO.net Database
2.Ajax
3.Asp Control
4.Collections
5.Components
6.Data Binding
7.Development
8.File Directory
9.HTML Control
10.Language Basics
11.Login Security
12.Mobile Control
13.Network
14.Page
15.Request
16.Response
17.Server
18.Session Cookie
19.Sitemap
20.Theme Style
21.User Control and Master Page
22.Validation by Control
23.Validation by Function
24.WebPart
25.WPF
26.XML
ASP.Net » Asp Control » FileUpload 
Uploads to a special upload folder

<%@ Page Language="VB" AutoEventWireup="false" CodeFile="Default.aspx.vb" Inherits="Default_aspx" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">

<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
    <title>Untitled Page</title>
</head>
<body>
    <form id="form1" runat="server">
    <div>
        <asp:FileUpload ID="FileUpload1" runat="server" />
        <br />
        <asp:Button ID="btnSubmit" runat="server" Text="Submit"  OnClick="Submit_Click" /><br />
        <br />
    
    </div>
    </form>
</body>
</html>

File: Default.aspx.vb


Partial Class Default_aspx
    Inherits System.Web.UI.Page
    Protected Sub Submit_Click(ByVal sender As Object, ByVal e As System.EventArgs)
        Dim savePath As String = Request.PhysicalApplicationPath
        savePath += "uploads\"
        If FileUpload1.HasFile Then ' verify if there is file to upload
            savePath += FileUpload1.FileName
            ' existing file will be overwritten
            FileUpload1.SaveAs(savePath)
            Response.Write("File uploaded successfully!")
        Else
            Response.Write("No file to upload")
        End If

    End Sub
End Class

 
Related examples in the same category
1.FileUpload Control
2.Get file name
java2s.com  | Contact Us | Privacy Policy
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.