public string GetFileInfo(IFileInfoProvider provider, string columnName, ShellItem item)
        {
            string retVal = string.Empty;

            ShellAPI.STATSTG info = provider.GetFileInfo();

            switch (columnName)
            {
            case "Size":
                #region Size
            {
                retVal = GetSizeString(info.cbSize);
            }
                #endregion
                break;

            case "Date Created":
                #region Date Created
            {
                DateTime dateTime = ShellAPI.FileTimeToDateTime(info.ctime);
                string   time     = dateTime.ToLongTimeString();
                retVal = string.Format("{0} {1}",
                                       dateTime.ToShortDateString(),
                                       time.Remove(time.Length - 3, 3));
            }
                #endregion
                break;

            case "Date Modified":
                #region Date Modified
            {
                DateTime dateTime = ShellAPI.FileTimeToDateTime(info.mtime);
                string   time     = dateTime.ToLongTimeString();
                retVal = string.Format("{0} {1}",
                                       dateTime.ToShortDateString(),
                                       time.Remove(time.Length - 3, 3));
            }
                #endregion
                break;
            }

            return(retVal);
        }
        public string GetFolderInfo(IDirInfoProvider provider, string columnName, ShellItem item)
        {
            string retVal = string.Empty;

            if (columnName != "Size" && !item.IsSystemFolder && !item.IsDisk && item.IsFileSystem)
            {
                ShellAPI.STATSTG info = provider.GetDirInfo();

                switch (columnName)
                {
                case "Date Created":
                    #region Date Created
                {
                    DateTime dateTime = ShellAPI.FileTimeToDateTime(info.ctime);
                    string   time     = dateTime.ToLongTimeString();
                    retVal = string.Format("{0} {1}",
                                           dateTime.ToShortDateString(),
                                           time.Remove(time.Length - 3, 3));
                }
                    #endregion
                    break;

                case "Date Modified":
                    #region Date Modified
                {
                    DateTime dateTime = ShellAPI.FileTimeToDateTime(info.mtime);
                    string   time     = dateTime.ToLongTimeString();
                    retVal = string.Format("{0} {1}",
                                           dateTime.ToShortDateString(),
                                           time.Remove(time.Length - 3, 3));
                }
                    #endregion
                    break;
                }
            }

            return(retVal);
        }
Beispiel #3
0
        /// <summary>
        /// return STATSTG info of a file.
        /// </summary>
        internal static bool getFileStat(IStorage parentStorage, string filename, out ShellAPI.STATSTG statstg)
        {
            IntPtr  streamPtr = IntPtr.Zero;
            IStream stream    = null;

            statstg = new ShellAPI.STATSTG();

            try
            {
                if (parentStorage.OpenStream(
                        filename,
                        IntPtr.Zero,
                        ShellAPI.STGM.READ,
                        0,
                        out streamPtr) == ShellAPI.S_OK)
                {
                    stream = (IStream)Marshal.GetTypedObjectForIUnknown(streamPtr, typeof(IStream));
                    stream.Stat(out statstg, ShellAPI.STATFLAG.DEFAULT);
                    return(true);
                }
            }
            finally
            {
                if (stream != null)
                {
                    Marshal.ReleaseComObject(stream);
                    stream = null;
                }

                if (streamPtr != IntPtr.Zero)
                {
                    Marshal.Release(streamPtr);
                    streamPtr = IntPtr.Zero;
                }
            }
            return(false);
        }
Beispiel #4
0
 public int Stat(out ShellAPI.STATSTG pstatstg, ShellAPI.STATFLAG grfStatFlag)
 {
     return(_iStorage.Stat(out pstatstg, grfStatFlag));
 }