<%@ Page Title="Folder Drop (VB.NET)" Language="VB" MasterPageFile="~/Site.master" AutoEventWireup="true" %>
<%@ Register Assembly="AjaxUploader" Namespace="AjaxUploader.Controls" TagPrefix="au" %>
<script runat="server">
    Protected Sub Uploader1_FileUploaded(ByVal sender As Object, ByVal e As AjaxUploader.Events.FileUploadedEventArgs)
        ' e.RelativePath: "photos/2026/beach.jpg" for folder uploads, Nothing for
        ' plain files. Already traversal-sanitized - still combine it under a
        ' root YOU choose so the tree can only ever descend from there.
        Dim relative As String = If(e.RelativePath, System.IO.Path.GetFileName(If(e.FileName, "file")))
        Dim destination As String = System.IO.Path.Combine(
            Server.MapPath("~/App_Data/FolderDemoVB"), relative.Replace("/"c, "\"c))

        System.IO.Directory.CreateDirectory(System.IO.Path.GetDirectoryName(destination))
        Dim svc As New AjaxUploader.Services.UploadService()
        svc.CopyFile(e.FileGuid, destination)

        litSaved.Text &= "<li><code>" & Server.HtmlEncode(relative) & "</code> (tree preserved)</li>"
    End Sub
</script>
<asp:Content ID="TitleContent" ContentPlaceHolderID="TitleContent" runat="server">Folder Drop (VB.NET) - AjaxUploader v5.3 Demos</asp:Content>
<asp:Content ID="HeaderContent" ContentPlaceHolderID="HeaderTitle" runat="server">Folder Drop - VB.NET</asp:Content>
<asp:Content ID="BodyContent" ContentPlaceHolderID="MainContent" runat="server">
<div class="demo-card"> <div class="demo-card-header">Recreate the dropped folder tree, in VB.NET</div> <div class="demo-card-body">
 <p class="demo-description"> Drop a folder (or browse a directory) and each file arrives with its relative path preserved.
 The VB handler recreates the structure under <code>App_Data/FolderDemoVB</code> using
 <code>e.RelativePath</code> - one <code>Path.Combine</code> and one <code>CreateDirectory</code>. </p>
 <div class="demo-expect"><strong>What you should see:</strong> drop a nested folder; after the automatic postback the list names each file's preserved path, and the same tree exists on disk under <code>App_Data/FolderDemoVB</code>.</div>
 <au:AjaxFileUpload ID="Uploader1" runat="server"
     AllowMultiple="true"
     AutoUpload="true"
     AutoPostBack="true"
     WebkitDirectory="true"
     ButtonText="Browse a Directory"
     ShowProgress="true"
     OnFileUploaded="Uploader1_FileUploaded" />
 <ul class="small mt-3"><asp:Literal ID="litSaved" runat="server" /></ul>
 <div class="code-panel"> <pre><code>Protected Sub Uploader1_FileUploaded(ByVal sender As Object,
        ByVal e As AjaxUploader.Events.FileUploadedEventArgs)
    ' e.RelativePath is sanitized server-side; Nothing for plain files
    Dim relative As String = If(e.RelativePath,
        System.IO.Path.GetFileName(If(e.FileName, "file")))
    Dim destination As String = System.IO.Path.Combine(
        Server.MapPath("~/App_Data/FolderDemoVB"), relative.Replace("/"c, "\"c))

    System.IO.Directory.CreateDirectory(System.IO.Path.GetDirectoryName(destination))
    Dim svc As New AjaxUploader.Services.UploadService()
    svc.CopyFile(e.FileGuid, destination)
End Sub</code></pre> </div>
</div> </div>
</asp:Content>
