共用方式為


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。 如果您針對新版檔案使用相同的 URL,某些 Proxy 伺服器可能會從其快取中提供過時的數據,因為它們不會在檔案過時時向原始伺服器進行驗證。

對於上傳,如果本機檔案在傳輸時變更,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);
}

規格需求

需求
最低支援的用戶端 Windows XP
最低支援的伺服器 Windows Server 2003
目標平台 Windows
標頭 bits.h
程式庫 Bits.lib
Dll QmgrPrxy.dll

另請參閱

IBackgroundCopyJob3::AddFileWithRanges

IBackgroundCopyJob::AddFile

IBackgroundCopyJob::EnumFiles

IBackgroundCopyJob::GetState

IBackgroundCopyJob::Resume