Beispiel #1
0
        /// <summary>
        /// Returns a formatted, Unicode string representation of a property value.
        /// </summary>
        /// <param name="format">One or more of the PropertyDescriptionFormat flags
        /// that indicate the desired format.</param>
        /// <returns>The formatted value as a string, or null if this property
        /// cannot be formatted for display.</returns>
        public string FormatForDisplay(PropertyDescriptionFormatOptions format)
        {
            string formattedString;

            if (Description == null || Description.NativePropertyDescription == null)
            {
                // We cannot do anything without a property description
                return(null);
            }

            IPropertyStore store = ShellPropertyCollection.CreateDefaultPropertyStore(ParentShellObject);

            using (PropVariant propVar = new PropVariant())
            {
                store.GetValue(ref propertyKey, propVar);

                // Release the Propertystore
                Marshal.ReleaseComObject(store);
                store = null;

                HResult hr = Description.NativePropertyDescription.FormatForDisplay(propVar, ref format, out formattedString);

                // Sometimes, the value cannot be displayed properly, such as for blobs
                // or if we get argument exception
                if (!CoreErrorHelper.Succeeded(hr))
                {
                    throw new ShellException(hr);
                }

                return(formattedString);
            }
        }
        /// <summary>Returns a formatted, Unicode string representation of a property value.</summary>
        /// <param name="format">One or more of the PropertyDescriptionFormat flags that indicate the desired format.</param>
        /// <param name="formattedString">The formatted value as a string, or null if this property cannot be formatted for display.</param>
        /// <returns>True if the method successfully locates the formatted string; otherwise False.</returns>
        public bool TryFormatForDisplay(PropertyDescriptionFormatOptions format, out string formattedString)
        {
            if (Description == null || Description.NativePropertyDescription == null)
            {
                // We cannot do anything without a property description
                formattedString = null;
                return(false);
            }

            var store = ShellPropertyCollection.CreateDefaultPropertyStore(ParentShellObject);

            using (var propVar = new PropVariant())
            {
                store.GetValue(ref propertyKey, propVar);

                // Release the Propertystore
                Marshal.ReleaseComObject(store);
                store = null;

                var hr = Description.NativePropertyDescription.FormatForDisplay(propVar, ref format, out formattedString);

                // Sometimes, the value cannot be displayed properly, such as for blobs or if we get argument exception
                if (!CoreErrorHelper.Succeeded(hr))
                {
                    formattedString = null;
                    return(false);
                }
                return(true);
            }
        }
 private static string GetAttributeValue(this FileObject fileObject, PropertyKey propertyKey, PropertyDescriptionFormatOptions propertyFormat, ref string strError)
 {
     return("");
     //return FileFunctions.GetFileAttributeValue(fileObject.FilePath, propertyKey, propertyFormat, ref strError);
 }