当前位置: 首页>>代码示例>>C#>>正文


C# FileMode类代码示例

本文整理汇总了C#中FileMode的典型用法代码示例。如果您正苦于以下问题:C# FileMode类的具体用法?C# FileMode怎么用?C# FileMode使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


FileMode类属于命名空间,在下文中一共展示了FileMode类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: Compress

 public void Compress(string sourceFilename, string targetFilename, FileMode fileMode, OutArchiveFormat archiveFormat,
     CompressionMethod compressionMethod, CompressionLevel compressionLevel, ZipEncryptionMethod zipEncryptionMethod,
     string password, int bufferSize, int preallocationPercent, bool check, Dictionary<string, string> customParameters)
 {
     bufferSize *= this._sectorSize;
     SevenZipCompressor compressor = new SevenZipCompressor();
     compressor.FastCompression = true;
     compressor.ArchiveFormat = archiveFormat;
     compressor.CompressionMethod = compressionMethod;
     compressor.CompressionLevel = compressionLevel;
     compressor.DefaultItemName = Path.GetFileName(sourceFilename);
     compressor.DirectoryStructure = false;
     compressor.ZipEncryptionMethod = zipEncryptionMethod;
     foreach (var pair in customParameters)
     {
         compressor.CustomParameters[pair.Key] = pair.Value;
     }
     using (FileStream sourceFileStream = new FileStream(sourceFilename,
         FileMode.Open, FileAccess.Read, FileShare.None, bufferSize,
         Win32.FileFlagNoBuffering | FileOptions.SequentialScan))
     {
         using (FileStream targetFileStream = new FileStream(targetFilename,
                fileMode, FileAccess.ReadWrite, FileShare.ReadWrite, 8,
                FileOptions.WriteThrough | Win32.FileFlagNoBuffering))
         {
             this.Compress(compressor, sourceFileStream, targetFileStream,
                 password, preallocationPercent, check, bufferSize);
         }
     }
 }
开发者ID:simony,项目名称:WinUtils,代码行数:30,代码来源:LocalArch.cs

示例2: FileModeChanged

 private static void FileModeChanged(string[] assets, FileMode mode)
 {
     if (Provider.enabled && Provider.PromptAndCheckoutIfNeeded(assets, ""))
     {
         Provider.SetFileMode(assets, mode);
     }
 }
开发者ID:CarlosHBC,项目名称:UnityDecompiled,代码行数:7,代码来源:AssetModificationProcessorInternal.cs

示例3: Open

	/**
     * open file.
     * @param void.
     * @return void.
     */
	public bool Open(string strFileName, FileMode eMode, FileAccess eAccess)
	{
		if (string.IsNullOrEmpty(strFileName))
		{
			return false;
		}
		
		if ((FileMode.Open == eMode) && !File.Exists(strFileName))
		{
			return false;
		}
		
		try
		{
			m_cStream = new FileStream(strFileName, eMode, eAccess);
		}
		catch (Exception cEx)
		{
			Console.Write(cEx.Message);
		}
		
		if (null == m_cStream)
		{
			return false;
		}
		
		m_bOpen = true;
		return true;
	}
开发者ID:602147629,项目名称:2DPlatformer-SLua,代码行数:34,代码来源:YwArchiveBinFile.cs

示例4: FileOpen

		public Stream FileOpen(string filePath, FileMode fileMode, FileAccess fileAccess, FileShare fileShare)
		{
#if WINDOWS_STORE_APP
			var folder = ApplicationData.Current.LocalFolder;
			if (fileMode == FileMode.Create || fileMode == FileMode.CreateNew)
			{
				return folder.OpenStreamForWriteAsync(filePath, CreationCollisionOption.ReplaceExisting).GetAwaiter().GetResult();
			}
			else if (fileMode == FileMode.OpenOrCreate)
			{
				if (fileAccess == FileAccess.Read)
					return folder.OpenStreamForReadAsync(filePath).GetAwaiter().GetResult();
				else
				{
					// Not using OpenStreamForReadAsync because the stream position is placed at the end of the file, instead of the beginning
					var f = folder.CreateFileAsync(filePath, CreationCollisionOption.OpenIfExists).AsTask().GetAwaiter().GetResult();
					return f.OpenAsync(FileAccessMode.ReadWrite).AsTask().GetAwaiter().GetResult().AsStream();
				}
			}
			else if (fileMode == FileMode.Truncate)
			{
				return folder.OpenStreamForWriteAsync(filePath, CreationCollisionOption.ReplaceExisting).GetAwaiter().GetResult();
			}
			else
			{
				//if (fileMode == FileMode.Append)
				// Not using OpenStreamForReadAsync because the stream position is placed at the end of the file, instead of the beginning
				folder.CreateFileAsync(filePath, CreationCollisionOption.OpenIfExists).AsTask().GetAwaiter().GetResult().OpenAsync(FileAccessMode.ReadWrite).AsTask().GetAwaiter().GetResult().AsStream();
				var f = folder.CreateFileAsync(filePath, CreationCollisionOption.OpenIfExists).AsTask().GetAwaiter().GetResult();
				return f.OpenAsync(FileAccessMode.ReadWrite).AsTask().GetAwaiter().GetResult().AsStream();
			}
#else
			return File.Open(filePath, fileMode, fileAccess, fileShare);
#endif
		}
