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


C# FileInfo.Open方法代码示例

本文整理汇总了C#中System.IO.FileInfo.Open方法的典型用法代码示例。如果您正苦于以下问题:C# FileInfo.Open方法的具体用法?C# FileInfo.Open怎么用?C# FileInfo.Open使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在System.IO.FileInfo的用法示例。


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

示例1: SaveFile

 public void SaveFile(string fileName, IList<Shape> shapes)
 {
     var fileInfo = new FileInfo(fileName);
     try
     {
         if (fileInfo.Exists)
         {
             using (var fileStream = fileInfo.Open(FileMode.Truncate, FileAccess.ReadWrite))
             {
                 SerializeAndSave(shapes, fileStream);
             }
         }
         else
         {
             using (var fileStream = fileInfo.Open(FileMode.CreateNew, FileAccess.ReadWrite))
             {
                 SerializeAndSave(shapes, fileStream);
             }
         }
     }
     catch (Exception exception)
     {
        ThrowMeaningfulException(exception, fileName);
     }
 }
开发者ID:CraigEng,项目名称:HueShape,代码行数:25,代码来源:DocumentLogic.cs

示例2: DeleteAppVersionIndexEntry

 public void DeleteAppVersionIndexEntry(Guid appKey)
 {
     var localAppIndexFile = new FileInfo(config.DeploymentDirectory + STR_LOCAL_APP_INDEX_FILE);
     string serialised;
     if (localAppIndexFile.Exists)
     {
         List<Plywood.Internal.EntityIndexEntry> index;
         using (var stream = localAppIndexFile.Open(FileMode.Open, FileAccess.Read))
         {
             index = Internal.Indexes.ParseIndex(stream);
         }
         if (index.Any(e => e.Key == appKey))
         {
             index.RemoveAll(e => e.Key == appKey);
             index.Sort(delegate(Internal.EntityIndexEntry a, Internal.EntityIndexEntry b)
             {
                 return string.Compare(a.Name, b.Name, true);
             });
             serialised = Internal.Indexes.SerialiseIndex(index);
             using (var stream = localAppIndexFile.Open(FileMode.Create, FileAccess.Write))
             {
                 var writer = new StreamWriter(stream);
                 writer.Write(serialised);
                 writer.Flush();
                 stream.Flush();
             }
         }
     }
 }
开发者ID:danielrbradley,项目名称:Plywood,代码行数:29,代码来源:AppDeployment.cs

示例3: CreateProcessor

 /// <summary>
 /// Creates a processor that corresponds to this command.
 /// </summary>
 /// <returns></returns>
 public override ProcessorBase CreateProcessor()
 {
     var outputFile = new FileInfo(this.File);
     if (outputFile.Exists)
     {
         return new ProcessorTarget(new PBFOsmStreamTarget(outputFile.Open(FileMode.Truncate)));
     }
     return new ProcessorTarget(new PBFOsmStreamTarget(outputFile.Open(FileMode.Create)));
 }
开发者ID:ltbam,项目名称:odp,代码行数:13,代码来源:CommandWritePBF.cs

示例4: CreateFile

 static void CreateFile()
 {
     FileInfo f = new FileInfo(filename);
     if (f.Exists)
     {
         Console.WriteLine("Файл уже существует. Пересоздать? yes/no");
         if (Console.ReadLine() == "yes")
             using (FileStream fs = f.Open(FileMode.Create)) { }
     }
     else
         using (FileStream fs = f.Open(FileMode.CreateNew)) { }
     Console.WriteLine("Готово!");
 }
开发者ID:NikitaVas,项目名称:CSharp,代码行数:13,代码来源:Program.cs

示例5: CreateOrAppendToFile

 public void CreateOrAppendToFile(string fileLocation, Stream stream)
 {
     var sourcePath = Path.Combine(DebugConfig.LocalStoragePath, fileLocation);
     var fileInfo = new FileInfo(sourcePath);
     if (fileInfo.Exists)
     {
         using (var streamWrite = fileInfo.Open(FileMode.Append, FileAccess.Write))
             stream.CopyTo(streamWrite);
     }
     else
     {
         using (var streamWrite = fileInfo.Open(FileMode.Create, FileAccess.Write))
             stream.CopyTo(streamWrite);
     }
 }
