共用方式為


IBackgroundCopyJob::AddFileSet 方法(bits.h)

在一個工作中新增多個檔案。

語法

HRESULT AddFileSet(
  [in] ULONG        cFileCount,
  [in] BG_FILE_INFO *pFileSet
);

參數

[in] cFileCount

paFileSet 中的元素數量。

[in] pFileSet

一組 BG_FILE_INFO 結構陣列,用來識別要傳輸檔案的本地與遠端檔案名稱。

上傳工作限制在單一檔案內。 如果陣列包含多個元素,或工作已經包含檔案,方法會回傳BG_E_TOO_MANY_FILES。

返回值

此方法回傳以下 HRESULT 值及其他值。

回傳碼 Description
S_OK
檔案成功加入了工作中。
BG_E_TOO_MANY_FILES
上傳工作只能包含一個檔案;你不能在工作中新增超過一個檔案。 陣列中沒有任何檔案被加入該工作。
BG_E_TOO_MANY_FILES_IN_JOB
MaxFilesPerJob 群組政策設定決定工作可包含多少檔案。 將檔案加入工作會超過MaxFilesPerJob的限制。
E_INVALIDARG
您可能因以下原因之一而收到此錯誤:
  • 本地或遠端檔案名稱都無效。
  • 遠端檔名使用不支援的協定。
  • 本地檔名是透過相對路徑指定。
E_ACCESSDENIED
使用者沒有權限在用戶端寫入指定的目錄。

備註

在新增多個檔案到工作時,呼叫 AddFileSet 方法比在迴圈中呼叫 IBackgroundCopyJob::AddFile 方法更有效率。 若要將單一檔案加入工作,請呼叫 AddFile 方法。 更多資訊請參閱 「新增檔案到工作」。

若要將檔案加入 BITS 從檔案下載資料範圍的工作中,請呼叫 IBackgroundCopyJob3::AddFileWithRanges 方法。

上傳工作只能包含一個檔案。 如果你加入多個檔案,方法會回傳BG_E_TOO_MANY_FILES。

對於下載,BITS 保證所傳輸的檔案版本(基於檔案大小與日期,而非內容)是一致的;然而,這並不保證一組檔案會一致。 例如,如果 BITS 正在伺服器更新檔案時正在下載第二個檔案,BITS 會重新啟動第二個檔案的下載;但第一個檔案不會重新下載。

請注意,如果你擁有從伺服器下載的檔案,應該為每個新版本的檔案建立一個新的網址。 如果你使用相同的 URL 來管理新版本的檔案,有些代理伺服器可能會從快取中提供過時的資料,因為他們不會向原始伺服器驗證檔案是否過時。

對於上傳,若本地檔案在傳輸過程中發生變更,BITS 會產生錯誤。 錯誤代碼BG_E_FILE_CHANGED,上下文BG_ERROR_CONTEXT_LOCAL_FILE。

BITS 會依序在工作中傳輸檔案。 若傳輸檔案時發生錯誤,工作會進入錯誤狀態,且在錯誤解決前不會再處理該工作中的檔案。

預設情況下,使用者最多可將 200 個檔案加入一個工作。 此限制不適用於管理員或服務帳號。 要更改預設值,請設定 MaxFilesPerJob 群組政策。

Windows Vista 之前: 使用者可新增的檔案數量沒有限制。

關於擴展性的問題,請參閱 使用 BITS 的最佳實務

範例

以下範例展示了如何在一個下載任務中新增多個檔案。 範例假設 IBackgroundCopyJob 介面指標有效。

HRESULT hr;
IBackgroundCopyJob* pJob;
BG_FILE_INFO* paFiles = NULL;
int idx = 0;
int nCount = 0;  //Number of files to add to the job.
LPWSTR pszLocalName = NULL;
LPWSTR pszRemoteName = NULL;

//Set nCount to the number of files to transfer.

//Allocate a block of memory to contain the array of BG_FILE_INFO structures.
//The BG_FILE_INFO structure contains the local and remote names of the 
//file being transferred.
paFiles = (BG_FILE_INFO*) malloc(sizeof(BG_FILE_INFO) * nCount);
if (NULL == paFiles)
{
  //Handle error
}
else
{
  //Add local and remote file name pairs to the memory block. 
  for (idx=0; idx<nCount; idx++)
  {
    //Set pszLocalName to point to an LPWSTR that contains the local name or
    //allocate memory for pszLocalName and copy the local name to pszLocalName.
    (paFiles+idx)->LocalName = pszLocalName;

    //Set pszRemoteName to point to an LPWSTR that contains the remote name or
    //allocate memory for pszRemoteName and copy the remote name to pszRemoteName.
    (paFiles+idx)->RemoteName = pszRemoteName;
  }

  //Add the files to the job.
  hr = pJob->AddFileSet(nCount, paFiles);
  if (SUCCEEDED(hr))
  {
     //Do Something.
  }

  //Free the memory block for the array of BG_FILE_INFO structures. If you allocated
  //memory for the local and remote file names, loop through the array and free the
  //memory for the file names before you free paFiles.
  free(paFiles);
}

需求

Requirement 價值觀
最低支援的用戶端 視窗XP
支援的最低伺服器 Windows Server 2003
目標平臺 窗戶
Header Bits.h
Library Bits.lib
DLL QmgrPrxy.dll

另請參閱

IBackgroundCopyJob3::AddFileWithRanges

IBackgroundCopyJob::AddFile

IBackgroundCopyJob::EnumFiles

IBackgroundCopyJob::GetState

IBackgroundCopyJob::履歷