Click or drag to resize

PlaceholderFileSetMetadata Method

IT Hit User File System
Updates placeholder file information and file content if the file is hydrated.

Namespace:  ITHit.FileSystem.Windows
Assembly:  ITHit.FileSystem.Windows (in ITHit.FileSystem.Windows.dll) Version: 3.3.9602.0
Syntax
public override void SetMetadata(
	IFileSystemItemMetadata fileMetadata
)

Parameters

fileMetadata
Type: ITHit.FileSystemIFileSystemItemMetadata
New placeholder file information. This parameter must be of type IFileMetadata.
Exceptions
ExceptionCondition
ConflictExceptionThrown if the file is not in sync with the cloud.
BlockedExceptionThrown if the file is blocked and can not be updated.
Remarks

This method updates file placeholder attributes, creation and modification dates as well as custom data. It will also update file size and dehydrate the file. If the file is pinned or if the file is on disk and not marked as unpinned, it will then hydrate the file.

This method does not update the item name, the Name is ignored.

Examples

The code below is part of 'VirtualFileSystem' C# sample provided with the SDK.

C#
internal async Task<bool> UpdateAsync(FileSystemItemBasicInfo itemInfo)
{
    try
    {
        // Because of the on-demand population the file or folder placeholder may not exist in the user file system.
        if (FsPath.Exists(userFileSystemPath))
        {
            PlaceholderItem placeholderItem = PlaceholderItem.GetItem(userFileSystemPath);

            // Dehydrate/hydrate the file, update file size, custom data, creation date, modification date, attributes.
            placeholderItem.SetItemInfo(itemInfo);

            // Set ETag.
            await ETag.SetETagAsync(userFileSystemPath, itemInfo.ETag);

            // Clear icon.
            await ClearStateAsync();

            return true;
        }
    }
    catch (Exception ex)
    {
        await SetDownloadErrorStateAsync(ex);

        // Rethrow the exception preserving stack trace of the original exception.
        System.Runtime.ExceptionServices.ExceptionDispatchInfo.Capture(ex).Throw();
    }
    return false;
}
C#
internal async Task<bool> UpdateAsync(FileSystemItemBasicInfo itemInfo)
{
    try
    {
        // Because of the on-demand population the file or folder placeholder may not exist in the user file system.
        if (FsPath.Exists(userFileSystemPath))
        {
            PlaceholderItem placeholderItem = PlaceholderItem.GetItem(userFileSystemPath);

            // To be able to update the item we need to remove the read-only attribute.
            if((FsPath.GetFileSystemItem(userFileSystemPath).Attributes | System.IO.FileAttributes.ReadOnly) != 0)
            {
                FsPath.GetFileSystemItem(userFileSystemPath).Attributes &= ~System.IO.FileAttributes.ReadOnly;
            }

            // Dehydrate/hydrate the file, update file size, custom data, creation date, modification date, attributes.
            placeholderItem.SetItemInfo(itemInfo);

            // Set ETag.
            await ETag.SetETagAsync(userFileSystemPath, itemInfo.ETag);

            // Clear icon.
            //await ClearStateAsync();

            // Set the lock icon and read-only attribute, to indicate that the item is locked by another user.
            await SetLockedByAnotherUserAsync(itemInfo.LockedByAnotherUser);

            return true;
        }
    }
    catch (Exception ex)
    {
        await SetDownloadErrorStateAsync(ex);

        // Rethrow the exception preserving stack trace of the original exception.
        System.Runtime.ExceptionServices.ExceptionDispatchInfo.Capture(ex).Throw();
    }
    return false;
}
See Also