开发者ID:jandujar,项目名称:AdrotatorV2,代码行数:35,代码来源:FileHelpers.cs

示例5: OpenFileStream

        /// <summary>
        /// File might be locked when attempting to open it. This will attempt to open the file the number of times specified by <paramref name="retry"/>
        /// </summary>
        /// <param name="filePath">The file to attempt to get a file stream for</param>
        /// <param name="retry">The number of times a file open should be attempted</param>
        /// <param name="fileMode">The file mode to use</param>
        /// <param name="fileAccess">The file access to use</param>
        /// <param name="fileShare">The file sharing to use</param>
        /// <returns>A file stream of the file</returns>
        /// <remarks>
        /// It attempt to open the file in increasingly longer periods and throw an exception if it cannot open it within the
        /// specified number of retries.
        /// </remarks>
        public Stream OpenFileStream(string filePath, int retry, FileMode fileMode, FileAccess fileAccess, FileShare fileShare)
        {
            var delay = 0;

            for(var i = 0; i < retry; i++)
            {
                try
                {
                    var stream = new FileStream(filePath, fileMode, fileAccess, fileShare);
                    return stream;
                }
                catch(DirectoryNotFoundException)
                {
                    CreateDirectoryStructure(filePath);
                }
                catch(FileNotFoundException)
                {
                    throw;
                }
                catch(IOException)
                {
                    delay += 100;
                    if(i == retry) throw;
                }
                Thread.Sleep(delay);
            }

            //We will never get here
            throw new IOException(string.Format("Unable to open file '{0}'", filePath));
        }
开发者ID:Worthaboutapig,项目名称:SquishIt,代码行数:43,代码来源:RetryableFileOpener.cs

示例6: RemoteFileSystemFileStream

		public RemoteFileSystemFileStream(RemoteFileSystem RemoteFileSystem, String FileName, FileMode FileMode)
			: base(RemoteFileSystem, (Lazy<Stream>)null)
		{
			this.RemoteFileSystem = RemoteFileSystem;
			this.FileName = FileName;
			this.FileMode = FileMode;
		}
开发者ID:soywiz,项目名称:csharputils,代码行数:7,代码来源:RemoteFileSystemFileStream.cs

示例7: CreateFile

 private static extern SafeFileHandle CreateFile(string filename,
                                FileAccess desiredAccess,
                                FileShare shareMode,
                                IntPtr attributes,
                                FileMode creationDisposition,
                                uint flagsAndAttributes = 0,
                                IntPtr templateFile = default(IntPtr));
开发者ID:EkardNT,项目名称:Roslyn,代码行数:7,代码来源:Kernel32File.cs

示例8: FileAccess

		internal static void FileAccess(FileMode fileMode, FileAccess fileAccess)
		{
			// exception if:

			// !write && append
			// !write && create
			// !write && createNew
			// !write && truncate

			var noWrite = (fileAccess & System.IO.FileAccess.Write) == 0;
			if (noWrite && fileMode == FileMode.CreateNew)
				throw new ArgumentException(string.Format(
					"Can only open files in {0} mode when requesting FileAccess.Write access.", fileMode));

			if (noWrite && fileMode == FileMode.Truncate)
				throw new IOException("Cannot truncate a file if file mode doesn't include WRITE.");

			// or if:
			// readwrite && append
			// read && append

			if (fileAccess == System.IO.FileAccess.Read && fileMode == FileMode.Append)
				throw new ArgumentException("Cannot open file in read-mode when having FileMode.Append");

			//if (
			//    ((fileMode == FileMode.Append) && fileAccess != FileAccess.Write) ||
			//    ((fileMode == FileMode.CreateNew || fileMode == FileMode.Create || fileMode == FileMode.Truncate)
			//     && (fileAccess != FileAccess.Write && fileAccess != FileAccess.ReadWrite)) ||
			//    false //((Exists && fileMode == FileMode.OpenOrCreate && fileAccess == FileAccess.Write))
			//    )
		}
