C# File.CopyTo的代码示例

通过代码示例来学习C# File.CopyTo方法

通过代码示例来学习编程是非常高效的。
1. 代码示例提供了一个具体而直观的学习环境,使初学者能够立即看到编程概念和语法的实际应用。
2. 通过分析和模仿现有的代码实例,初学者可以更好地理解编程逻辑和算法的工作原理。
3. 代码实例往往涵盖了多种编程技巧和最佳实践,通过学习和模仿这些实例,学习者可以逐步掌握如何编写高效、可读性强和可维护的代码。这对于初学者来说,是一种快速提升编程水平的有效途径。


File.CopyTo是C#的System.IO命名空间下中的一个方法, 小编为大家找了一些网络大拿们常见的代码示例,源码中的File.CopyTo() 已经帮大家高亮显示了,大家可以重点学习File.CopyTo() 方法的写法,从而快速掌握该方法的应用。

File.CopyTo的代码示例1 - SignIndex()

    using System.IO;

        private void SignIndex()
        {
            using (ITracer activity = this.tracer.StartActivity("SignIndex", EventLevel.Informational, Keywords.Telemetry, metadata: null))
            {
                using (FileStream fs = File.Open(this.indexPath, FileMode.Open, FileAccess.ReadWrite))
                {
                    // Truncate the old hash off. The Index class is expected to preserve any existing hash.
                    fs.SetLength(fs.Length - 20);
                    using (HashingStream hashStream = new HashingStream(fs))
                    {
                        fs.Position = 0;
                        hashStream.CopyTo(Stream.Null);
                        byte[] hash = hashStream.Hash;

                        // The fs pointer is now where the old hash used to be. Perfect. :)
                        fs.Write(hash, 0, hash.Length);
                    }
                }
            }
        }
    

开发者ID:microsoft,项目名称:VFSForGit,代码行数:22,代码来源:Index.cs

在SignIndex()方法中,File的代码示例类中的CopyTo的代码示例方法一共出现了1次, 见黄色背景高亮显示的地方,欢迎大家点赞

File.CopyTo的代码示例2 - TestPicturesAreCopied()

    
		/// 
		/// If we construct a new Id3v2 tag, then try to copy that onto a File.Tag
		/// We observe that simple text frames are copied, but APIC and GEOB aren't
		/// 
		[Test]
		public void TestPicturesAreCopied ()
		{
			string tempFile = TestPath.Samples + "tmpwrite_sample_v2_only.mp3";

			System.IO.File.Copy (sample_file, tempFile, true);

			// Put a picture on the starting file
			File file = TagLib.File.Create (tempFile);
			var picture = new Picture (TestPath.Samples + "sample_gimp.gif") {
				Type = PictureType.BackCover,
				Description = "TEST description 1"
			};
			file.Tag.Pictures = new[] { picture };
			file.Save ();

			Assert.IsTrue (file.Tag.Pictures.Count () == 1, "File should start with 1 picture");

			// Now construct a new tag with a title, APIC and GEOB frame

			var tag = new TagLib.Id3v2.Tag();
			tag.Title = "FOOBAR";

			// single red dot (1x1 px red image) APIC frame found in wild
			var redDot = new byte[] { 65, 80, 73, 67, 0, 0, 0, 155, 0, 0, 0, 105, 109, 97, 103, 101, 47, 112, 110, 103, 0, 3, 0, 137, 80, 78,
				71, 13, 10, 26, 10, 0, 0, 0, 13, 73, 72, 68, 82, 0, 0, 0, 1, 0, 0, 0, 1, 8, 2, 0, 0, 0, 144, 119, 83, 222, 0, 0, 0, 4, 103, 65,
				77, 65, 0, 0, 177, 143, 11, 252, 97, 5, 0, 0, 0, 9, 112, 72, 89, 115, 0, 0, 11, 18, 0, 0, 11, 18, 1, 210, 221, 126, 252, 0, 0, 0,
				24, 116, 69, 88, 116, 83, 111, 102, 116, 119, 97, 114, 101, 0, 112, 97, 105, 110, 116, 46, 110, 101, 116, 32, 52, 46, 49, 46, 53,
				100, 71, 88, 82, 0, 0, 0, 12, 73, 68, 65, 84, 24, 87, 99, 248, 47, 162, 0, 0, 3, 73, 1, 52, 163, 224, 5, 179, 0, 0, 0, 0, 73, 69,
				78, 68, 174, 66, 96, 130 };
			var pictureFrame = new TagLib.Id3v2.AttachmentFrame (redDot, 3);

			var geobFrame = new TagLib.Id3v2.AttachmentFrame ();
			geobFrame.MimeType = "plain/text";
			geobFrame.Description = "random";
			geobFrame.Type = PictureType.NotAPicture;
			geobFrame.Data = "random text in geob";

			tag.AddFrame (pictureFrame);
			tag.AddFrame (geobFrame);

			tag.CopyTo (file.Tag, false);

			Assert.AreEqual ("MP3 title", file.Tag.Title, "Title shouldn't be copied if overwrite=false");
			Assert.AreEqual (1, file.Tag.Pictures.Count (), "GEOB/APIC frames shouldn't be copied if overwrite=false");

			tag.CopyTo (file.Tag, true);

			Assert.AreEqual (tag.Title, file.Tag.Title, "Title wasn't copied");
			Assert.AreEqual (tag.Pictures.Count (), file.Tag.Pictures.Count (), "GEOB/APIC frames weren't copied");
		}
    