开发者ID:andrerpena,项目名称:Cerebello,代码行数:15,代码来源:LocalStorageService.cs

示例6: Save

        public void Save(string fileName)
        {
            var file = new FileInfo(fileName);
            using (FileStream stream = file.Open(FileMode.Create, FileAccess.Write))
            {
                using (var writer = new BinaryWriter(stream, Encoding.Unicode))
                {
                    writer.Write(Encoding.ASCII.GetBytes("gufont"));

                    byte[] nameBytes = Encoding.UTF8.GetBytes(FontName);
                    writer.Write(nameBytes.Length);
                    writer.Write(nameBytes);

                    writer.Write((int)Style);
                    writer.Write(UnitsPerEm);
                    writer.Write(ascend);
                    writer.Write(descend);
                    writer.Write(lineGap);

                    writer.Write(glyphDictionary.Count);
                    foreach (var kvp in glyphDictionary)
                    {
                        writer.Write(kvp.Key);
                        writer.Write(kvp.Value);
                    }

                    writer.Write(glyphs.Length);
                    foreach (var glyph in glyphs)
                        glyph.Save(writer);
                }
            }
        }
开发者ID:Artentus,项目名称:GameUtils,代码行数:32,代码来源:GameUtilsFont.cs

示例7: AeroWindow_Loaded

        private void AeroWindow_Loaded(object sender, RoutedEventArgs e)
        {
            className = null;
            var info = new FileInfo(path);
            if (!info.Exists)
            {
                MessageBox.Show(string.Format("File \"{0}\" doesn't exist!", path), "Error!", MessageBoxButton.OK, MessageBoxImage.Error);
                Close();
                return;
            }

            try
            {
                var buffer = info.Open(FileMode.Open).ReadToBuffer();
                var assembly = Assembly.Load(buffer);
                listTaskClasses.ItemsSource = from type in assembly.GetExportedTypes()
                                              where (from interf in type.GetInterfaces()
                                                     where interf == interfaceType
                                                     select interf).Count() > 0
                                              select type;

                textBoxAssembly.Text = assembly.FullName;
                textBoxLocalPath.Text = path;
            }
            catch (Exception err)
            {
                MessageBox.Show(string.Format("File \"{0}\" opening error:\n{1}", path, err), "Error!", MessageBoxButton.OK, MessageBoxImage.Error);
                Close();
                return;
            }
        }
开发者ID:kapitanov,项目名称:diploma,代码行数:31,代码来源:ClassBrowser.xaml.cs

示例8: SlowFileWriting

        public void SlowFileWriting(
            [Values(true, false)]bool contentChanges,
            [Values(FileAccess.ReadWrite, FileAccess.Write)]FileAccess access,
            [Values(FileShare.None, FileShare.ReadWrite, FileShare.Read, FileShare.Delete)]FileShare share)
        {
            int length = 10;
            this.ContentChangesActive = contentChanges;
            this.InitializeAndRunRepo(swallowExceptions: true);
            var file = new FileInfo(Path.Combine(this.localRootDir.FullName, "file"));
            using (var task = Task.Factory.StartNew(() => {
                using (var stream = file.Open(FileMode.CreateNew, access, share)) {
                    for (int i = 0; i < length; i++) {
                        Thread.Sleep(1000);
                        stream.WriteByte((byte)'0');
                    }
                }
            })) {
                while (!task.Wait(1000)) {
                    this.AddStartNextSyncEvent();
                    this.repo.Run();
                }

                this.AddStartNextSyncEvent();
                this.repo.Run();
            }

            Assert.That(this.localRootDir.GetFiles().Length, Is.EqualTo(1));
            Assert.That(this.remoteRootDir.GetChildren().TotalNumItems, Is.EqualTo(1));
            Assert.That(this.localRootDir.GetFiles().First().Length, Is.EqualTo(length));
            Assert.That((this.remoteRootDir.GetChildren().First() as IDocument).ContentStreamLength, Is.EqualTo(length));
        }
