/// <summary> /// Get the relative path from one file/directory to other. /// Thanks to Jozsef Bekes for the patch. /// </summary> /// <param name="fromType">Kind of file system "from" object (directory or file?)</param> /// <param name="fromPath">Absolute path of the file system "from" object</param> /// <param name="toType">Kind of file system "to" object (directory or file?)</param> /// <param name="toPath">Absolute path of the file system "to" object</param> /// <returns>The path of the "to" object relative to the "from" object. /// As example if, "from" is c:\foo\file.txt and "to" is c:\foo\bar\otherfile.txt, it will /// return ".\bar\otherfile.txt"</returns> /// <exception cref="ArgumentException">If "from" and "to" dont have a common root. /// As example "c:\foo.txt" and "d:\bar.txt" dont have it.</exception> public static string GetRelativePath(FSObjType fromType, string fromPath, FSObjType toType, string toPath) { int fromAttr = GetPathAttribute(fromPath, fromType); int toAttr = GetPathAttribute(toPath, toType); StringBuilder path = new StringBuilder(260); // MAX_PATH if (PathRelativePathTo( path, fromPath, fromAttr, toPath, toAttr) == 0) { throw new ArgumentException("Paths must have a common prefix"); } string filename = path.ToString(); // TODO: Check whats happening with unicode... // "xxxxx.htm" (where xxxxx is "vodka" translated to russian) is returning "?????.htm", // and PathRelativePathToW (unicode version) is not working.... if (filename.Contains("?")) { filename = toPath; } return(filename); }
/// <summary> /// Get win32 attribute value for file system object. /// Thanks to Jozsef Bekes for the patch. /// </summary> /// <param name="path">Path to the file system object</param> /// <param name="fsObjType">Kind of the file system object</param> /// <returns>FILE_ATTRIBUTE_DIRECTORY if the object is a directory. FILE_ATTRIBUTE_NORMAL /// if its a file</returns> /// <exception cref="FileNotFoundException">If fsObjType is eAuto and the object path does /// not exist.</exception> private static int GetPathAttribute(string path, FSObjType fsObjType) { switch (fsObjType) { case FSObjType.eDir: return(FILE_ATTRIBUTE_DIRECTORY); case FSObjType.eFile: return(FILE_ATTRIBUTE_NORMAL); default: DirectoryInfo di = new DirectoryInfo(path); if (di.Exists) { return(FILE_ATTRIBUTE_DIRECTORY); } FileInfo fi = new FileInfo(path); if (fi.Exists) { return(FILE_ATTRIBUTE_NORMAL); } throw new FileNotFoundException(); } }
public void DocumentFilter(FSObjType objType, bool isRecursive) { if (objType == FSObjType.Document) { CAMLQueryGenericFilter filterDocs = new CAMLQueryGenericFilter("FSObjType", FieldType.Integer, FSObjType.Document.ToString(), QueryType.Equal); ANDFilter(filterDocs); } else if (objType == FSObjType.Folder) { CAMLQueryGenericFilter filterFolders = new CAMLQueryGenericFilter("FSObjType", FieldType.Integer, FSObjType.Folder.ToString(), QueryType.Equal); ANDFilter(filterFolders); } IsRecursive = isRecursive; }
/// <summary> /// Get win32 attribute value for file system object. /// Thanks to Jozsef Bekes for the patch. /// </summary> /// <param name="path">Path to the file system object</param> /// <param name="fsObjType">Kind of the file system object</param> /// <returns>FILE_ATTRIBUTE_DIRECTORY if the object is a directory. FILE_ATTRIBUTE_NORMAL /// if its a file</returns> /// <exception cref="FileNotFoundException">If fsObjType is eAuto and the object path does /// not exist.</exception> private static int GetPathAttribute(string path, FSObjType fsObjType) { switch (fsObjType) { case FSObjType.eDir: return FILE_ATTRIBUTE_DIRECTORY; case FSObjType.eFile: return FILE_ATTRIBUTE_NORMAL; default: DirectoryInfo di = new DirectoryInfo(path); if (di.Exists) { return FILE_ATTRIBUTE_DIRECTORY; } FileInfo fi = new FileInfo(path); if (fi.Exists) { return FILE_ATTRIBUTE_NORMAL; } throw new FileNotFoundException(); } }
/// <summary> /// Get the relative path from one file/directory to other. /// Thanks to Jozsef Bekes for the patch. /// </summary> /// <param name="fromType">Kind of file system "from" object (directory or file?)</param> /// <param name="fromPath">Absolute path of the file system "from" object</param> /// <param name="toType">Kind of file system "to" object (directory or file?)</param> /// <param name="toPath">Absolute path of the file system "to" object</param> /// <returns>The path of the "to" object relative to the "from" object. /// As example if, "from" is c:\foo\file.txt and "to" is c:\foo\bar\otherfile.txt, it will /// return ".\bar\otherfile.txt"</returns> /// <exception cref="ArgumentException">If "from" and "to" dont have a common root. /// As example "c:\foo.txt" and "d:\bar.txt" dont have it.</exception> public static string GetRelativePath(FSObjType fromType, string fromPath, FSObjType toType, string toPath) { int fromAttr = GetPathAttribute(fromPath, fromType); int toAttr = GetPathAttribute(toPath, toType); StringBuilder path = new StringBuilder(260); // MAX_PATH if (PathRelativePathTo( path, fromPath, fromAttr, toPath, toAttr) == 0) { throw new ArgumentException("Paths must have a common prefix"); } string filename = path.ToString(); // TODO: Check whats happening with unicode... // "xxxxx.htm" (where xxxxx is "vodka" translated to russian) is returning "?????.htm", // and PathRelativePathToW (unicode version) is not working.... if( filename.Contains("?") ) filename = toPath; return filename; }