Temporary file

In this chapter you will learn:

  1. How to create temporary file

Create temporary file

The following code creates a temporary file and delete it.

using System;//  j  a v  a2s.co m
using System.IO;

static class MainClass
{
    static void Main()
    {
        string tempFile = Path.GetTempFileName();

        Console.WriteLine("Using " + tempFile);

        using (FileStream fs = new FileStream(tempFile, FileMode.Open))
        {
            // (Write some data.)
        }

        File.Delete(tempFile);

    }
}

The code above generates the following result.

Next chapter...

What you will learn in the next chapter:

  1. Path operation
Home » C# Tutorial » File, Path
File creation
Deleting Files
Put to recycle bin
File Exists
File moving
File size
File attribute
Set file attribute
File time change
File time
Random file name
Temporary file
Path
Directory creation
Delete directory
Path existance
Change the path
Current Path
Directory listing
Recursive Path Listing
Combine path
Calculate Directory Size
Invalid path characters
System path
Directory copy
Drive
Drive information
File access rule
File System watcher