本文整理汇总了C#中System.CodeDom.Compiler.TempFileCollection类的典型用法代码示例。如果您正苦于以下问题:C# TempFileCollection类的具体用法?C# TempFileCollection怎么用?C# TempFileCollection使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
TempFileCollection类属于System.CodeDom.Compiler命名空间,在下文中一共展示了TempFileCollection类的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Main
//引入命名空间
using System;
using System.CodeDom.Compiler;
using System.IO;
class Program
{
static void Main(string[] args)
{
// Create a directory in the current working directory.
Directory.CreateDirectory("testDir");
TempFileCollection tfc = new TempFileCollection("testDir", false);
// Returns the file name relative to the current working directory.
string fileName = tfc.AddExtension("txt");
Console.WriteLine(fileName);
// Name a file in the test directory.
string file2Name = "testDir\\test.txt";
// Add the file to the temp directory and indicate it is to be kept.
tfc.AddFile(file2Name, true);
Console.WriteLine(tfc.Count);
// Create and use the test files.
FileStream fs1 = File.OpenWrite(fileName);
FileStream fs2 = File.OpenWrite(file2Name);
StreamWriter sw1 = new StreamWriter(fs1);
StreamWriter sw2 = new StreamWriter(fs2);
sw1.WriteLine("Test string");
sw2.WriteLine("Test string");
sw1.Close();
sw2.Close();
tfc.Delete();
Console.WriteLine(tfc.Count);
try
{
// This call should succeed.
File.OpenRead(file2Name);
// This call should fail.
File.OpenRead(fileName);
}
catch (FileNotFoundException e)
{
Console.WriteLine(e.Message);
}
}
}