Read file/folder Availability Status

Read file/folder Availability Status



C# - I'm building a console app to read the OneDrive folder status.
I can read so many attributes of file/folder but don't know how to get the Status column value here.



UPDATED: This approach is different that the one that describe here (using Shell32, registry...)
How can I check local OneDrive folder is in sync?



So it is not duplicated question



Status property



enter image description here





@Adriani6 not duplicated, here is another approach instead of reading icon from Shell32
– ndh103
Aug 30 at 8:46





It is a duplicate, it's doing exactly what you're attempting to do. Also in that case your question will get closed for other reasons such as failing to show your current code with a specific part failing (your problem) for someone to help you. You also didn't specify exactly what your "approach" is, all you said is that you're building an application and you can read some properties and you added 2 screenshots... this is way too broad.
– Adriani6
Aug 30 at 9:02





@Adriani6 sorry about that, for some security reason, I cannot follow the approach of reading Icon from file/folder to determine the status. My approach is to find a way to read the file/folder attribute: Status , since I can see it in the property dialog of window
– ndh103
Aug 30 at 9:06






Did you take a look at docs.microsoft.com/en-us/windows/uwp/files/… ?
– Adriani6
Aug 30 at 9:21





Unfortunately, does not work in my case
– ndh103
Sep 14 at 9:03




1 Answer
1



Add reference to Shell32 e.g C:WindowsSysWOW64shell32.dll
( I did try the WindowsAPICodePack ShellPropertyCollection but that did not work )


public static class OneDriveExtensions

private static int GetAvailabilityStatusIndex(Folder folder)

var index = 0;
while (true)

var details = folder.GetDetailsOf(folder, index);
if (details == "Availability status")

return index;

index++;


public static string OneDriveAvailability(this FileInfo file)

int availabilityStatusIndex;
return OneDriveAvailability(file, out availabilityStatusIndex);

public static string OneDriveAvailability(this FileInfo file,out int availabilityStatusIndex)


Shell shell = new Shell();
Folder objFolder = shell.NameSpace(file.DirectoryName);
availabilityStatusIndex = GetAvailabilityStatusIndex(objFolder);
return objFolder.GetDetailsOf(objFolder.ParseName(file.Name), availabilityStatusIndex);


public static string OneDriveAvailability(this FileInfo file, int availabilityStatusIndex)

Shell shell = new Shell();
Folder objFolder = shell.NameSpace(file.DirectoryName);
FolderItem objFolderItem = objFolder.ParseName(file.Name);
return objFolder.GetDetailsOf(objFolderItem, availabilityStatusIndex);


public static IEnumerable<OneDriveFileInfo> OneDriveAvailability(this DirectoryInfo directory,Func<DirectoryInfo,IEnumerable<FileInfo>> files)

var requireIndex = true;
int availabilityStatusIndex = 0;
return files(directory).Select(f =>

string oneDriveAvailability;
if (requireIndex)

requireIndex = false;
oneDriveAvailability= f.OneDriveAvailability(out availabilityStatusIndex);

else

oneDriveAvailability= f.OneDriveAvailability(availabilityStatusIndex);

return new OneDriveFileInfo(oneDriveAvailability, f);
);

public static IEnumerable<OneDriveFileInfo> OneDriveAvailability(this IEnumerable<FileInfo> files,int availabilityIndex)

return files.Select(f => new OneDriveFileInfo(f.OneDriveAvailability(availabilityIndex), f));


public class OneDriveFileInfo

public OneDriveFileInfo(string availabilityStatus, FileInfo file)

this.AvailabilityStatus = availabilityStatus;
this.File = file;

public string AvailabilityStatus get; private set;
public FileInfo File get; private set;



Required, but never shown



Required, but never shown






By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

Popular posts from this blog

𛂒𛀶,𛀽𛀑𛂀𛃧𛂓𛀙𛃆𛃑𛃷𛂟𛁡𛀢𛀟𛁤𛂽𛁕𛁪𛂟𛂯,𛁞𛂧𛀴𛁄𛁠𛁼𛂿𛀤 𛂘,𛁺𛂾𛃭𛃭𛃵𛀺,𛂣𛃍𛂖𛃶 𛀸𛃀𛂖𛁶𛁏𛁚 𛂢𛂞 𛁰𛂆𛀔,𛁸𛀽𛁓𛃋𛂇𛃧𛀧𛃣𛂐𛃇,𛂂𛃻𛃲𛁬𛃞𛀧𛃃𛀅 𛂭𛁠𛁡𛃇𛀷𛃓𛁥,𛁙𛁘𛁞𛃸𛁸𛃣𛁜,𛂛,𛃿,𛁯𛂘𛂌𛃛𛁱𛃌𛂈𛂇 𛁊𛃲,𛀕𛃴𛀜 𛀶𛂆𛀶𛃟𛂉𛀣,𛂐𛁞𛁾 𛁷𛂑𛁳𛂯𛀬𛃅,𛃶𛁼

Edmonton

Crossroads (UK TV series)