开发者ID:OpenDataSpace,项目名称:CmisSync,代码行数:31,代码来源:UploadSlowWrittenFile.cs

示例9: DownLoadFile

 /// <summary>
 /// 下载文件
 /// </summary>
 /// <param name="FileFullPath">下载文件下载的完整路径及名称</param>
 public static void DownLoadFile(string FileFullPath)
 {
     if (!string.IsNullOrEmpty(FileFullPath) && FileExists(FileFullPath))
     {
         FileInfo fi = new FileInfo(FileFullPath);//文件信息
         FileFullPath = HttpUtility.UrlEncode(FileFullPath); //对文件名编码
         FileFullPath = FileFullPath.Replace("+", "%20"); //解决空格被编码为"+"号的问题
         HttpContext.Current.Response.Clear();
         HttpContext.Current.Response.ContentType = "application/octet-stream";
         HttpContext.Current.Response.AppendHeader("Content-Disposition", "attachment; filename=" + FileFullPath);
         HttpContext.Current.Response.AppendHeader("content-length", fi.Length.ToString()); //文件长度
         int chunkSize = 102400;//缓存区大小,可根据服务器性能及网络情况进行修改
         byte[] buffer = new byte[chunkSize]; //缓存区
         using (FileStream fs = fi.Open(FileMode.Open))  //打开一个文件流
         {
             while (fs.Position >= 0 && HttpContext.Current.Response.IsClientConnected) //如果没到文件尾并且客户在线
             {
                 int tmp = fs.Read(buffer, 0, chunkSize);//读取一块文件
                 if (tmp <= 0) break; //tmp=0说明文件已经读取完毕,则跳出循环
                 HttpContext.Current.Response.OutputStream.Write(buffer, 0, tmp);//向客户端传送一块文件
                 HttpContext.Current.Response.Flush();//保证缓存全部送出
                 Thread.Sleep(10);//主线程休息一下,以释放CPU
             }
         }
     }
 }
开发者ID:uwitec,项目名称:web-mvc-logistics,代码行数:30,代码来源:Download.cs

示例10: OnStartup

        protected override void OnStartup(StartupEventArgs e)
        {
            OpenFileDialog dialog = new OpenFileDialog();

            Nullable<bool> result = dialog.ShowDialog();

            if (result != true)
            {
                Shutdown();
                return;
            }

            MachineType machineType;

            FileInfo fileInfo = new FileInfo(dialog.FileName);

            try
            {
                using (FileStream filestream = fileInfo.Open(FileMode.Open, FileAccess.Read))
                {
                    machineType = ReadMachineType(filestream);
                }
            }
            catch (PEHeaderNotFoundException error)
            {
                MessageBox.Show(error.Message);
                Shutdown();
                return;
            }

            DisplayMachineType(machineType);

            Shutdown();
        }
开发者ID:hwaien,项目名称:SixtyFourBitAssemblyChecker,代码行数:34,代码来源:App.xaml.cs

示例11: IsLocked

        internal static bool IsLocked(string filePath)
        {
            if (filePath.IsNullOrWhiteSpace())
            {
                throw new ArgumentNullException("filePath");
            }

            FileInfo file = new FileInfo(filePath);
            FileStream fileStream = null;

            try
            {
                fileStream = file.Open(FileMode.Open, FileAccess.Read, FileShare.Read);
            }
            catch (IOException)
            {
                return true;
            }
            finally
            {
                if (fileStream != null)
                    fileStream.Close();
            }

            return false;
        }
开发者ID:xmenxwk,项目名称:MediaToolkit,代码行数:26,代码来源:Document.cs

