Share via


TempFileCollection.AddFile(String, Boolean) 方法

定義

使用指示在處置集合或呼叫 Delete() 方法之後是否保留檔案的指定值,將指定檔案加入集合中。

public:
 void AddFile(System::String ^ fileName, bool keepFile);
public void AddFile (string fileName, bool keepFile);
member this.AddFile : string * bool -> unit
Public Sub AddFile (fileName As String, keepFile As Boolean)

參數

fileName
String

要加入至集合中的檔案名稱。

keepFile
Boolean

如果檔案應該在使用後保留,則為 true,如果檔案應該刪除,則為 false

例外狀況

fileNamenull 或空字串。

-或-

fileName 已重複。

範例

下列範例示範如何使用 AddFile(String, Boolean) 方法來新增要保留至集合的檔案。 此程式代碼範例是提供給 類別之較大範例的 TempFileCollection 一部分。

// 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);
' Name a file in the test directory.
Dim file2Name As String = "testDir\test.txt"
' Add the file to the temp directory and indicate it is to be kept.
tfc.AddFile(file2Name, True)

適用於