Search code examples
c#.netwindows-10offline-caching

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


Solution

  • 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"]
                        }
                    }
                }