當前位置: 首頁>>代碼示例>>C#>>正文


C# TempDirectory.CreateTempFile方法代碼示例

本文整理匯總了C#中System.IO.TempDirectory.CreateTempFile方法的典型用法代碼示例。如果您正苦於以下問題:C# TempDirectory.CreateTempFile方法的具體用法?C# TempDirectory.CreateTempFile怎麽用?C# TempDirectory.CreateTempFile使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在System.IO.TempDirectory的用法示例。


在下文中一共展示了TempDirectory.CreateTempFile方法的9個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的C#代碼示例。

示例1: GetFile_throws_exception_if_more_than_one_file_matches

        public void GetFile_throws_exception_if_more_than_one_file_matches()
        {
            using(var dir = new TempDirectory())
            {
                dir.CreateTempFile("test1.txt");
                dir.CreateTempFile("test2.txt");

                dir.DirectoryInfo.GetFile("test*.txt");
            }
        }
開發者ID:DavidMoore,項目名稱:Foundation,代碼行數:10,代碼來源:DirectoryInfoExtensionsTests.cs

示例2: Can_create_temporary_file

 public void Can_create_temporary_file()
 {
     using( var dir = new TempDirectory() )
     {
         var file = dir.CreateTempFile();
         Assert.IsTrue(file.Exists);
     }
 }
開發者ID:DavidMoore,項目名稱:Foundation,代碼行數:8,代碼來源:TempDirectoryFixture.cs

示例3: Can_write_to_temporary_file

 public void Can_write_to_temporary_file()
 {
     using( var dir = new TempDirectory() )
     {
         var file = dir.CreateTempFile();
         Assert.IsTrue(file.Exists);
         File.WriteAllText(file.FullName, "Test\r\nLine2");
         Assert.AreEqual(File.ReadAllText(file.FullName), "Test\r\nLine2");
     }
 }
開發者ID:DavidMoore,項目名稱:Foundation,代碼行數:10,代碼來源:TempDirectoryFixture.cs

示例4: Can_create_temporary_file_with_a_specific_filename

 public void Can_create_temporary_file_with_a_specific_filename()
 {
     using( var dir = new TempDirectory() )
     {
         var file = dir.CreateTempFile("test.tmp");
         Assert.IsTrue(file.Exists);
         Assert.AreEqual(file.Name, "test.tmp");
         Assert.AreEqual(Path.Combine(dir.DirectoryInfo.FullName, "test.tmp"), file.FullName);
     }
 }
開發者ID:DavidMoore,項目名稱:Foundation,代碼行數:10,代碼來源:TempDirectoryFixture.cs

示例5: Temporary_file_gets_removed_properly_when_out_of_scope

        public void Temporary_file_gets_removed_properly_when_out_of_scope()
        {
            string filename;

            using( var dir = new TempDirectory() )
            {
                var file = dir.CreateTempFile();
                Assert.IsTrue(file.Exists);
                filename = file.FullName;
            }

            Assert.IsFalse(File.Exists(filename));
        }
開發者ID:DavidMoore,項目名稱:Foundation,代碼行數:13,代碼來源:TempDirectoryFixture.cs

示例6: IsFile

        public void IsFile()
        {
            using( var dir = new TempDirectory())
            {
                // An existing directory is not a file
                Assert.IsFalse(dir.DirectoryInfo.IsFile());

                // A file without an extension that exists can still be detected as a file
                var file = dir.CreateTempFile("tempfile");
                Assert.IsTrue( new DirectoryInfo(file.FullName).IsFile() );
            }

            // A file without an extension and that doesn't exist can't be detected as a file
            Assert.IsFalse( new DirectoryInfo(@"D:\test").IsFile() );

            // A file that doesn't exist but has an extension is detected as a file
            Assert.IsTrue(new DirectoryInfo(@"D:\test.extension").IsFile());
        }
開發者ID:DavidMoore,項目名稱:Foundation,代碼行數:18,代碼來源:DirectoryInfoExtensionsTests.cs

示例7: DateModified

        public void DateModified()
        {
            using (var tempDir = new TempDirectory())
            {
                var tempFile = tempDir.CreateTempFile("firstFile.txt");

                var dateTime = tempFile.LastWriteTime;

                var data = new FindData();

                using (var handle = Win32Api.IO.FindFirstFile(tempFile.FullName, data))
                {
                    Assert.IsFalse(handle.IsInvalid);
                    Assert.IsFalse(handle.IsClosed);
                    var actualDateTime = data.LastWriteTime.ToDateTime();
                    Assert.AreEqual(dateTime, actualDateTime);
                }
            }
        }
開發者ID:DavidMoore,項目名稱:Foundation,代碼行數:19,代碼來源:FindDataTests.cs

示例8: FileSize

        public void FileSize()
        {
            using (var tempDir = new TempDirectory())
            {
                var tempFile = tempDir.CreateTempFile("firstFile.txt");
                File.WriteAllText(tempFile.FullName, @"abcde12345");

                var size = tempFile.Length;

                var data = new FindData();
                using (var handle = Win32Api.IO.FindFirstFile(tempFile.FullName, data))
                {
                    Assert.IsFalse(handle.IsInvalid);
                    Assert.IsFalse(handle.IsClosed);

                    var fileSize = data.FileSize;
                    Assert.AreEqual(size, fileSize);
                }
            }
        }
開發者ID:DavidMoore,項目名稱:Foundation,代碼行數:20,代碼來源:FindDataTests.cs

示例9: CreatedDate

        public void CreatedDate()
        {
            using (var tempDir = new TempDirectory())
            {
                var tempFile = tempDir.CreateTempFile("firstFile.txt");

                var creationTime = tempFile.CreationTime;

                var data = new FindData();

                using (var handle = Win32Api.IO.FindFirstFile(tempFile.FullName, data))
                {
                    Assert.IsFalse(handle.IsInvalid);
                    Assert.IsFalse(handle.IsClosed);

                    var dataCreationTime = data.CreationTime.ToDateTime();
                    Assert.AreEqual(creationTime, dataCreationTime);
                }
            }
        }
開發者ID:DavidMoore,項目名稱:Foundation,代碼行數:20,代碼來源:FindDataTests.cs


注:本文中的System.IO.TempDirectory.CreateTempFile方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。