开发者ID:mono,项目名称:taglib-sharp,代码行数:56,代码来源:Id3V2FormatTest.cs

在TestPicturesAreCopied()方法中,File的代码示例类中的CopyTo的代码示例方法一共出现了2次, 见黄色背景高亮显示的地方,欢迎大家点赞

File.CopyTo的代码示例3 - AddBoardsToSet()

    using System.IO;

        public void AddBoardsToSet(List FileList, ProgressLog Logger , bool fixgroup = true, bool forcezerowidth = false)
        {
            Logger.PushActivity("AddBoardsToSet");
            foreach (var a in FileList)
            {
                Logger.AddString(String.Format("adding {0}", a));
                BoardSide aSide = BoardSide.Unknown;
                BoardLayer aLayer = BoardLayer.Unknown;
                string ext = Path.GetExtension(a);
                if (ext == ".zip")
                {
                    using (ZipFile zip1 = ZipFile.Read(a))
                    {
                        foreach (ZipEntry e in zip1)
                        {
                            MemoryStream MS = new MemoryStream();
                            if (e.IsDirectory == false)
                            {
                                //                              e.Extract(MS);
                                //                                MS.Seek(0, SeekOrigin.Begin);
                                Gerber.DetermineBoardSideAndLayer(e.FileName, out aSide, out aLayer);
                                if (aLayer == BoardLayer.Outline) hasgko = true;

                                //     AddFileStream(MS, e.FileName, drillscaler);
                            }
                        }
                    }
                }
                else
                {

                    Gerber.DetermineBoardSideAndLayer(a, out aSide, out aLayer);
                }
                if (aLayer == BoardLayer.Outline) hasgko = true;
            }

            foreach (var a in FileList)
            {
                if (Logger != null) Logger.AddString(String.Format("Loading {0}", Path.GetFileName(a)));
                string ext = Path.GetExtension(a);
                if (ext == ".zip")
                {
                    using (ZipFile zip1 = ZipFile.Read(a))
                    {
                        foreach (ZipEntry e in zip1)
                        {
                            MemoryStream MS = new MemoryStream();
                            if (e.IsDirectory == false)
                            {
                                if (Logger != null) Logger.AddString(String.Format("Loading inside zip: {0}", Path.GetFileName(e.FileName)));

                                e.Extract(MS);
                                MS.Seek(0, SeekOrigin.Begin);
                                AddFileToSet(MS, e.FileName, Logger, 1, forcezerowidth);
                            }
                        }
                    }
                }
                else
                {
                    try
                    {
                        MemoryStream MS2 = new MemoryStream();
                        FileStream FS = File.OpenRead(a);
                        FS.CopyTo(MS2);
                        MS2.Seek(0, SeekOrigin.Begin);
                        AddFileToSet(MS2, a, Logger,1, forcezerowidth);
                    }
                    catch (Exception E)
                    {
                        Logger.AddString(String.Format("Failed to add file! {0},{1}", a, E));
                    }
                }
            }

            if (fixgroup)
            {
                if (Logger != null) Logger.AddString("Checking for common file format mistakes.");
                FixEagleDrillExportIssues(Logger);
                CheckRelativeBoundingBoxes(Logger);
                CheckForOutlineFiles(Logger);

                CheckRelativeBoundingBoxes(Logger);

            }

            Logger.PopActivity();
        }
    

