IBackgroundCopyJob::AddFileSet 方法 (bits.h)

将多个文件添加到作业。

Syntax

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 方法。 有关详细信息,请参阅 将文件添加到作业

若要将文件添加到从该文件下载数据范围的作业,请调用 IBackgroundCopyJob3::AddFileWithRanges 方法。

上传作业只能包含一个文件。 如果添加多个文件,该方法将返回BG_E_TOO_MANY_FILES。

对于下载,BITS 保证文件版本(基于文件大小和日期,而不是内容)将保持一致;但是,它不能保证一组文件将一致。 例如,如果在服务器上更新文件时,BITS 正在下载两个文件中的第二个文件,则 BITS 将重启第二个文件的下载;但是,不会再次下载第一个文件。

请注意,如果拥有从服务器下载的文件,则应为每个新版本的文件创建新的 URL。 如果对文件的新版本使用相同的 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 价值
最低支持的客户端 Windows XP
支持的最低服务器 Windows Server 2003
目标平台 Windows操作系统
Header bits.h
Library Bits.lib
DLL QmgrPrxy.dll

另请参阅

IBackgroundCopyJob3::AddFileWithRanges

IBackgroundCopyJob::AddFile

IBackgroundCopyJob::EnumFiles

IBackgroundCopyJob::GetState

IBackgroundCopyJob::Resume