Hi Claire,
I also did not have much experience on this TempFileCollection class.
However, based on my research, TempFileCollection is normally used with
Compilation process. It can manage a collection of files with the same name
and different extensions, we can use TempFileCollection.AddExtension method
to specify the extensions we want to manage in the collection. We can also
use TempFileCollection.AddFile method to add other files in the collection.
Additionally, we can use TempFileCollection.KeepFiles property to specify
if the files in the collection should be deleted.
I can find 2 articles make use of this class, for your information:
"Compiling code during runtime"
http://www.codeproject.com/csharp/CodeCompilation.asp
"VB060004 - Understanding and Using System.Reflection.Emit"
http://www.codenotes.com/articles/articleAction.aspx?articleID=506
For Path.GetTempFileName method, if we use Reflector to view its source
code, we will see that:
//Path.GetTempFileName
public static string GetTempFileName()
{
string text1 = Path.GetTempPath();
StringBuilder builder1 = new StringBuilder(260);
uint num1 = Win32Native.GetTempFileName(text1, "tmp", 0, builder1);
if (num1 == 0)
{
__Error.WinIOError();
}
return builder1.ToString();
}
//Path.GetTempPath
public static string GetTempPath()
{
new EnvironmentPermission(PermissionState.Unrestricted).Demand();
StringBuilder builder1 = new StringBuilder(260);
uint num1 = Win32Native.GetTempPath(260, builder1);
string text1 = builder1.ToString();
if (num1 == 0)
{
__Error.WinIOError();
}
return text1;
}
Path.GetTempPath internally encapsulate WIn32 GetTempPath API. From the
Win32 GetTempPath API, we can see that:
The GetTempPath function checks for the existence of environment variables
in the following order and uses the first path found:
The path specified by the TMP environment variable.
The path specified by the TEMP environment variable.
The path specified by the USERPROFILE environment variable.
The Windows directory.
So, Path.GetTempFileName actually lets the system create a temp file in
system temp directory with filename marked with "tmp". However, when the
system shuts down, temporary files whose names have been created by this
function are not automatically deleted.
I am not sure what function you really want. If you wanted to get the temp
file automatically deleted after it is closed, I think we may P/invoke
CreateFile Win32 API with FILE_FLAG_DELETE_ON_CLOSE flag specified. This
flag will force the system to delete the file immediately after all of its
handles are closed
Hope this helps
============================================================
Thank you for your patience and cooperation. If you have any questions or
concerns, please feel free to post it in the group. I am standing by to be
of assistance.
Best regards,
Jeffrey Tan
Microsoft Online Partner Support
Get Secure! -
www.microsoft.com/security
This posting is provided "as is" with no warranties and confers no rights.