参数说明:
rb_pleasant_ID 目标实体的recordID
entity 需要赋值文件的接受实体;
private void copyFileColumnPro(IOrganizationService service,Entity entity,Guid rb_pleasant_ID)
{
// Download file
var initializeFile = new InitializeFileBlocksDownloadRequest
{
FileAttributeName = "rb_file1",
Target = new EntityReference("rb_pleasant", rb_pleasant_ID)
};
var fileResponse = (InitializeFileBlocksDownloadResponse)service.Execute(initializeFile);
var req = new DownloadBlockRequest { FileContinuationToken = fileResponse.FileContinuationToken, BlockLength = fileResponse.FileSizeInBytes };
var response = (DownloadBlockResponse)service.Execute(req);
var limit = 4194304;
var blockIds = new List<string>();
var initializeFileUploadRequest = new InitializeFileBlocksUploadRequest
{
FileAttributeName = "rb_file1",
Target = entity.ToEntityReference(),
FileName = fileResponse.FileName
};
var fileUploadResponse = (InitializeFileBlocksUploadResponse)service.Execute(initializeFileUploadRequest);
for (int i = 0; i < Math.Ceiling(response.Data.Length / Convert.ToDecimal(limit)); i++)
{
var blockId = Convert.ToBase64String(Encoding.UTF8.GetBytes(Guid.NewGuid().ToString()));
blockIds.Add(blockId);
var blockData = response.Data.Skip(i * limit).Take(limit).ToArray();
var blockRequest = new UploadBlockRequest() { FileContinuationToken = fileUploadResponse.FileContinuationToken, BlockId = blockId, BlockData = blockData };
var blockResponse = (UploadBlockResponse)service.Execute(blockRequest);
}
var commitRequest = new CommitFileBlocksUploadRequest()
{
BlockList = blockIds.ToArray(),
FileContinuationToken = fileUploadResponse.FileContinuationToken,
FileName = fileResponse.FileName,
MimeType = System.Web.MimeMapping.GetMimeMapping(fileResponse.FileName),
};
service.Execute(commitRequest);
}
标签:rb,service,column,FileContinuationToken,Record,File,var,new,fileResponse From: https://www.cnblogs.com/BricksMover/p/17293533.html