Upload with folder structure

Home > Basic examples > Example 13

Explanation

Upload the file including the folder structure.

On the server, you can obtain the folder path with the name 'DEXTUploadX5_Folder'.

# server side code
			
using (var dext = new DEXTUpload.NET.FileUpload())
{
    var sb = new StringBuilder();

    var files = dext.GetFileElements("DEXTUploadX5_FileData");
    var folders = dext.GetStringElements("DEXTUploadX5_Folder");
    var list = files.Zip(folders, (first, second) => new { File = first, Folder = second });
    var dir = null as DirectoryInfo;

    foreach (var pair in list)
    {
        dir = new DirectoryInfo(Path.Combine(dext.DefaultPath, pair.Folder.Value.Substring(1)));
        if (!dir.Exists) dir.Create();

        if (!pair.File.IsEmpty)
        {
            pair.File.Save(dir);
            sb.AppendFormat("F:{0}\n", pair.File.LastSavedFilePath);
        }
    }
    ...
}

Precautions for uploading the folder structure are as follows.

Example