/// <summary> /// Gets the path of this this known folder. /// </summary> /// <param name="fileExists"> /// Returns false if the folder is virtual, or a boolean /// value that indicates whether this known folder exists. /// </param> /// <param name="knownFolderNative">Native IKnownFolder reference</param> /// <returns> /// A <see cref="System.String"/> containing the path, or <see cref="string.Empty"/> if this known folder does not exist. /// </returns> private string GetPath(out bool fileExists, IKnownFolderNative knownFolderNative) { Debug.Assert(knownFolderNative != null); string kfPath = string.Empty; fileExists = true; // Virtual folders do not have path. if (knownFolderProperties.category == FolderCategory.Virtual) { fileExists = false; return(kfPath); } try { kfPath = knownFolderNative.GetPath(0); } catch (System.IO.FileNotFoundException) { fileExists = false; } catch (System.IO.DirectoryNotFoundException) { fileExists = false; } return(kfPath); }
/// <summary> /// Gets the path of this this known folder or null if known folder is not /// available or does not have a representation in the file system. /// </summary> /// <param name="fileExists"> /// Returns false if the folder is virtual, or a boolean /// value that indicates whether this known folder exists. /// </param> /// <param name="knownFolderNative">Native IKnownFolder reference</param> /// <returns> /// A <see cref="System.String"/> containing the path, or <see cref="System.String.Empty"/> /// if this known folder does not exist. /// </returns> public static string GetPath(out bool fileExists, IKnownFolderNative knownFolderNative) { string kfPath = null; fileExists = true; if (knownFolderNative == null) { fileExists = false; return(null); } // Virtual folders do not have path. if (knownFolderNative.GetCategory() == FolderCategory.Virtual) { fileExists = false; return(kfPath); } IntPtr ptrPath = default(IntPtr); try { knownFolderNative.GetPath(0, out ptrPath); if (ptrPath != default(IntPtr)) { kfPath = Marshal.PtrToStringUni(ptrPath); } } catch (System.IO.FileNotFoundException) { fileExists = false; } catch (System.IO.DirectoryNotFoundException) { fileExists = false; } finally { if (ptrPath != default(IntPtr)) { Marshal.FreeCoTaskMem(ptrPath); } } return(kfPath); }
/// <summary> /// Gets the path of this this known folder. /// </summary> /// <param name="fileExists"> /// Returns false if the folder is virtual, or a boolean /// value that indicates whether this known folder exists. /// </param> /// <param name="knownFolderNative">Native IKnownFolder reference</param> /// <returns> /// A <see cref="System.String"/> containing the path, or <see cref="System.String.Empty"/> if this known folder does not exist. /// </returns> private string GetPath(out bool fileExists, IKnownFolderNative knownFolderNative) { Debug.Assert(knownFolderNative != null); string kfPath = String.Empty; fileExists = true; // Virtual folders do not have path. if (knownFolderProperties.category == FolderCategory.Virtual) { fileExists = false; return kfPath; } try { kfPath = knownFolderNative.GetPath(0); } catch (System.IO.FileNotFoundException) { fileExists = false; } catch (System.IO.DirectoryNotFoundException) { fileExists = false; } return kfPath; }