开发者ID:bittercoder,项目名称:Windsor,代码行数:31,代码来源:Validate.cs

示例9: FromFile

        public static IStream FromFile(string fileName, FileMode mode, StreamInfo streamInfo)
        {
            if (fileName == null)
                throw new ArgumentNullException("fileName");

            return FromStream(File.Open(fileName, mode), streamInfo ?? StreamInfo.FromFile(fileName));
        }
开发者ID:netide,项目名称:netide,代码行数:7,代码来源:StreamUtil.cs

示例10: SerializeToFile

 public static void SerializeToFile(object obj, string file, FileMode fileMode, XmlSerializerNamespaces namespaces, bool omitXmlDeclaration)
 {
     using (FileStream fileStream = new FileStream(file, fileMode))
     {
         SerializeToStream(obj, fileStream, namespaces, omitXmlDeclaration);
     }
 }
开发者ID:hoobiedoo,项目名称:MOSProtocol.Serialization,代码行数:7,代码来源:XmlSerializerHelper.cs

示例11: GetMode

 // uint GetMode( FileMode mode )
 // Converts the filemode constant to win32 constant
 #region GetMode
 private static uint GetMode(FileMode mode)
 {
     uint umode = 0;
     switch (mode)
     {
         case FileMode.CreateNew:
             umode = CREATE_NEW;
             break;
         case FileMode.Create:
             umode = CREATE_ALWAYS;
             break;
         case FileMode.Append:
             umode = OPEN_ALWAYS;
             break;
         case FileMode.Open:
             umode = OPEN_EXISTING;
             break;
         case FileMode.OpenOrCreate:
             umode = OPEN_ALWAYS;
             break;
         case FileMode.Truncate:
             umode = TRUNCATE_EXISTING;
             break;
     }
     return umode;
 }
开发者ID:BigDaddy1337,项目名称:DocsReader,代码行数:29,代码来源:Win32File.cs

示例12: Output

 public Output(string filename, FileMode mode)
 {
     StandardOutput = IsStandardOutput(filename);
     Name = StandardOutput ? "(standard output)" : filename;
     Mode = mode;
     Open = () => StandardOutput ? Console.OpenStandardOutput() : File.Open(Name, Mode);
 }
开发者ID:neochrome,项目名称:nutools,代码行数:7,代码来源:Output.cs

示例13: CreateFile

 private static extern IntPtr CreateFile(string fileName, 
     FILE_ACCESS_RIGHTS access,
     FileShare share,
     int securityAttributes,
     FileMode creation,
     FILE_FLAGS flags,
     IntPtr templateFile);
开发者ID:nefarius,项目名称:AnnoyingFlooder,代码行数:7,代码来源:AnnoyingFlooder.cs

示例14: CreateFile

 public static extern SafeFileHandle CreateFile(String fileName,
     FileAccess desiredAccess,
     FileShare shareMode,
     IntPtr securityAttrs,
     FileMode creationDisposition,
     int flagsAndAttributes,
     IntPtr templateFile);
开发者ID:SzymonPobiega,项目名称:FlushFileBuffersTest,代码行数:7,代码来源:Program.cs

示例15: ShapefileWriter

        protected ShapefileWriter(string path, ShapefileHeader header, FileMode fileMode, FileAccess fileAccess)
        {
            _writerShape = new BinaryWriter(new FileStream(path, fileMode, fileAccess));
            _writerIndex = new BinaryWriter(new FileStream(Path.ChangeExtension(path, ".shx"), fileMode, fileAccess));

            _header = header;
        }
开发者ID:interworks,项目名称:FastShapefile,代码行数:7,代码来源:ShapefileWriter.cs


注:本文中的FileMode类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。