Handling metadata

Home > Basic examples > Example 02

Explanation

Metadata is additional data that can be used only in local files and is registered in "key=value" format.

To register the metadata, register the key and value using the index(order) of the local file.

var dx = dx5.get("component id");
// Returning the value for the "user" key in the metadata of the 6th item.
var userValue = dx.getMetaDataByIndex(5, "user");
// Setting the value for the "user" key in the metadata of the 6th item to "ABC". 
dx.setMetaDataByIndex(5, "user", "ABC");
// Deleting the "user" key in the 6th item's metadata. 
dx.deleteMetaDataByIndex(5, "user");

The metadata is passed to the server when the local file is uploaded.

In server-side code, the "DEXTUploadX5_MetaData" is passed as the form name, so metadata can be obtained from the form data.

The metadata passed to the form name("DEXTUploadX5_MetaData") follows the order of the uploaded file.

# Server-side					
						
using (var dext = new DEXTUpload.NET.FileUpload())
{
    var sb = new StringBuilder();
    var files = dext.GetFileElements("DEXTUploadX5_FileData");
    // You can get the metadata from the "DEXTUploadX5_MetaData" form name.
    var meta = dext.GetStringElements("DEXTUploadX5_MetaData");
    // Metadata is paired with a file.
    var list = files.Zip(meta, (first, second) => new { File = first, Metadata = second });
                
    foreach (var pair in list)
    {
        if (!pair.File.IsEmpty)
        {
            pair.File.Save();
            sb.AppendFormat("F:{0}, M:{1}\n", pair.File.FileName, pair.Metadata.Value);
        }
    }
    context.Response.ContentType = "text/plain";
    context.Response.Write(sb.ToString());
}

If there are multiple metadata for a single file, the metadata that is passed to the server as the "key1[SPLT]value1[SPLT]key2[SPLT]value2[SPLT]key3[SPLT]Value3" format, not the "key1=value1[SPLT]key2=value2[SPLT]key3=value3" format.

To obtain the data, separate the tokens with the string "[SPLT]", use the odd-numbered keys as the key, and the even-numbered as the value.

Example

Metadata applies only to local files. (Add a local file to test)