示例12: DisplayManager

		public DisplayManager(PresentationPanel presentationPanel)
		{
			GL = GlobalWin.GL;
			this.presentationPanel = presentationPanel;
			GraphicsControl = this.presentationPanel.GraphicsControl;
			CR_GraphicsControl = GlobalWin.GLManager.GetContextForGraphicsControl(GraphicsControl);

			//it's sort of important for these to be initialized to something nonzero
			currEmuWidth = currEmuHeight = 1;

			if (GL is BizHawk.Bizware.BizwareGL.Drivers.OpenTK.IGL_TK)
				Renderer = new GuiRenderer(GL);
			else if (GL is BizHawk.Bizware.BizwareGL.Drivers.SlimDX.IGL_SlimDX9)
				Renderer = new GuiRenderer(GL);
			else
				Renderer = new GDIPlusGuiRenderer((BizHawk.Bizware.BizwareGL.Drivers.GdiPlus.IGL_GdiPlus)GL);

			VideoTextureFrugalizer = new TextureFrugalizer(GL);

			ShaderChainFrugalizers = new RenderTargetFrugalizer[16]; //hacky hardcoded limit.. need some other way to manage these
			for (int i = 0; i < 16; i++)
			{
				ShaderChainFrugalizers[i] = new RenderTargetFrugalizer(GL);
			}

			using (var xml = typeof(Program).Assembly.GetManifestResourceStream("BizHawk.Client.EmuHawk.Resources.courier16px.fnt"))
			using (var tex = typeof(Program).Assembly.GetManifestResourceStream("BizHawk.Client.EmuHawk.Resources.courier16px_0.png"))
				TheOneFont = new StringRenderer(GL, xml, tex);

			using (var gens = typeof(Program).Assembly.GetManifestResourceStream("BizHawk.Client.EmuHawk.Resources.gens.ttf"))
				LoadCustomFont(gens);
			using (var fceux = typeof(Program).Assembly.GetManifestResourceStream("BizHawk.Client.EmuHawk.Resources.fceux.ttf"))
				LoadCustomFont(fceux);

			if (GL is BizHawk.Bizware.BizwareGL.Drivers.OpenTK.IGL_TK || GL is BizHawk.Bizware.BizwareGL.Drivers.SlimDX.IGL_SlimDX9)
			{
				var fiHq2x = new FileInfo(Path.Combine(PathManager.GetExeDirectoryAbsolute(), "Shaders/BizHawk/hq2x.cgp"));
				if (fiHq2x.Exists)
					using (var stream = fiHq2x.OpenRead())
						ShaderChain_hq2x = new Filters.RetroShaderChain(GL, new Filters.RetroShaderPreset(stream), Path.Combine(PathManager.GetExeDirectoryAbsolute(), "Shaders/BizHawk"));
				var fiScanlines = new FileInfo(Path.Combine(PathManager.GetExeDirectoryAbsolute(), "Shaders/BizHawk/BizScanlines.cgp"));
				if (fiScanlines.Exists)
					using (var stream = fiScanlines.OpenRead())
						ShaderChain_scanlines = new Filters.RetroShaderChain(GL, new Filters.RetroShaderPreset(stream), Path.Combine(PathManager.GetExeDirectoryAbsolute(), "Shaders/BizHawk"));
				string bicubic_path = "Shaders/BizHawk/bicubic-fast.cgp";
				if(GL is BizHawk.Bizware.BizwareGL.Drivers.SlimDX.IGL_SlimDX9)
					bicubic_path = "Shaders/BizHawk/bicubic-normal.cgp";
				var fiBicubic = new FileInfo(Path.Combine(PathManager.GetExeDirectoryAbsolute(), bicubic_path));
				if (fiBicubic.Exists)
					using (var stream = fiBicubic.Open(FileMode.Open, FileAccess.Read, FileShare.Read))
						ShaderChain_bicubic = new Filters.RetroShaderChain(GL, new Filters.RetroShaderPreset(stream), Path.Combine(PathManager.GetExeDirectoryAbsolute(), "Shaders/BizHawk"));
			}

			LuaSurfaceSets["emu"] = new SwappableDisplaySurfaceSet();
			LuaSurfaceSets["native"] = new SwappableDisplaySurfaceSet();
			LuaSurfaceFrugalizers["emu"] = new TextureFrugalizer(GL);
			LuaSurfaceFrugalizers["native"] = new TextureFrugalizer(GL);

			RefreshUserShader();
		}
