- VAL.src.zip
- VAL
- Database
- packages
- EntityFramework.4.2.0.0
- lib
- net40
- EntityFramework.dll
- log4net.1.2.10
- lib
- 1.0
- log4net.dll
- 1.1
- log4net.dll
- 2.0
- log4net.dll
- log4net.1.2.11
- lib
- net10-full
- log4net.dll
- net11-full
- log4net.dll
- net20-cf
- log4net.dll
- net20-full
- log4net.dll
- net35-client
- log4net.dll
- net35-full
- log4net.dll
- net40-client
- log4net.dll
- net40-full
- log4net.dll
- Moq.4.0.10827
- lib
- NET35
- Moq.dll
- NET40
- Moq.dll
- Silverlight4
- Castle.Core.dll
- Moq.Silverlight.dll
- License.txt
- Moq.chm
- repositories.config
- structuremap.2.6.3
- lib
- StructureMap.dll
- READ-ME-First!.txt
- VAL.BusinessService
- VAL.ClientService
- VAL.Common
- VAL.Contracts
- VAL.Controls
- VAL.Data
- VAL.GUI
- VAL.Model
- VAL.Service
- VAL.sln
- VAL.Tests
- VAL.User.Documentation
- VAL.zip
- VisualApplicationLauncher
- Database
- Local.testsettings
- NRepo
- ProjectReferences
- EFCachingProvider.dll
- EFCachingProvider.Web.dll
- EFProviderWrapperToolkit.dll
- EFTracingProvider.dll
- log4net.dll
- StructureMap.dll
- READ-ME-First!.txt
- TraceAndTestImpact.testsettings
- VAL.BusinessService
- VAL.Common
- VAL.Contracts
- VAL.Controls
- VAL.Data
- VAL.GUI
- VAL.Model
- VAL.Service
- VAL.sln
- VAL.Tests
- VAL.User.Documentation
- VAL.vsmdi
|
namespace VAL
{
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Drawing;
using System.Runtime.InteropServices;
/// <summary>
/// Simple class to define some of the information required to display file
/// information
/// </summary>
public class KnownExplorerFile
{
/// <summary>
/// Default ctor
/// </summary>
/// <param name="description">The description of the file type</param>
/// <param name="icon">The icon for the file type</param>
public KnownExplorerFile(string description, Icon icon)
{
this.TypeDescription = description;
this.Icon = icon;
}
/// <summary>
/// The description of the file as seen in windows explorer
/// </summary>
public string TypeDescription { get; private set; }
/// <summary>
/// An icon associated with a file type
/// </summary>
public Icon Icon { get; private set; }
/// <summary>
/// Method that returns information about a particular file
/// <para>
/// This will get the file type description (as seen in windows explorer) and the
/// icon associated with the file type
/// </para>
/// </summary>
/// <param name="fileName">The filename to retrieve information about</param>
/// <returns>A <see cref="KnownExplorerFile"/> object</returns>
public static KnownExplorerFile GetInstance(string fileName)
{
NativeMethods.SHFILEINFO shinfo = new NativeMethods.SHFILEINFO();
IntPtr fi;
/*
Type: DWORD_PTR
Returns a value whose meaning depends on the uFlags parameter.
If uFlags does not contain SHGFI_EXETYPE or SHGFI_SYSICONINDEX,
the return value is nonzero if successful, or zero otherwise.
*/
fi = NativeMethods.SHGetFileInfo(fileName, 0, ref shinfo,
(uint)Marshal.SizeOf(shinfo),
SHGetFileInfoFlags.SHGFI_ICON |
SHGetFileInfoFlags.SHGFI_TYPENAME);
KnownExplorerFile knownFile = null;
if (fi.ToInt32() != 0)
{
// Clone the icon from handle, then clean up
Icon fileIcon = (Icon)Icon.FromHandle(shinfo.hIcon).Clone();
NativeMethods.DestroyIcon(shinfo.hIcon);
string fileType = shinfo.szTypeName;
knownFile = new KnownExplorerFile(fileType, fileIcon);
}
else
{
knownFile = new KnownExplorerFile("Unknown", null);
}
return knownFile;
}
/// <summary>
/// Gets the file type description for the specified file
/// </summary>
/// <param name="fileName"></param>
/// <returns></returns>
public static string GetFileTypeDescription(string fileName)
{
NativeMethods.SHFILEINFO shinfo = new NativeMethods.SHFILEINFO();
IntPtr fi;
string fileType = string.Empty;
fi = NativeMethods.SHGetFileInfo(fileName, 0, ref shinfo,
(uint)Marshal.SizeOf(shinfo),
SHGetFileInfoFlags.SHGFI_TYPENAME);
if (fi.ToInt32() != 0)
fileType = shinfo.szTypeName;
return fileType;
}
}
}
|
By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.
If a file you wish to view isn't highlighted, and is a text file (not binary), please
let us know and we'll add colourisation support for it.
This member has not yet provided a Biography. Assume it's interesting and varied, and probably something to do with programming.