Docusign使用Docusign Nuget包在模板中进行选项卡

时间:2016-06-24 21:13:11

标签: package nuget docusignapi

我正在尝试写一个我在Docusign上传的模板。到目前为止,我在Developer sandbox中创建了一个帐户,上传了一个模板,并在Docusign的模板中创建了几个文本字段。

现在我想从.NET应用程序中写入这些字段。我在我的应用程序中安装了Docusign Nuget Package。

我没有找到任何使用Nuget Package解决我的问题的例子。

以下是我的准则。我可以登录Docusign,这一步很清楚。以下是信封创作。有人可以帮助我使用Docusign Nuget Package将TextFields / Email Fields的值写入模板(上传到Docusign Dev帐户)吗? 在此先感谢。

 EnvelopeDefinition envDef = new EnvelopeDefinition();
        envDef.EmailSubject = "[DocuSign C# SDK] - Please sign this doc";
        envDef.TemplateId ="My TemplateID";
        TemplateRole tRole = new TemplateRole();
        tRole.Email = "Email";
        tRole.Name = "Name";
        tRole.RoleName = "RoleName";
        tRole.ClientUserId = "1";

       Text item = new Text();
        item.TabLabel = "fullN";
        item.Value = "Mr.X";
        tRole.Tabs.TextTabs.Add(item);  **Getting Null reference Exception here**

        List<TemplateRole> rolesList = new List<TemplateRole>() { tRole };

        // add the role to the envelope and assign valid templateId from your account
        envDef.TemplateRoles = rolesList;
        envDef.Status = "sent";
        // Use the EnvelopesApi to send the signature request!
        EnvelopesApi envelopesApi = new EnvelopesApi();
        EnvelopeSummary envelopeSummary = envelopesApi.CreateEnvelope(accountId, envDef);
        string EnvelopeId = envelopeSummary.EnvelopeId;

1 个答案:

答案 0 :(得分:0)

下面是创建信封并将其发送到一个/多个电子邮件ID进行签名的示例。

private void CreateSendEnvelope(string accountID)
    {
        string pdfPath = Server.MapPath("/Models/myfile.pdf");

        if (!string.IsNullOrEmpty(accountID))
        {
            if (System.IO.File.Exists(pdfPath))
            {
                byte[] fileBytes = System.IO.File.ReadAllBytes(pdfPath);


                EnvelopeDefinition envDef = new EnvelopeDefinition();
                envDef.EmailSubject = "DocuSign - Please sign this doc";
                Document doc = new Document();
                doc.DocumentBase64 = System.Convert.ToBase64String(fileBytes);
                doc.Name = "myfile.pdf";
                doc.DocumentId = "1";

                envDef.Documents = new List<Document>();
                envDef.Documents.Add(doc);

                Signer signer = new Signer();
                signer.Email = "James@bond.com";
                signer.Name = "James Bond";
                signer.RecipientId = "1";
                signer.Tabs = new Tabs();
                signer.Tabs.SignHereTabs = new List<SignHere>();
                SignHere signHere = new SignHere();
                signHere.DocumentId = "1";
                signHere.PageNumber = "1";
                signHere.RecipientId = "1";
                signHere.AnchorXOffset= "1";
                signHere.AnchorXOffset= "0";
                signHere.Name = "James Bond";


                FullName fullName = new FullName();
                fullName.AnchorString = "Applicant Name";
                fullName.AnchorUnits = "inches";
                fullName.AnchorXOffset = "1.5";
                fullName.AnchorYOffset = "0";
                fullName.DocumentId = "2";
                fullName.AnchorIgnoreIfNotPresent = "false";
                fullName.Name = "James Bond";

                signer.Tabs.FullNameTabs = new List<FullName>();
                signer.Tabs.FullNameTabs.Add(fullName);

                Date date = new Date();
                date.AnchorString = "Date";
                date.AnchorUnits = "inches";
                date.AnchorXOffset = "1";
                date.AnchorYOffset = "-0.5";
                date.DocumentId = "2";
                date.AnchorIgnoreIfNotPresent = "true";
                DateTime loca = DateTime.Now;
                date.Value =  loca.Date.ToString();
                signer.Tabs.DateTabs = new List<Date>();
                signer.Tabs.DateTabs.Add(date);



                signer.Tabs.SignHereTabs.Add(signHere);

                envDef.Recipients = new Recipients();
                envDef.Recipients.Signers = new List<Signer>();
                envDef.Recipients.Signers.Add(signer);

                //set envelope status to "sent" to immediately send the signature request 
                envDef.Status = "sent";


                // |EnvelopesApi| contains methods related to creating and sending Envelopes (aka signature requests) 
                EnvelopesApi envelopesApi = new EnvelopesApi(cfi);
                EnvelopeSummary envelopeSummary = envelopesApi.CreateEnvelope(accountID, envDef);

                // print the JSON response 
                Console.WriteLine("EnvelopeSummary:\n{0}", JsonConvert.SerializeObject(envelopeSummary));

            }