/// <summary> /// Initialize a new instance of the <see cref="ShellObject" /> class /// to the specified parsing name. /// </summary> /// <param name="parsingName"><c>ParsingName</c>.</param> /// <returns>Created <see cref="ShellObject" />.</returns> public static ShellObject FromParsingName(string parsingName) { Contract.Requires <ArgumentException>(!String.IsNullOrWhiteSpace(parsingName)); Contract.Ensures(Contract.Result <ShellObject>() != null); return(Create(ShellItem.FromParsingName(parsingName))); }
/// <summary> /// Create a new instance of the <see cref="ShellFolder" /> class /// to the specified folder path. /// </summary> /// <param name="path">Folder path.</param> /// <returns>Created <see cref="ShellFolder" />.</returns> public static ShellFolder FromFolderPath(string path) { Contract.Requires <ArgumentException>(!String.IsNullOrWhiteSpace(path)); Contract.Ensures(Contract.Result <ShellFolder>() != null); var absPath = GetAbsolutePath(path); if (!Directory.Exists(absPath)) { throw new DirectoryNotFoundException(String.Format(CultureInfo.InvariantCulture, ErrorMessages.FilePathNotExist, path)); } return(new ShellFolder(ShellItem.FromParsingName(absPath))); }
/// <summary> /// Create a new instance of the <see cref="ShellFile" /> class /// to the specified file path. /// </summary> /// <param name="path">File path.</param> /// <returns>Created <see cref="ShellFile" />.</returns> public static ShellFile FromFilePath(string path) { Contract.Requires <ArgumentException>(!String.IsNullOrEmpty(path)); Contract.Ensures(Contract.Result <ShellFile>() != null); var absPath = GetAbsolutePath(path); if (!File.Exists(absPath)) { throw new FileNotFoundException(String.Format(CultureInfo.CurrentUICulture, ErrorMessages.FilePathNotExist, path), path); } return(new ShellFile(ShellItem.FromParsingName(absPath))); }
public async Task FromParsingNameTest1() { await STATask.Run(() => { const string parsingName = @"::{031E4825-7B94-4DC3-B131-E946B44C8DD5}\Documents.library-ms"; var actual = ShellItem.FromParsingName(parsingName); Assert.NotNull(actual); Assert.Equal(parsingName, actual.GetParsingName()); Assert.Equal(".library-ms", actual.GetItemType()); Console.WriteLine("ParsingName = {0}", actual.GetParsingName()); Console.WriteLine("ItemType = {0}", actual.GetItemType()); var folder = ShellFactory.FromShellItem(actual); Console.WriteLine("folder.ParsingName = {0}", folder.ParsingName); Console.WriteLine("folder.Type = {0}", folder.GetType()); }); }