开发者ID:ThisIsNotRocketScience,项目名称:GerberTools,代码行数:90,代码来源:ImageCreator.cs

在AddBoardsToSet()方法中,File的代码示例类中的CopyTo的代码示例方法一共出现了1次, 见黄色背景高亮显示的地方,欢迎大家点赞

File.CopyTo的代码示例4 - AddFile()

    using System.IO;

        public void AddFile(ProgressLog log, string filename, double drillscaler = 1.0)
        {

            string[] filesplit = filename.Split('.');
            string ext = filesplit[filesplit.Count() - 1].ToLower();
            if (ext == "zip")
            {
                using (ZipFile zip1 = ZipFile.Read(filename))
                {
                    foreach (ZipEntry e in zip1)
                    {
                        MemoryStream MS = new MemoryStream();
                        if (e.IsDirectory == false)
                        {
                            e.Extract(MS);
                            MS.Seek(0, SeekOrigin.Begin);
                            AddFileStream(log, MS, e.FileName, drillscaler);
                        }
                    }
                }
                return;

            }


            MemoryStream MS2 = new MemoryStream();
            FileStream FS = File.OpenRead(filename);
            FS.CopyTo(MS2);
            MS2.Seek(0, SeekOrigin.Begin);
            AddFileStream(log, MS2, filename, drillscaler);

        }
    

开发者ID:ThisIsNotRocketScience,项目名称:GerberTools,代码行数:34,代码来源:LoadedStuff.cs

在AddFile()方法中,File的代码示例类中的CopyTo的代码示例方法一共出现了1次, 见黄色背景高亮显示的地方,欢迎大家点赞

File.CopyTo的代码示例5 - AddBoardsToSet()

    using System.IO;

        public void AddBoardsToSet(List FileList, bool fixgroup = true, ProgressLog Logger = null)
        {
            foreach (var a in FileList)
            {
                BoardSide aSide = BoardSide.Unknown;
                BoardLayer aLayer = BoardLayer.Unknown;
                string ext = Path.GetExtension(a);
                if (ext == ".zip")
                {
                    using (ZipFile zip1 = ZipFile.Read(a))
                    {
                        foreach (ZipEntry e in zip1)
                        {
                            MemoryStream MS = new MemoryStream();
                            if (e.IsDirectory == false)
                            {
                                //                              e.Extract(MS);
                                //                                MS.Seek(0, SeekOrigin.Begin);
                                Gerber.DetermineBoardSideAndLayer(e.FileName, out aSide, out aLayer);
                                if (aLayer == BoardLayer.Outline) HasLoadedOutline = true;

                                //     AddFileStream(MS, e.FileName, drillscaler);
                            }
                        }
                    }
                }
                else
                {

                    Gerber.DetermineBoardSideAndLayer(a, out aSide, out aLayer);
                }
                if (aLayer == BoardLayer.Outline) HasLoadedOutline = true;
            }

            foreach (var a in FileList)
            {
                if (Logger != null) Logger.AddString(String.Format("Loading {0}", Path.GetFileName(a)));
                string ext = Path.GetExtension(a);
                if (ext == ".zip")
                {
                    using (ZipFile zip1 = ZipFile.Read(a))
                    {
                        foreach (ZipEntry e in zip1)
                        {
                            MemoryStream MS = new MemoryStream();
                            if (e.IsDirectory == false)
                            {
                                if (Logger != null) Logger.AddString(String.Format("Loading inside zip: {0}", Path.GetFileName(e.FileName)));

                                e.Extract(MS);
                                MS.Seek(0, SeekOrigin.Begin);
                                AddFileToSet(MS, e.FileName, Logger);
                            }
                        }
                    }
                }
                else
                {
                    MemoryStream MS2 = new MemoryStream();
                    FileStream FS = File.OpenRead(a);
                    FS.CopyTo(MS2);
                    MS2.Seek(0, SeekOrigin.Begin);
                    AddFileToSet(MS2, a, Logger);
                }
            }

            if (fixgroup)
            {
                if (Logger != null) Logger.AddString("Checking for common file format mistakes.");
                FixEagleDrillExportIssues(Logger);
                CheckRelativeBoundingBoxes(Logger);
                CheckForOutlineFiles(Logger);

                CheckRelativeBoundingBoxes(Logger);

            }
        }
    

