Jasinski Technical Wiki

Navigation

Home Page
Index
All Pages

Quick Search
»
Advanced Search »

Contributor Links

Create a new Page
Administration
File Management
Login/Logout
Your Profile

Other Wiki Sections

Software

PoweredBy

FileUpload Control Sample - ASP.NET

RSS
Modified on Tue, Jun 30, 2009, 10:08 AM by Administrator Categorized as ASP·NET Web Forms, Code Sample
The following code shows how to implement file uploading in ASP.NET using the FileUpload control and an "Upload" button. (This code handles the Click event for the button.)

Protected Sub uxUploadButton_Click(ByVal sender As Object, ByVal e As EventArgs)

    If uxFileUpload.HasFile Then

        Dim id As Integer = Session(Constants.SESSION_ID)
        Dim shortFileName As String = uxFileUpload.FileName

        Dim serverPath as String = Server.MapPath("~\uploads\TD\" & id.ToString())

        If Not Directory.Exists(serverPath) Then
            Directory.CreateDirectory(serverPath)
        End If

        Dim serverFile As String = Path.Combine(serverPath, shortFileName)

        uxFileUpload.SaveAs(serverFile)

    End If

End Sub

ScrewTurn Wiki version 3.0.1.400. Some of the icons created by FamFamFam. Except where noted, all contents Copyright © 1999-2024, Patrick Jasinski.