CmisSync.Lib.Storage.FileSystem.ExtendedAttributeReaderUnix.SetExtendedAttribute C# (CSharp) Method

SetExtendedAttribute() public method

Sets the extended attribute.
public SetExtendedAttribute ( string path, string key, string value, bool restoreLastModificationDate = false ) : void
path string Path to the file or folder.
key string Key of the extended attribute.
value string Value of the extended attribute.
restoreLastModificationDate bool If set to true restore last modification date.
return void
        public void SetExtendedAttribute(string path, string key, string value, bool restoreLastModificationDate = false) {
#if __MonoCS__
            path = Path.GetFullPath(path);
            if (!File.Exists(path) && !Directory.Exists(path)) {
                throw new FileNotFoundException(string.Format("{0}: on path \"{1}\"", "No such file or directory", path), path);
            }

            long ret;
            if (value == null) {
                RemoveExtendedAttribute(path, key);
                return;
            } else {
                ret = Syscall.setxattr(path, prefix + key, Encoding.UTF8.GetBytes(value));
            }

            if (ret != 0) {
                throw new ExtendedAttributeException(string.Format("{0}: on path \"{1}\"", Syscall.GetLastError().ToString(), path));
            }
#else
            throw new WrongPlatformException();
#endif
        }

Usage Example

 public void SetAttributeToFile()
 {
     using (File.Create(path));
     string key = "test";
     string value = "value";
     var reader = new ExtendedAttributeReaderUnix();
     reader.SetExtendedAttribute(path, key, value);
     Assert.That(reader.GetExtendedAttribute(path, key).Equals(value));
 }
All Usage Examples Of CmisSync.Lib.Storage.FileSystem.ExtendedAttributeReaderUnix::SetExtendedAttribute