开发者ID:ThisIsNotRocketScience,项目名称:GerberTools,代码行数:79,代码来源:SickOfBeige.cs

在AddBoardsToSet()方法中,File的代码示例类中的CopyTo的代码示例方法一共出现了1次, 见黄色背景高亮显示的地方,欢迎大家点赞

File.CopyTo的代码示例6 - ExecuteCore()

    using System.IO;

        private int ExecuteCore(RazorConfiguration configuration, string projectDirectory, string outputFilePath, string[] assemblies)
        {
            outputFilePath = Path.Combine(projectDirectory, outputFilePath);

            var metadataReferences = new MetadataReference[assemblies.Length];
            for (var i = 0; i < assemblies.Length; i++)
            {
                metadataReferences[i] = Parent.AssemblyReferenceProvider(assemblies[i], default(MetadataReferenceProperties));
            }

            var engine = RazorProjectEngine.Create(configuration, RazorProjectFileSystem.Empty, b =>
            {
                b.Features.Add(new DefaultMetadataReferenceFeature() { References = metadataReferences });
                b.Features.Add(new CompilationTagHelperFeature());
                b.Features.Add(new DefaultTagHelperDescriptorProvider());
                b.Features.Add(new ComponentTagHelperDescriptorProvider());
            });

            var feature = engine.Engine.Features.OfType().Single();
            var tagHelpers = feature.GetDescriptors();

            using (var stream = new MemoryStream())
            {
                Serialize(stream, tagHelpers);

                stream.Position = 0;

                var newHash = Hash(stream);
                var existingHash = Hash(outputFilePath);

                if (!HashesEqual(newHash, existingHash))
                {
                    stream.Position = 0;
                    using (var output = File.Open(outputFilePath, FileMode.Create))
                    {
                        stream.CopyTo(output);
                    }
                }
            }

            return ExitCodeSuccess;
        }
    

开发者ID:aspnet,项目名称:Razor,代码行数:44,代码来源:DiscoverCommand.cs

在ExecuteCore()方法中,File的代码示例类中的CopyTo的代码示例方法一共出现了1次, 见黄色背景高亮显示的地方,欢迎大家点赞

File.CopyTo的代码示例7 - Save()

    using System.IO;

        /// 
        /// Saves the file to the specified path.
        /// 
        public void Save(string filePath)
        {
            var directory = Path.GetDirectoryName(filePath);
            if (!Directory.Exists(directory))
            {
                Directory.CreateDirectory(directory);
            }

            using (var outStream = File.Create(filePath))
            {
                using (var inStream = OpenRead())
                {
                    inStream.CopyTo(outStream);
                }
            }
        }
    

开发者ID:aspnet,项目名称:Razor,代码行数:21,代码来源:TestFile.cs

在Save()方法中,File的代码示例类中的CopyTo的代码示例方法一共出现了1次, 见黄色背景高亮显示的地方,欢迎大家点赞

File.CopyTo的代码示例8 - Create()

    using System.IO;
        public void Create(string filePath)
        {
            string tempFile1 = ExampleHelper.GetTempFilePath(filePath);
            string tempFile2 = ExampleHelper.GetTempFilePath(filePath);
            try
            {
                new UsingTables().Create(tempFile1);
                var wb = new XLWorkbook(tempFile1);

                var wsSource = wb.Worksheet(1);
                // Copy the worksheet to a new sheet in this workbook
                wsSource.CopyTo("Copy");

                // We're going to open another workbook to show that you can
                // copy a sheet from one workbook to another:
                new BasicTable().Create(tempFile2);
                var wbSource = new XLWorkbook(tempFile2);
                wbSource.Worksheet(1).CopyTo(wb, "Copy From Other");

                // Save the workbook with the 2 copies
                wb.SaveAs(filePath);
            }
            finally
            {
                if (File.Exists(tempFile1))
                {
                    File.Delete(tempFile1);
                }
                if (File.Exists(tempFile2))
                {
                    File.Delete(tempFile2);
                }
            }
        }
    

开发者ID:ClosedXML,项目名称:ClosedXML,代码行数:35,代码来源:CopyingWorksheets.cs

在Create()方法中,File的代码示例类中的CopyTo的代码示例方法一共出现了1次, 见黄色背景高亮显示的地方,欢迎大家点赞

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