使用 .NET SDK 应用模板

Apply Template using .NET SDK

我正在尝试使用 .NET SDK 应用模板(而不是使用 模板),但我似乎无法获取它。我在这里看过一两篇其他文章,但都没有使用 SDK。谁能帮我用 SDK 解决这个问题?

我的情况是这样的:我定义了一个模板,其中包含我所有的锚标记和放置信息。当我通过 UI 应用模板时,它工作正常并且标签被正确放置。当我通过 API 上传相同的文档时,没有应用标签。

我尝试使用复合模板复制这些文章中显示的内容,但没有成功:

在其中一篇文章中,OP 说信封需要是草稿。我试过了,但后来我没能把它改成“已发送”。

这是我的 ASP.NET Web Forms 测试项目中的一些相关代码。在这个项目中,我使用 asp:FileUpload 控件来获取文件内容,然后调用 SendFileToDocusign() 方法:

    private void SendFileToDocusign(byte[] fileData, string accessToken)
    {
        //Create a signer recipient to sign the document, identified by name and email
        //We set the clientUserId to enable embedded signing for the recipient
        Signer tmpSigner1 = new Signer {
            Email = "me@me.com", Name = "Test Tester",
            ClientUserId = "1000", RecipientId = "1", RoleName = "Signer1", CustomFields = new List<string> { "Buyer1" }
        };

        //Step 1. Create the envelope definition
        EnvelopeDefinition tmpEnvDef = MakeEnvelopeAndApplyTemplate(fileData, new List<Signer> { tmpSigner1 });

        //Step 2. Call DocuSign to create the envelope           
        ApiClient tmpClient = new ApiClient(DOCUSIGN_API_BASEPATH);
        tmpClient.Configuration.AddDefaultHeader("Authorization", "Bearer " + accessToken);
        EnvelopesApi tmpEnvelopesApi = new EnvelopesApi(tmpClient);
        EnvelopeSummary tmpResults = tmpEnvelopesApi.CreateEnvelope(DOCUSIGN_ACCOUNTID, tmpEnvDef);
        string tmpEnvelopeID = tmpResults.EnvelopeId;

        //Step 3. create the recipient view, the Signing Ceremony
        RecipientViewRequest tmpViewRequest = MakeRecipientViewRequest(tmpSigner1);
        //call the CreateRecipientView API
        ViewUrl tmpRecipView = tmpEnvelopesApi.CreateRecipientView(DOCUSIGN_ACCOUNTID, tmpEnvelopeID, tmpViewRequest);

       Response.Redirect(tmpRecipView.Url);
    } 

    private EnvelopeDefinition MakeEnvelopeAndApplyTemplate(byte[] fileData, List<Signer> signers)
    {
        EnvelopeDefinition tmpEnv = new EnvelopeDefinition(EmailSubject:"We don't really use the Subject Line here");
        Document tmpDoc = new Document();
        Recipients tmpRecipients = new Recipients(Signers:signers);
        CompositeTemplate tmpCompTemplate = new CompositeTemplate("1");

        string tmpfileDataB64 = Convert.ToBase64String(fileData);

        tmpDoc.DocumentBase64 = tmpfileDataB64;
        tmpDoc.Name = "Test file";//can be different from actual file name
        tmpDoc.FileExtension = "pdf";
        tmpDoc.DocumentId = "1";

        InlineTemplate tmpInlineTemplate = new InlineTemplate();
        tmpInlineTemplate.Sequence = "1";
        tmpInlineTemplate.Recipients = tmpRecipients;

        ServerTemplate tmpServerTemplate = new ServerTemplate("2", DOCUSIGN_TEMPLATE_ID);

        tmpCompTemplate.ServerTemplates = new List<ServerTemplate>() { tmpServerTemplate };
        tmpCompTemplate.InlineTemplates = new List<InlineTemplate>() { tmpInlineTemplate };
        tmpCompTemplate.Document = tmpDoc;

        tmpEnv.CompositeTemplates = new List<CompositeTemplate>() { tmpCompTemplate };

        //Request that the envelope be sent by setting |status| to "sent".
        //To request that the envelope be created as a draft, set to "created"
        tmpEnv.Status = "sent";

        return tmpEnv;
    }

感谢您提供的任何帮助。

您的代码必须正确处理收件人。 模板中的收件人 pre-defined 和您在代码中添加的收件人之间的角色名称必须匹配。 我在你的代码中没有看到那部分。 您使用的示例用于复合模板。与此相关的代码在 regular template example 中,但它是相同的。

https://github.com/docusign/code-examples-csharp/blob/master/launcher-csharp/eSignature/Controllers/Eg009UseTemplateController.cs

TemplateRole signer1 = new TemplateRole();
                signer1.Email = signerEmail;
                signer1.Name =  signerName;
                signer1.RoleName = "signer";
    
                TemplateRole cc1 = new TemplateRole();
                cc1.Email = ccEmail;
                cc1.Name = ccName;
                cc1.RoleName = "cc";