コード例 #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>
        /// <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);
            }

            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))
                {
                    formattedString = null;
                    return(false);
                }
                return(true);
            }
        }
コード例 #2
0
        private void GetImageReference()
        {
            IPropertyStore store = ShellPropertyCollection.CreateDefaultPropertyStore(ParentShellObject);

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

                Marshal.ReleaseComObject(store);
                store = null;

                string refPath;
                ((IPropertyDescription2)Description.NativePropertyDescription).GetImageReferenceForValue(
                    propVar, out refPath);

                if (refPath == null)
                {
                    return;
                }

                int index = ShellNativeMethods.PathParseIconLocation(ref refPath);
                if (refPath != null)
                {
                    imageReferencePath      = refPath;
                    imageReferenceIconIndex = index;
                }
            }
        }