开发者ID:henke37,项目名称:BizHawk,代码行数:60,代码来源:DisplayManager.cs

示例13: SetCurText

        /// <summary>
        /// 
        /// </summary>
        /// <param name="orderid"></param>
        public void SetCurText(string orderid)
        {
            FileStream fileStream = null;
            StreamWriter writer = null;
            try
            {
                System.IO.FileInfo fileInfo = new System.IO.FileInfo(_fileName);
                if (!fileInfo.Exists)
                {
                    fileStream = fileInfo.Create();
                    writer = new StreamWriter(fileStream);
                }
                else
                {
                    fileStream = fileInfo.Open(FileMode.Create, FileAccess.Write);
                    writer = new StreamWriter(fileStream);
                }
                writer.WriteLine(orderid);

            }
            finally
            {
                if (writer != null)
                {
                    writer.Close();
                    writer.Dispose();
                    fileStream.Close();
                    fileStream.Dispose();
                }
            }
        }
开发者ID:reckcn,项目名称:DevLib.Comm,代码行数:35,代码来源:SingleFileLine.cs

示例14: loadItemDescription

        public void loadItemDescription(ItemDescription details, String fileName)
        {
            FileInfo file = new FileInfo(dirPath.FullName + "\\" + fileName);
            if (!file.Exists)
            {
                throw new IOException("File does not exist");
            }
            FileStream s = file.Open(FileMode.Open, FileAccess.Read);
            StreamReader stream = new StreamReader(s, Encoding.Default);
            String content = stream.ReadToEnd();
            String[] splitted = content.Split(new string[] { "[","]\r\n","\r\n\r\n" }, StringSplitOptions.RemoveEmptyEntries);

            for (int i = 0; i < splitted.Length - 1; i++)
            {
                if (splitted[i] == agape_rfid_desktop.Properties.Resources.descIT)
                {
                    details[Languages.IT].Description = splitted[++i];
                }
                else if (splitted[i] == agape_rfid_desktop.Properties.Resources.descEN)
                {
                    details[Languages.EN].Description = splitted[++i];
                }
                else if (splitted[i] == agape_rfid_desktop.Properties.Resources.valIT)
                {
                    details[Languages.IT].Values = splitted[++i];
                }
                else if (splitted[i] == agape_rfid_desktop.Properties.Resources.valEN)
                {
                    details[Languages.EN].Values = splitted[++i];
                }
            }

                // alla fine della fiera...close file stream
            s.Close();
        }
开发者ID:aamerkhan562,项目名称:agape-rfid,代码行数:35,代码来源:DescriptionFileHandler.cs

示例15: Main

        public static void Main()
        {
            string fileName = @"enumtest.txt";
            FileInfo file = new FileInfo(fileName);
            file.Open(FileMode.Create).Close();

            FileAttributes startingAttributes =
                file.Attributes;

            file.Attributes = FileAttributes.Hidden |
                FileAttributes.ReadOnly;

            Console.WriteLine("\"{0}\" outputs as \"{1}\"",
                file.Attributes.ToString().Replace(",", " |"),
                file.Attributes);

            FileAttributes attributes =
                (FileAttributes)Enum.Parse(typeof(FileAttributes),
                file.Attributes.ToString());

            Console.WriteLine(attributes);

            File.SetAttributes(fileName,
                startingAttributes);
            file.Delete();
        }
开发者ID:andrewdwalker,项目名称:EssentialCSharp,代码行数:26,代码来源:Listing08.18.UsingFlagsAttribute.cs


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