IFileAccess

by Daniel Marbach on December 29th, 2009
No notes
Syntax: C#
Show lines - Hide lines - Show in textbox - Download
  1. /// <summary>
  2. /// Interface which simplifies the access to the file system.
  3. /// </summary>
  4. public interface IFileAccess
  5. {
  6. /// <summary>
  7. /// Deletes the specified file. An exception is not thrown if the specified file
  8. /// does not exist.
  9. /// </summary>
  10. /// <param name="path">The name of the file to be deleted.</param>
  11. /// <exception cref="ArgumentException">path is a zero-length string, contains only
  12. /// white space, or contains one or more invalid characters as defined by
  13. /// System.IO.Path.InvalidPathChars.</exception>
  14. /// <exception cref="ArgumentNullException">path is null.</exception>
  15. /// <exception cref="DirectoryNotFoundException">The specified path is invalid,
  16. /// (for example, it is on an unmapped drive).</exception>
  17. /// <exception cref="IOException">The specified file is in use.</exception>
  18. /// <exception cref="NotSupportedException">path is in an invalid format.
  19. /// </exception>
  20. /// <exception cref="PathTooLongException">The specified path, file name, or both
  21. /// exceed the system-defined maximum length. For example, on Windows-based
  22. /// platforms, paths must be less than 248 characters, and file names must be less
  23. /// than 260 characters.</exception>
  24. /// <exception cref="UnauthorizedAccessException">The caller does not have the
  25. /// required permission. -or- path is a directory. -or- path specified a
  26. /// read-only file.
  27. /// </exception>
  28. void Delete(string path);
  29.  
  30. /// <summary>
  31. /// Creates or opens a file for writing UTF-8 encoded text.
  32. /// </summary>
  33. /// <param name="path">The file to be opened for writing.</param>
  34. /// <returns>A <see cref="System.IO.StreamWriter"/> that writes to the specified
  35. /// file using UTF-8 encoding.</returns>
  36. /// <exception cref="System.UnauthorizedAccessException">The caller does not have
  37. /// the required permission.</exception>
  38. /// <exception cref="System.ArgumentNullException">path is null.</exception>
  39. /// <exception cref="System.ArgumentException"> path is a zero-length string, contains only white space, or contains one or more invalid characters as defined by System.IO.Path.InvalidPathChars.</exception>
  40. /// <exception cref="System.IO.PathTooLongException">The specified path, file name, or both exceed the system-defined maximum length. For example, on Windows-based platforms, paths must be less than 248 characters, and file names must be less than 260 characters.</exception>
  41. /// <exception cref="System.IO.DirectoryNotFoundException">The specified path is invalid (for example, it is on an unmapped drive).</exception>
  42. /// <exception cref="System.NotSupportedException">path is in an invalid format.</exception>
  43. StreamWriter CreateText(string path);
  44.  
  45. /// <summary>
  46. /// Gets the <see cref="FileAttributes"/> of the file on the path.
  47. /// </summary>
  48. /// <param name="path">The path to the file.</param>
  49. /// <returns>The <see cref="FileAttributes"/> of the file on the path</returns>
  50. /// <exception cref="ArgumentException">path is empty, contains only white spaces,
  51. /// or contains invalid characters.</exception>
  52. /// <exception cref="PathTooLongException">The specified path, file name, or both
  53. /// exceed the system-defined maximum length. For example, on Windows-based
  54. /// platforms, paths must be less than 248 characters, and file names must be less
  55. /// than 260 characters.</exception>
  56. /// <exception cref="NotSupportedException">path is in an invalid format.
  57. /// </exception>
  58. /// <exception cref="FileNotFoundException">path represents a file and is invalid,
  59. /// such as being on an unmapped drive, or the file cannot be found.</exception>
  60. /// <exception cref="DirectoryNotFoundException">path represents a directory and is
  61. /// invalid, such as being on an unmapped drive, or the directory cannot be found.
  62. /// </exception>
  63. FileAttributes GetAttributes(string path);
  64.  
  65. /// <summary>
  66. /// Sets the date and time that the specified file was last written to.
  67. /// </summary>
  68. /// <param name="path">The file for which to set the date and time information.
  69. /// </param>
  70. /// <param name="lastWriteTime">A <see cref="System.DateTime"/> containing the
  71. /// value to set for the last write date and time of path. This value is expressed
  72. /// in local time.</param>
  73. /// <exception cref="System.ArgumentOutOfRangeException">
  74. /// <paramref name="lastWriteTime"/> specifies a value outside the range of dates
  75. /// or times permitted for this operation.</exception>
  76. /// <exception cref="System.ArgumentException">path is a zero-length string,
  77. /// contains only white space, or contains one or more invalid characters as
  78. /// defined by System.IO.Path.InvalidPathChars.</exception>
  79. /// <exception cref="System.ArgumentNullException">path is null.</exception>
  80. /// <exception cref="System.IO.PathTooLongException">The specified path, file name,
  81. /// or both exceed the system-defined maximum length. For example, on Windows-based
  82. /// platforms, paths must be less than 248 characters, and file names must be less
  83. /// than 260 characters.</exception>
  84. /// <exception cref="System.IO.FileNotFoundException">The specified path was not
  85. /// found.</exception>
  86. /// <exception cref="System.UnauthorizedAccessException">The caller does not have
  87. /// the required permission.</exception>
  88. /// <exception cref="System.NotSupportedException">path is in an invalid format.
  89. /// </exception>
  90. void SetLastWriteTime(string path, DateTime lastWriteTime);
  91.  
  92. /// <summary>
  93. /// Sets the specified <see cref="FileAttributes"/> of the file on the specified
  94. /// path.
  95. /// </summary>
  96. /// <param name="path">The path to the file.</param>
  97. /// <param name="fileAttributes">The desired <see cref="FileAttributes"/>, such as
  98. /// Hidden, ReadOnly, Normal, and Archive.</param>
  99. /// <exception cref="ArgumentException">path is empty, contains only white spaces,
  100. /// contains invalid characters, or the file attribute is invalid.</exception>
  101. /// <exception cref="PathTooLongException">The specified path, file name, or both
  102. /// exceed the system-defined maximum length. For example, on Windows-based
  103. /// platforms, paths must be less than 248 characters, and file names must be less
  104. /// than 260 characters.</exception>
  105. /// <exception cref="NotSupportedException">path is in an invalid format.
  106. /// </exception>
  107. /// <exception cref="DirectoryNotFoundException">The specified path is invalid,
  108. /// (for example, it is on an unmapped drive).</exception>
  109. /// <exception cref="FileNotFoundException">The file cannot be found.</exception>
  110. /// <exception cref="UnauthorizedAccessException">path specified a file that is
  111. /// read-only. -or- This operation is not supported on the current platform. -or-
  112. /// path specified a directory. -or- The caller does not have the required
  113. /// permission.</exception>
  114. void SetAttributes(string path, FileAttributes fileAttributes);
  115.  
  116. /// <summary>
  117. /// Determines whether the specified file exists.
  118. /// </summary>
  119. /// <param name="path">The file to check.</param>
  120. /// <returns>true if the caller has the required permissions and path contains the
  121. /// name of an existing file; otherwise, false. This method also returns false if
  122. /// path is null, an invalid path, or a zero-length string. If the caller does not
  123. /// have sufficient permissions to read the specified file, no exception is thrown
  124. /// and the method returns false regardless of the existence of path.</returns>
  125. bool Exists(string path);
  126.  
  127. /// <summary>
  128. /// Opens a binary file, reads the contents of the file into a byte array, and then
  129. /// closes the file.
  130. /// </summary>
  131. /// <param name="path">The file to open for reading.</param>
  132. /// <returns>An enumerable containing the contents of the file.</returns>
  133. /// <exception cref="ArgumentException"> path is a zero-length string, contains
  134. /// only white space, or contains one or more invalid characters as defined by
  135. /// System.IO.Path.InvalidPathChars.</exception>
  136. /// <exception cref="ArgumentNullException"> path is null.</exception>
  137. /// <exception cref="PathTooLongException"> The specified path, file name, or both
  138. /// exceed the system-defined maximum length. For example, on Windows-based
  139. /// platforms, paths must be less than 248 characters, and file names must be less
  140. /// than 260 characters.</exception>
  141. /// <exception cref="DirectoryNotFoundException"> The specified path is invalid
  142. /// (for example, it is on an unmapped drive).</exception>
  143. /// <exception cref="IOException"> An I/O error occurred while opening the file.
  144. /// </exception>
  145. /// <exception cref="UnauthorizedAccessException"> This operation is not supported
  146. /// on the current platform. -or- path specified a directory. -or- The caller
  147. /// does not have the required permission.</exception>
  148. /// <exception cref="FileNotFoundException"> The file specified in path was not
  149. /// found.</exception>
  150. /// <exception cref="NotSupportedException"> path is in an invalid format.
  151. /// </exception>
  152. /// <exception cref="SecurityException">The caller does not have the required permission.</exception>
  153. IEnumerable<byte> ReadAllBytes(string path);
  154.  
  155. /// <summary>
  156. /// Opens a file, reads all lines of the file with the specified encoding, and then closes the file.
  157. /// </summary>
  158. /// <param name="path">The file to open for reading.</param>
  159. /// <param name="encoding">The encoding applied to the contents of the file.</param>
  160. /// <returns>An enumerable containing all lines of the file.</returns>
  161. /// <exception cref="ArgumentException"> path is a zero-length string, contains
  162. /// only white space, or contains one or more invalid characters as defined by
  163. /// System.IO.Path.InvalidPathChars.</exception>
  164. /// <exception cref="ArgumentNullException"> path is null.</exception>
  165. /// <exception cref="PathTooLongException"> The specified path, file name, or both
  166. /// exceed the system-defined maximum length. For example, on Windows-based
  167. /// platforms, paths must be less than 248 characters, and file names must be less
  168. /// than 260 characters.</exception>
  169. /// <exception cref="DirectoryNotFoundException"> The specified path is invalid
  170. /// (for example, it is on an unmapped drive).</exception>
  171. /// <exception cref="IOException"> An I/O error occurred while opening the file.
  172. /// </exception>
  173. /// <exception cref="UnauthorizedAccessException"> This operation is not supported
  174. /// on the current platform. -or- path specified a directory. -or- The caller
  175. /// does not have the required permission.</exception>
  176. /// <exception cref="FileNotFoundException"> The file specified in path was not
  177. /// found.</exception>
  178. /// <exception cref="NotSupportedException"> path is in an invalid format.
  179. /// </exception>
  180. /// <exception cref="SecurityException">The caller does not have the required permission.</exception>
  181. IEnumerable<string> ReadAllLines(string path, Encoding encoding);
  182.  
  183. /// <summary>
  184. /// Opens a text file, reads all lines of the file, and then closes the file.
  185. /// </summary>
  186. /// <param name="path">The file to open for reading.</param>
  187. /// <returns>An enumerable containing all lines of the file.</returns>
  188. /// <exception cref="ArgumentException"> path is a zero-length string, contains
  189. /// only white space, or contains one or more invalid characters as defined by
  190. /// System.IO.Path.InvalidPathChars.</exception>
  191. /// <exception cref="ArgumentNullException"> path is null.</exception>
  192. /// <exception cref="PathTooLongException"> The specified path, file name, or both
  193. /// exceed the system-defined maximum length. For example, on Windows-based
  194. /// platforms, paths must be less than 248 characters, and file names must be less
  195. /// than 260 characters.</exception>
  196. /// <exception cref="DirectoryNotFoundException"> The specified path is invalid
  197. /// (for example, it is on an unmapped drive).</exception>
  198. /// <exception cref="IOException"> An I/O error occurred while opening the file.
  199. /// </exception>
  200. /// <exception cref="UnauthorizedAccessException"> This operation is not supported
  201. /// on the current platform. -or- path specified a directory. -or- The caller
  202. /// does not have the required permission.</exception>
  203. /// <exception cref="FileNotFoundException"> The file specified in path was not
  204. /// found.</exception>
  205. /// <exception cref="NotSupportedException"> path is in an invalid format.
  206. /// </exception>
  207. /// <exception cref="SecurityException">The caller does not have the required permission.</exception>
  208. IEnumerable<string> ReadAllLines(string path);
  209.  
  210. /// <summary>
  211. /// Opens a file, reads all lines of the file with the specified encoding, and then closes the file.
  212. /// </summary>
  213. /// <param name="path">The file to open for reading.</param>
  214. /// <param name="encoding">The encoding applied to the contents of the file.</param>
  215. /// <returns>A string containing all lines of the file.</returns>
  216. /// <exception cref="ArgumentException"> path is a zero-length string, contains
  217. /// only white space, or contains one or more invalid characters as defined by
  218. /// System.IO.Path.InvalidPathChars.</exception>
  219. /// <exception cref="ArgumentNullException"> path is null.</exception>
  220. /// <exception cref="PathTooLongException"> The specified path, file name, or both
  221. /// exceed the system-defined maximum length. For example, on Windows-based
  222. /// platforms, paths must be less than 248 characters, and file names must be less
  223. /// than 260 characters.</exception>
  224. /// <exception cref="DirectoryNotFoundException"> The specified path is invalid
  225. /// (for example, it is on an unmapped drive).</exception>
  226. /// <exception cref="IOException"> An I/O error occurred while opening the file.
  227. /// </exception>
  228. /// <exception cref="UnauthorizedAccessException"> This operation is not supported
  229. /// on the current platform. -or- path specified a directory. -or- The caller
  230. /// does not have the required permission.</exception>
  231. /// <exception cref="FileNotFoundException"> The file specified in path was not
  232. /// found.</exception>
  233. /// <exception cref="NotSupportedException"> path is in an invalid format.
  234. /// </exception>
  235. /// <exception cref="SecurityException">The caller does not have the required permission.</exception>
  236. string ReadAllText(string path, Encoding encoding);
  237.  
  238. /// <summary>
  239. /// Opens a file, reads all lines of the file with the specified encoding, and then closes the file.
  240. /// </summary>
  241. /// <param name="path">The file to open for reading.</param>
  242. /// <returns>A string containing all lines of the file.</returns>
  243. /// <exception cref="ArgumentException"> path is a zero-length string, contains
  244. /// only white space, or contains one or more invalid characters as defined by
  245. /// System.IO.Path.InvalidPathChars.</exception>
  246. /// <exception cref="ArgumentNullException"> path is null.</exception>
  247. /// <exception cref="PathTooLongException"> The specified path, file name, or both
  248. /// exceed the system-defined maximum length. For example, on Windows-based
  249. /// platforms, paths must be less than 248 characters, and file names must be less
  250. /// than 260 characters.</exception>
  251. /// <exception cref="DirectoryNotFoundException"> The specified path is invalid
  252. /// (for example, it is on an unmapped drive).</exception>
  253. /// <exception cref="IOException"> An I/O error occurred while opening the file.
  254. /// </exception>
  255. /// <exception cref="UnauthorizedAccessException"> This operation is not supported
  256. /// on the current platform. -or- path specified a directory. -or- The caller
  257. /// does not have the required permission.</exception>
  258. /// <exception cref="FileNotFoundException"> The file specified in path was not
  259. /// found.</exception>
  260. /// <exception cref="NotSupportedException"> path is in an invalid format.
  261. /// </exception>
  262. /// <exception cref="SecurityException">The caller does not have the required permission.</exception>
  263. string ReadAllText(string path);
  264. }

Leave a Reply

Note: XHTML is allowed. Your email address will never be published.

Subscribe to this comment feed via RSS