eMi
eMi

Reputation: 5628

Check if file or folder is "Always available offline"?

How can we check (return true or false) if a folder or file is activated for "Always available offline"? I am using Microsoft Sync Center.

enter image description here

Upvotes: 0

Views: 1302

Answers (1)

eMi
eMi

Reputation: 5628

I was able to get the need informations by using the WMI provider: https://learn.microsoft.com/de-de/previous-versions/windows/desktop/offlinefiles/about-offline-files-wmi-provider

EDIT:

Don't forget to add a reference to System.Management.

I came up with following snippet:

            ManagementScope scope = new ManagementScope("\\\\.\\ROOT\\cimv2");
            ObjectQuery query = new ObjectQuery("SELECT * FROM Win32_OfflineFilesItem");
            ManagementObjectSearcher searcher = new ManagementObjectSearcher(scope, query);
            ManagementObjectCollection queryCollection = searcher.Get();
            foreach (ManagementObject m in queryCollection)
            {
                var pinInfo = (ManagementBaseObject)m.GetPropertyValue("PinInfo");

                if (pinInfo != null)
                {
                    if ((bool)pinInfo.GetPropertyValue("Pinned"))
                    {
                          //the file or folder is set to "always available offline"
                          var itemPath = m["ItemPath"]
                    }
                }
            }

Upvotes: 1

Related Questions