/// <summary> /// constructor /// </summary> /// <param name="directoryPath">the media item path</param> public DirectoryItem(string directoryPath) { try { if (!Directory.Exists(directoryPath)) { throw new FileNotFoundException("The directory added to DirectoryItem was not found!", directoryPath); } _mDirectoryPath = directoryPath; FileInfo fileInfo = new FileInfo(_mDirectoryPath); _displayName = fileInfo.Name; // // Get all the files in the directory // string[] files = Directory.GetFiles(_mDirectoryPath); foreach (string file in files) { _mediaItems.Add(new FileItem(file)); } // // Get all the subdirectories // string[] directories = Directory.GetDirectories(_mDirectoryPath); foreach (string directory in directories) { _mediaItems.Add(new DirectoryItem(directory)); } // // Get the Directory icon // SHFILEINFO shinfo = new SHFILEINFO(); IntPtr hImg = Win32.SHGetFileInfo(_mDirectoryPath, 0, ref shinfo, (uint)Marshal.SizeOf(shinfo), Win32.SHGFI_ICON | Win32.SHGFI_SMALLICON); if (IntPtr.Zero != shinfo.hIcon) { //The icon is returned in the hIcon member of the shinfo struct System.Drawing.IconConverter imageConverter = new System.Drawing.IconConverter(); System.Drawing.Icon icon = System.Drawing.Icon.FromHandle(shinfo.hIcon); try { _fileIconImage = (System.Drawing.Image) imageConverter.ConvertTo(icon, typeof(System.Drawing.Image)); } catch (NotSupportedException) { } Win32.DestroyIcon(shinfo.hIcon); } } catch (Exception ex) { throw new global::System.InvalidOperationException("Error adding folder" + ex.Message); } }
public FileItem(string path) { if (!File.Exists(path)) { throw new FileNotFoundException("File yang ditambahkan tidak ditemukan !!", path); } filePath = path; FileInfo fileInfo = new FileInfo(filePath); displayName = fileInfo.Name; panjangFile = fileInfo.Length; SHFILEINFO shinfo = new SHFILEINFO(); IntPtr hImg = Win32.SHGetFileInfo(filePath, 0, ref shinfo, (uint)Marshal.SizeOf(shinfo), Win32.SHGFI_ICON | Win32.SHGFI_SMALLICON); if (shinfo.hIcon != null) { System.Drawing.IconConverter imageConverter = new System.Drawing.IconConverter(); System.Drawing.Icon icon = System.Drawing.Icon.FromHandle(shinfo.hIcon); try { fileIconImage = (System.Drawing.Image) imageConverter.ConvertTo(icon, typeof(System.Drawing.Image)); } catch (NotSupportedException) { } Win32.DestroyIcon(shinfo.hIcon); } }
public FileItem(string path) { if (!File.Exists(path)) { throw new FileNotFoundException("The file added to FileItem was not found!", path); } filePath = path; var fileInfo = new FileInfo(filePath); displayName = fileInfo.Name; m_fileLength = fileInfo.Length; // Get the File icon var shinfo = new SHFILEINFO(); IntPtr hImg = NativeMethods.SHGetFileInfo(filePath, 0, ref shinfo, (uint)Marshal.SizeOf(shinfo), NativeMethods.SHGFI_ICON | NativeMethods.SHGFI_SMALLICON); //The icon is returned in the hIcon member of the shinfo struct var imageConverter = new System.Drawing.IconConverter(); var icon = System.Drawing.Icon.FromHandle(shinfo.hIcon); try { fileIconImage = (System.Drawing.Image) imageConverter.ConvertTo(icon, typeof(System.Drawing.Image)); } catch (NotSupportedException) { } NativeMethods.DestroyIcon(shinfo.hIcon); }
/// <summary> /// /// </summary> /// <param name="directoryPath"></param> public DirectoryItem(string directoryPath) { if (!Directory.Exists(directoryPath)) { throw new FileNotFoundException("The directory added to DirectoryItem was not found!", directoryPath); } m_directoryPath = directoryPath; FileInfo fileInfo = new FileInfo(m_directoryPath); displayName = fileInfo.Name; // // Get all the files in the directory // string[] files = Directory.GetFiles(m_directoryPath); foreach (string file in files) { mediaItems.Add(new FileItem(file)); } // // Get all the subdirectories // string[] directories = Directory.GetDirectories(m_directoryPath); foreach (string directory in directories) { mediaItems.Add(new DirectoryItem(directory)); } // // Get the Directory icon // SHFILEINFO shinfo = new SHFILEINFO(); IntPtr hImg = Win32.SHGetFileInfo(m_directoryPath, 0, ref shinfo, (uint)Marshal.SizeOf(shinfo), Win32.SHGFI_ICON | Win32.SHGFI_SMALLICON); if (shinfo.hIcon != null) { //The icon is returned in the hIcon member of the shinfo struct System.Drawing.IconConverter imageConverter = new System.Drawing.IconConverter(); System.Drawing.Icon icon = System.Drawing.Icon.FromHandle(shinfo.hIcon); try { fileIconImage = (System.Drawing.Image) imageConverter.ConvertTo(icon, typeof(System.Drawing.Image)); } catch (NotSupportedException) { } Win32.DestroyIcon(shinfo.hIcon); } }
public FileItem(string path) { try { if (!File.Exists(path)) { throw new FileNotFoundException("The file added to FileItem was not found!", path); } filePath = path; FileInfo fileInfo = new FileInfo(filePath); _displayName = fileInfo.Name; _fileLength = fileInfo.Length; // // Get the File icon // SHFILEINFO shinfo = new SHFILEINFO(); IntPtr hImg = Win32.SHGetFileInfo(filePath, 0, ref shinfo, (uint)Marshal.SizeOf(shinfo), Win32.SHGFI_ICON | Win32.SHGFI_SMALLICON); if (IntPtr.Zero != shinfo.hIcon) { //The icon is returned in the hIcon member of the shinfo struct System.Drawing.IconConverter imageConverter = new System.Drawing.IconConverter(); System.Drawing.Icon icon = System.Drawing.Icon.FromHandle(shinfo.hIcon); try { _fileIconImage = (System.Drawing.Image) imageConverter.ConvertTo(icon, typeof(System.Drawing.Image)); } catch (NotSupportedException) { } Win32.DestroyIcon(shinfo.hIcon); } } catch (Exception ex) { throw new global::System.InvalidOperationException("Error adding file" + ex.Message); } }
public DirectoryItem(string directoryPath) { if (!Directory.Exists(directoryPath)) { throw new FileNotFoundException("File yang ditambahkan tidak ditemukan !!", directoryPath); } pathDirektori = directoryPath; FileInfo fileInfo = new FileInfo(pathDirektori); displayName = fileInfo.Name; string[] files = Directory.GetFiles(pathDirektori); foreach (string file in files) { mediaItems.Add(new FileItem(file)); } string[] directories = Directory.GetDirectories(pathDirektori); foreach (string directory in directories) { mediaItems.Add(new DirectoryItem(directory)); } SHFILEINFO shinfo = new SHFILEINFO(); IntPtr hImg = Win32.SHGetFileInfo(pathDirektori, 0, ref shinfo, (uint)Marshal.SizeOf(shinfo), Win32.SHGFI_ICON | Win32.SHGFI_SMALLICON); if (shinfo.hIcon != null) { System.Drawing.IconConverter imageConverter = new System.Drawing.IconConverter(); System.Drawing.Icon icon = System.Drawing.Icon.FromHandle(shinfo.hIcon); try { fileIconImage = (System.Drawing.Image) imageConverter.ConvertTo(icon, typeof(System.Drawing.Image)); } catch (NotSupportedException) { } Win32.DestroyIcon(shinfo.hIcon); } }
public FileItem(string path) { if (!File.Exists(path)) { throw new FileNotFoundException("The file added to FileItem was not found!", path); } filePath = path; FileInfo fileInfo = new FileInfo(filePath); displayName = fileInfo.Name; m_fileLength = fileInfo.Length; // // Get the File icon // SHFILEINFO shinfo = new SHFILEINFO(); IntPtr hImg = Win32.SHGetFileInfo(filePath, 0, ref shinfo, (uint)Marshal.SizeOf(shinfo), Win32.SHGFI_ICON | Win32.SHGFI_SMALLICON); if (shinfo.hIcon != null) { //The icon is returned in the hIcon member of the shinfo struct System.Drawing.IconConverter imageConverter = new System.Drawing.IconConverter(); System.Drawing.Icon icon = System.Drawing.Icon.FromHandle(shinfo.hIcon); try { fileIconImage = (System.Drawing.Image) imageConverter.ConvertTo(icon, typeof(System.Drawing.Image)); } catch (NotSupportedException) { } Win32.DestroyIcon(shinfo.hIcon); } }
public DirectoryItem(string directoryPath) { if (!Directory.Exists(directoryPath)) { throw new FileNotFoundException("The directory added to DirectoryItem was not found!", directoryPath); } m_directoryPath = directoryPath; var fileInfo = new FileInfo(m_directoryPath); DisplayName = fileInfo.Name; string[] files = Directory.GetFiles(m_directoryPath); foreach (string file in files) mediaItems.Add(new FileItem(file)); string[] directories = Directory.GetDirectories(m_directoryPath); foreach (string directory in directories) mediaItems.Add(new DirectoryItem(directory)); var shinfo = new SHFILEINFO(); IntPtr hImg = NativeMethods.SHGetFileInfo(m_directoryPath, 0, ref shinfo, (uint)Marshal.SizeOf(shinfo), NativeMethods.SHGFI_ICON | NativeMethods.SHGFI_SMALLICON); //The icon is returned in the hIcon member of the shinfo struct var imageConverter = new System.Drawing.IconConverter(); var icon = System.Drawing.Icon.FromHandle(shinfo.hIcon); try { fileIconImage = (System.Drawing.Image) imageConverter.ConvertTo(icon, typeof(System.Drawing.Image)); } catch (NotSupportedException) { } NativeMethods.DestroyIcon(shinfo.hIcon); }