• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

C# FileMode类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

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



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


示例16: WriteFile

        private void WriteFile(string filename, byte[] content, FileMode fileMode)
        {
            Stream target = null;
            BinaryWriter writer = null;

            try
            {
                target = File.Open(filename, fileMode);
                writer = new BinaryWriter(target);

                writer.Write(content);
            }
            catch (Exception ex)
            {
                throw new Exception("Could not write to file: " + filename + " - " + ex.Message);
            }
            finally
            {
                if (target != null)
                {
                    target.Close();
                }
                if (writer != null)
                {
                    writer.Close();
                }
            }
        }
开发者ID:Pamilator,项目名称:mylivemesh-epitech2013,代码行数:28,代码来源:FileUploadService.asmx.cs


示例17: WriteTextToFile

    public static void WriteTextToFile(string strFilePath, string strText, FileMode fileMode)
    {
        StreamWriter SW = File.AppendText(strFilePath);
        FileStream FS;
        char[] arrChar = strText.ToCharArray();

        try
        {
            if(FileExists(strFilePath))
            {
                SW.WriteLine(strText);
            }
            else
            {
                FS = File.Open(strFilePath, fileMode);

                for(int i = 0; i < strText.Length; i++)
                {
                    FS.WriteByte(Convert.ToByte(arrChar[i]));
                }
                FS.Flush();
                FS.Close();
            }
        }
        catch
        {
        }
        finally
        {
            SW.Flush();
            SW.Close();
        }
    }
开发者ID:marcsstevenson,项目名称:DataToSQL,代码行数:33,代码来源:clsFileController.cs


示例18: Open

 public override void Open(FileMode mode = FileMode.OpenOrCreate)
 {
     if (this.isOpen)
     {
         Console.WriteLine("DataFile::Open File is already open: " + this.name);
         return;
     }
     if (!this.OpenFileStream(this.name, mode))
     {
         this.beginPosition = 62L;
         this.endPosition = 62L;
         this.keysPosition = 62L;
         this.freePosition = 62L;
         this.keysLength = 0;
         this.freeLength = 0;
         this.keysNumber = 0;
         this.freeNumber = 0;
         this.isModified = true;
         base.WriteHeader();
     }
     else
     {
         if (!base.ReadHeader())
         {
             Console.WriteLine("DataFile::Open Error opening file " + this.name);
             return;
         }
         base.ReadKeys();
         base.ReadFree();
     }
     this.isOpen = true;
 }
开发者ID:ForTrade,项目名称:CSharp,代码行数:32,代码来源:NetDataFile.cs


示例19: Process

		public void Process(FileMode mode, bool agreement)
		{
			PropertyBag["mode"] = mode;
			PropertyBag["agreement"] = agreement;
			
			RenderView("result");
		}
开发者ID:nats,项目名称:castle-1.0.3-mono,代码行数:7,代码来源:RadioSampleController.cs


示例20: 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="fileInfo">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 FileStream OpenFileStream(FileInfo fileInfo, int retry, FileMode fileMode, FileAccess fileAccess, FileShare fileShare)
        {
            var delay = 0;

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

                Thread.Sleep(delay);
            }

            //We will never get here
            throw new IOException("Unable to open file - " + fileInfo.FullName);
        }
开发者ID:atifaziz,项目名称:talifun-web,代码行数:40,代码来源:RetryableFileOpener.cs



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


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
C# FileName类代码示例发布时间:2022-05-24
下一篇:
C# FileManager类代码示例发布时间:2022-05-24
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap