/// <summary> /// Opens the specified file. /// </summary> /// <param name="path"> /// A <see cref="String"/> containing the path of the file to open. /// </param> /// <param name="access"> /// One of the <see cref="FileAccess"/> value that specifies the operations that can be /// performed on the file. /// </param> /// <param name="mode"> /// One of the <see cref="FileMode"/> values that specifies whether a file is created /// if one does not exist, and determines whether the contents of existing files are /// retained or overwritten. /// </param> /// <param name="share"> /// One of the <see cref="FileShare"/> values specifying the type of access other threads /// have to the file. /// </param> /// <returns> /// A <see cref="FileStream"/> that provides access to the file specified in /// <paramref name="path"/>. /// </returns> /// <exception cref="ArgumentNullException"> /// <paramref name="path"/> is <see langword="null"/>. /// </exception> /// <exception cref="ArgumentException"> /// <paramref name="path"/> is an empty string (""), contains only white /// space, or contains one or more invalid characters as defined in /// <see cref="Path.GetInvalidPathChars()"/>. /// <para> /// -or- /// </para> /// <paramref name="path"/> contains one or more components that exceed /// the drive-defined maximum length. For example, on Windows-based /// platforms, components must not exceed 255 characters. /// </exception> /// <exception cref="PathTooLongException"> /// <paramref name="path"/> exceeds the system-defined maximum length. /// For example, on Windows-based platforms, paths must not exceed /// 32,000 characters. /// </exception> /// <exception cref="DirectoryNotFoundException"> /// One or more directories in <paramref name="path"/> could not be found. /// </exception> /// <exception cref="UnauthorizedAccessException"> /// The caller does not have the required access permissions. /// <para> /// -or- /// </para> /// <paramref name="path"/> refers to a file that is read-only and <paramref name="access"/> /// is not <see cref="FileAccess.Read"/>. /// <para> /// -or- /// </para> /// <paramref name="path"/> is a directory. /// </exception> /// <exception cref="IOException"> /// <paramref name="path"/> refers to a file that is in use. /// <para> /// -or- /// </para> /// <paramref name="path"/> specifies a device that is not ready. /// </exception> public static FileStream Open(string path, FileMode mode, FileAccess access, FileShare share) { if (Common.IsRunningOnMono() && Common.IsPlatformUnix()) { return(SysFile.Open(path, mode, access, share)); } return(Open(path, mode, access, share, 0, FileOptions.None)); }
public static FileStream Open(string path, FileMode mode) { if (Common.IsRunningOnMono() && Common.IsPlatformUnix()) { return(SysFile.Open(path, mode)); } return(File.Open(path, mode, (mode == FileMode.Append ? FileAccess.Write : FileAccess.ReadWrite), FileShare.None)); }