Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ShellItem: Name & ParsingName Properties not filled #66

Closed
tajbender opened this issue Oct 8, 2019 · 6 comments
Closed

ShellItem: Name & ParsingName Properties not filled #66

tajbender opened this issue Oct 8, 2019 · 6 comments
Assignees
Labels

Comments

@tajbender
Copy link
Contributor

Hi, David,

Describe the bug
I just migrated my packages from v2.7 to 3.1, where I'm using the Vanara.Windows.Shell-package. Using the good old ShellItems I can't retrieve their Name and DisplayName respectively which seem always to be null.

What code is involved
Vanara.Windows.Shell.ShellItem-Objects

Expected behavior
After having created an Vanara.Windows.Shell.ShellItem, I expected to have both Name and ParsingName filled to use them for Display and Parsing them.

For FileSystem-Objects, I could use the FileInfo, for virtual Items like Libraries this won't work of course. However, even calling GetDisplayName returns NULL, see screenie.

Is there something I've missed, or may this be a bug?

Thanks in advance, regards,
tajbender

Screenshots

Vanara v3 1 ShellItem-Issue

@dahall
Copy link
Owner

dahall commented Oct 8, 2019

Thanks for reporting. Just to confirm, in v2.3.7 those properties returned correct values and in v3.1 they come back as empty?

dahall added a commit that referenced this issue Oct 8, 2019
… Empty when a size not known (like as a return value from a COM object).
@dahall dahall self-assigned this Oct 8, 2019
@dahall dahall added the bug label Oct 8, 2019
@dahall
Copy link
Owner

dahall commented Oct 8, 2019

Nevermind. I found the problem. In trying to make string allocated with CoTaskMemAlloc more "safe", I ended up breaking the use case where you don't know the allocated size. It is fixed and will be released as part of v3.1.1 shortly.

@dahall dahall closed this as completed Oct 8, 2019
@tajbender
Copy link
Contributor Author

tajbender commented Jan 7, 2020

@dahall: On my machine, this still isn't working for ShellLibrary-Objects. Or did I get something wrong?

Win 10 Pro, x64, using Vanara v3.1.7:

Vanara3 1 7-SHLibraries

@dahall
Copy link
Owner

dahall commented Jan 9, 2020

I have just run the following unit test on "Any CPU", x86 and x64 with the same results. Please check your config to make sure you have v3.1.7 of Vanara.PInvoke.Shell32 and Vanara.Windows.Shell.

using (var i = new ShellFolder(PInvoke.Tests.TestCaseSources.WordDoc))
{
   Assert.That(i.GetDisplayName(ShellItemDisplayString.FileSysPath), Is.EqualTo(PInvoke.Tests.TestCaseSources.WordDoc).IgnoreCase);
   foreach (ShellItemDisplayString e in Enum.GetValues(typeof(ShellItemDisplayString)))
      Assert.That(() => TestContext.WriteLine($"{e}={i.GetDisplayName(e)}"), Throws.Nothing);
   Assert.That(i.GetDisplayName((ShellItemDisplayString)0x8fffffff), Is.EqualTo(i.GetDisplayName(0)));
}

using (var i = new ShellFolder(PInvoke.Tests.TestCaseSources.TempDir))
{
   Assert.That(i.GetDisplayName(ShellItemDisplayString.FileSysPath), Is.EqualTo(PInvoke.Tests.TestCaseSources.TempDir).IgnoreCase);
   foreach (ShellItemDisplayString e in Enum.GetValues(typeof(ShellItemDisplayString)))
      Assert.That(() => TestContext.WriteLine($"{e}={i.GetDisplayName(e)}"), Throws.Nothing);
   Assert.That(i.GetDisplayName((ShellItemDisplayString)0x8fffffff), Is.EqualTo(i.GetDisplayName(0)));
}

using (var i = new ShellFolder(KNOWNFOLDERID.FOLDERID_DocumentsLibrary))
{
   foreach (ShellItemDisplayString e in Enum.GetValues(typeof(ShellItemDisplayString)))
      Assert.That(() => TestContext.WriteLine($"{e}={i.GetDisplayName(e)}"), Throws.Nothing);
   Assert.That(i.GetDisplayName((ShellItemDisplayString)0x8fffffff), Is.EqualTo(i.GetDisplayName(0)));
}

Output

NormalDisplay=Test.docx
ParentRelativeParsing=Test.docx
DesktopAbsoluteParsing=C:\Temp\Test.docx
ParentRelativeEditing=Test.docx
DesktopAbsoluteEditing=C:\Temp\Test.docx
FileSysPath=C:\Temp\Test.docx
Url=file:///C:/Temp/Test.docx
ParentRelativeForAddressBar=Test.docx
ParentRelative=Test.docx
ParentRelativeForUI=Test.docx

NormalDisplay=Temp
ParentRelativeParsing=Temp
DesktopAbsoluteParsing=C:\Temp
ParentRelativeEditing=Temp
DesktopAbsoluteEditing=C:\Temp
FileSysPath=C:\Temp
Url=file:///C:/Temp
ParentRelativeForAddressBar=Temp
ParentRelative=Temp
ParentRelativeForUI=Temp

NormalDisplay=Documents
ParentRelativeParsing={7B0DB17D-9CD2-4A93-9733-46CC89022E7C}
DesktopAbsoluteParsing=::{031E4825-7B94-4DC3-B131-E946B44C8DD5}\Documents.library-ms
ParentRelativeEditing=Documents
DesktopAbsoluteEditing=Libraries\Documents
FileSysPath=
Url=
ParentRelativeForAddressBar=Documents
ParentRelative=Documents
ParentRelativeForUI=Documents

@dahall dahall reopened this Jan 9, 2020
dahall added a commit that referenced this issue Jan 9, 2020
@tajbender
Copy link
Contributor Author

Hi, David,

thanks for your quick reply. Perhaps I just misunderstood the Name property, but here's what I'm doing:

var libfolder = new ShellFolder(KNOWNFOLDERID.FOLDERID_Libraries);
var libraries = libfolder.EnumerateChildren(FolderItemFilter.Folders);
Console.WriteLine($"Enumerating '{ libfolder.Name }'");
foreach (var libitm in libraries)
  Console.WriteLine($"Current LibItem.Name: '{ libitm.Name } '  " + 
  $"having DisplayName: ' { libitm.GetDisplayName(ShellItemDisplayString.ParentRelative) }'");

This leads to the following output:

Enumerating 'Libraries'
Current LibItem.Name: ' ' having DisplayName: ' Git'
Current LibItem.Name: ' ' having DisplayName: ' taj's Test Library'
Current LibItem.Name: ' ' having DisplayName: ' [Git.Workspace]'
Current LibItem.Name: ' ' having DisplayName: ' Music'
Current LibItem.Name: ' ' having DisplayName: ' Saved Pictures'
Current LibItem.Name: ' ' having DisplayName: ' Videos'
Current LibItem.Name: ' ' having DisplayName: ' Camera Roll'
Current LibItem.Name: ' ' having DisplayName: ' Documents'
Current LibItem.Name: ' ' having DisplayName: ' Pictures'

So, yes, using GetDisplayName works, it's just the Name-property I'm wondering about. Shouldn't it be filled, too? If it never was intended for Display-purposes, just forget about it 🤣

Thanks in advance,
tajbender

@dahall
Copy link
Owner

dahall commented Jan 10, 2020

The Name property simply retrieves the ShellItemDisplayString.NormalDisplay value from GetDisplayName. If the IShellFolder provider did not supply a string for that value, then Name will be null or Empty.

@dahall dahall closed this as completed Jan 16, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants