How to get files signed
We will use the same code as the example before (using files path), and try to send a message with files to sign by a client and the owner.
Note
After the execution of this code, the first signatory will receive the document to be signed, then he will sign and finalise it, and the owner will receive the document as the last signatory.
Setting files to sign
To send a file to sign, you must specify the filesPath or fileArgs of your PDF documents in the right properties by adding the following code:
1. Create a list of SignFilesRequired
This list determines which file needs to be signed by the recipient. You can send files with a signature, and others without, in the same request.
List<SignFilesRequired> signFiles = new List<SignFilesRequired>();
2. Create a dictionnary of RecipientInfo with zones
We create a dictionnary of RecipientInfo with FileZoneDefinition to define different signature zones for each recipient.
var recipientIndex = new Dictionary<RecipientInfo, List<FileZoneDefinition>>();
3. Choose the file to sign
We gonna set the file to be sign by the recipient and the owner. You must add the SHA512 for each file in the list that needs to be signed.
Note
You can use the list of path (String) if you use the files path, or iterate around your FileArgs list if you use binaries files.
// 1. Retreived the SHA512 of 1st file need to be signed, use the CryptoHelper.GetSHA512OfFile to retreived the SHA512 of the file
string SHA512 = CryptoHelper.GetSHA512OfFile(filesPathList[0]);
// 2. Add that checksum to the signFilesRequired list
signFiles.Add(new SignFilesRequired()
{
SHA512 = SHA512,
DoNotAppendCertificateToFile = true
});
4. Setting zones for the recipient
We set the defined zones for the specified file for the recipient.
// 1. We create zones by calling the CreateField methods
var recipientZones = new SignZoneDetails[]
{
SignHelper.CreateFieldTextZone(filePath, 1, "myText", 10, 700, 100, 40, "A text here!!", 20, true),
SignHelper.CreateFieldNumberZone(filePath, 1, "myNumber", 10, 600, 100, 40, "", 24),
SignHelper.CreateFieldDateSignZone(filePath, 1, "myDateSign", 10, 500, 100, 40, 12, "dd-MM-yyyy"),
SignHelper.CreateFieldDateZone(filePath, 1, "myDatePicker", 10, 400, 100, 40, 24, "MM-dd-yyyy"),
SignHelper.CreateFieldSignZone(filePath, 1, "mySignature", 10, 300, 100, 40),
SignHelper.CreateFieldInitialZone(filePath, 1, "myInitial", 10, 200, 100, 40),
SignHelper.CreateFieldCheckBoxZone(filePath, 1, "myCheckBox1", 10, 100, 20, 20),
SignHelper.CreateFieldCheckBoxZone(filePath, 1, "myCheckBox2", 40, 100, 20, 20, true),
SignHelper.CreateFieldCheckBoxZone(filePath, 1, "myCheckBox3", 70, 100, 20, 20, false, true),
SignHelper.CreateFieldRadioZone(filePath, 1, "myRadio_g1" , 10, 60, 20, 20, Guid.NewGuid().ToString(), false),
SignHelper.CreateFieldRadioZone(filePath, 1, "myRadio_g1" , 40, 60, 20, 20, Guid.NewGuid().ToString(), true),
SignHelper.CreateFieldRadioZone(filePath, 1, "myRadio_g2" , 70, 60, 20, 20, Guid.NewGuid().ToString(), false),
SignHelper.CreateFieldRadioZone(filePath, 1, "myRadio_g2" ,100, 60, 20, 20, Guid.NewGuid().ToString(), false)
};
// 2. Here we choose the recipient to sign with zones
recipientIndex.Add(recipientList[0], new List<FileZoneDefinition>()
{
new FileZoneDefinition
{
UniqueName = SHA512,
ZonesDef = new SignZoneDefinition
{
Zones = recipientZones
}
}
});
5. Adding zones for owner
We set the owner by creating a new RecipientInfo with the "owner" as Email.
// 1. We create zones by calling the CreateField methods
var ownerZones = new SignZoneDetails[]
{
SignHelper.CreateFieldTextZone(filePath, 1, "myText2", 200, 700, 100, 40, "A text here for owner!!", 24, true),
SignHelper.CreateFieldDateSignZone(filePath, 1, "myDateSign2", 200, 500, 100, 40, 12, "dd-MM-yyyy"),
SignHelper.CreateFieldSignZone(filePath, 1, "mySignature2", 200, 300, 100, 40)
};
// 2. Here we set the owner to sign with zones
recipientIndex.Add(new RecipientInfo() { Email = "owner" }, new List<FileZoneDefinition>()
{
new FileZoneDefinition
{
UniqueName = SHA512,
ZonesDef = new SignZoneDefinition
{
Zones = ownerZones
}
}
});
6. We need to add the FileToSign to the args
If we have some files to sign, we add them to the args.
Note
Note that you can send files without signature only to the first recipient, if you have multiple recipient.
if (signFiles.Count > 0)
{
// You must also set the property FileToSign in the MutliRecipientArgs, The FileToSign property is a list of SignFilesRequired.
arg.FileToSign = signFiles;
// If the owner of the licence need to sign the file, set the OwnerDontNeedToSign property to false.
// If it's set to false, the licence owner will receive an email when the file will be ready to sign by him
arg.OwnerDontNeedToSign = false;
// Set the recipient zone definition
arg.SignRecipientsZoneDef = SignHelper.ConvertRecipientIndexToList(recipientIndex);
}
See the complete example bellow:
internal class Program
{
static Guid serial = new Guid("CF97C28F-CEAE-4FE3-B5CE-1D65AFF21039");
static Guid APIuser = new Guid("42A24D7D-256C-4671-86C0-3381CFA228DC");
static Guid APIpassword = new Guid("8097AF06-ADAD-4FB5-ADAF-C0AEF84727FF");
static Uri endpoint = new Uri("https://www.secure-exchanges.com/_api/0217/0217.asmx");
static void Main(string[] args)
{
// Create a recipient list and add a recipient
List<RecipientInfo> recipientList = new List<RecipientInfo>();
recipientList.Add(new RecipientInfo() { Email = "example@secure-exchanges.com" });
// The message you want to send. That string could be HTML
string message = "My <strong>HTML</strong> message";
// The subject of the email
string subject = "My subject";
// Set a password to your message
string password = null;
// Use that list to set binary files
List<FileArgs> binaryFiles = new List<FileArgs>();
// The method you want to use to send your message the supported values are
// onlyEmail => Send only by email
// onlySMS => Send only by SMS
// msgEmailCodeSMS => The message will be send by email, and the dynamic opening code will be sent by SMS
// msgSMSCodeEmail => The message will be send by sms and the dynamic opening code will be sent by email
var sendMethod = SecureExchangesSDK.SecureExchanges.SendMethodEnum.onlyEmail;
// Set to true to send with your own Smtp server
bool sendByMyOwnSMTPServer = false;
// The subject will be show
bool showSubject = true;
// Set this parameter to false if you don't want to be notify by email on opening
bool getNotify = true;
// Set the culture of the message, the supported culture are fr-CA and en-CA
string culture = "en-CA";
// The number of time that the message will be allowed to be open by the recipient
int maxOpeningTime = 5;
// The delay in minutes before your message expired, the maximum time is 43200 (30 days)
int expirationMinutes = 30;
// Create MutliRecipientArgs that contains message arguments.
// Here in our exemple we need SDK keys, endPoint, recipients list,
// message text, subject, culture, max open time and minute expiration
var arg = new SecureExchangesSDK.Models.Args.MutliRecipientArgs(
endpoint, serial, APIuser, APIpassword, recipientList,
message, subject, password, binaryFiles,
sendMethod, sendByMyOwnSMTPServer, showSubject,
getNotify, culture, maxOpeningTime, expirationMinutes
);
// ============================ USING FILES PATH ===============================
// Create a files path list and add a file path
var filesPathList = new List<string>();
var filePath = @"c:\temp\document.pdf";
filesPathList.Add(filePath);
arg.FilesPath = filesPathList; // Assign the files path list to the args
// ============================ USING FILES PATH ===============================
// ============================ SET FILES TO SIGN ==============================
// Create a list of SignFilesRequired
// The List determine in your files wich one need to be sign by the recipient, you can send files with signature, and some witout signature in the same sent
List<SignFilesRequired> signFiles = new List<SignFilesRequired>();
// Create a dictionnary of recipients info with FileDefinition signatures to define the zones of the differents fields for each recipients
var recipientIndex = new Dictionary<RecipientInfo, List<FileZoneDefinition>>();
// We gonna set the file to be sign by the recipient and the owner.
// You must add the SHA512 for each file in the list that needs to be signed.
// You can use the list of path (String) if you use the files path, or iterate around your FileArgs list if you use binaries files.
// 1. Retreived the SHA512 of 1st file need to be signed, use the CryptoHelper.GetSHA512OfFile to retreived the SHA512 of the file
string SHA512 = CryptoHelper.GetSHA512OfFile(filesPathList[0]);
// 2. Add that checksum to the signFilesRequired list
signFiles.Add(new SignFilesRequired()
{
SHA512 = SHA512,
DoNotAppendCertificateToFile = true
});
// Setting zones for the recipient.
// We set the defined zones for the specified file for the recipient.
// 1. We create zones by calling the CreateField methods
var recipientZones = new SignZoneDetails[]
{
SignHelper.CreateFieldTextZone(filePath, 1, "myText", 10, 700, 100, 40, "A text here!!", 20, true),
SignHelper.CreateFieldNumberZone(filePath, 1, "myNumber", 10, 600, 100, 40, "", 24),
SignHelper.CreateFieldDateSignZone(filePath, 1, "myDateSign", 10, 500, 100, 40, 12, "dd-MM-yyyy"),
SignHelper.CreateFieldDateZone(filePath, 1, "myDatePicker", 10, 400, 100, 40, 24, "MM-dd-yyyy"),
SignHelper.CreateFieldSignZone(filePath, 1, "mySignature", 10, 300, 100, 40),
SignHelper.CreateFieldInitialZone(filePath, 1, "myInitial", 10, 200, 100, 40),
SignHelper.CreateFieldCheckBoxZone(filePath, 1, "myCheckBox1", 10, 100, 20, 20),
SignHelper.CreateFieldCheckBoxZone(filePath, 1, "myCheckBox2", 40, 100, 20, 20, true),
SignHelper.CreateFieldCheckBoxZone(filePath, 1, "myCheckBox3", 70, 100, 20, 20, false, true),
SignHelper.CreateFieldRadioZone(filePath, 1, "myRadio_g1" , 10, 60, 20, 20, Guid.NewGuid().ToString(), false),
SignHelper.CreateFieldRadioZone(filePath, 1, "myRadio_g1" , 40, 60, 20, 20, Guid.NewGuid().ToString(), true),
SignHelper.CreateFieldRadioZone(filePath, 1, "myRadio_g2" , 70, 60, 20, 20, Guid.NewGuid().ToString(), false),
SignHelper.CreateFieldRadioZone(filePath, 1, "myRadio_g2" ,100, 60, 20, 20, Guid.NewGuid().ToString(), false)
};
// 2. Here we choose the recipient to sign with zones
recipientIndex.Add(recipientList[0], new List<FileZoneDefinition>()
{
new FileZoneDefinition
{
UniqueName = SHA512,
ZonesDef = new SignZoneDefinition
{
Zones = recipientZones
}
}
});
// Adding zones for owner
// We set the owner by creating a new RecipientInfo with the "owner" as Email.
// 1. We create zones by calling the CreateField methods
var ownerZones = new SignZoneDetails[]
{
SignHelper.CreateFieldTextZone(filePath, 1, "myText2", 200, 700, 100, 40, "A text here for owner!!", 24, true),
SignHelper.CreateFieldDateSignZone(filePath, 1, "myDateSign2", 200, 500, 100, 40, 12, "dd-MM-yyyy"),
SignHelper.CreateFieldSignZone(filePath, 1, "mySignature2", 200, 300, 100, 40)
};
// 2. Here we set the owner to sign with zones
recipientIndex.Add(new RecipientInfo() { Email = "owner" }, new List<FileZoneDefinition>()
{
new FileZoneDefinition
{
UniqueName = SHA512,
ZonesDef = new SignZoneDefinition
{
Zones = ownerZones
}
}
});
// If we have some file to sign, we add them to the args
// Notes that you can send files without signature only to the first recipient, if you have multiple recipient.
if (signFiles.Count > 0)
{
// You must also set the property FileToSign in the MutliRecipientArgs, The FileToSign property is a list of SignFilesRequired.
arg.FileToSign = signFiles;
// If the owner of the licence need to sign the file, set the OwnerDontNeedToSign property to false.
// If it's set to false, the licence owner will receive an email when the file will be ready to sign by him
arg.OwnerDontNeedToSign = false;
// Set the recipient zone definition
arg.SignRecipientsZoneDef = SignHelper.ConvertRecipientIndexToList(recipientIndex);
}
// ============================ SET FILES TO SIGN ==============================
// We call MultiRecipientMessage with the arguments to send the message to the recipients.
// We get a MultiRecipientAnswer.
var messageAnswer = SecureExchangesSDK.Helpers.MessageHelper.MultiRecipientMessage(arg);
// The status code 200 mean the message has been sent with success.
if (messageAnswer.Status == 200)
{
Console.WriteLine("Your message has been sent successfully");
foreach(var recipientAnswer in messageAnswer.RecipientsAnswer)
{
// That is the answer for each recipient in the list
Console.WriteLine($"The status is {recipientAnswer.Answer.Status}");
Console.WriteLine($"The url of the message is {recipientAnswer.Answer.URL}");
Console.WriteLine($"The HTML of the message is {recipientAnswer.Answer.HtmlMsg}");
}
}
// If someting wrong you will find the reason in the data properties
else
{
Console.WriteLine(messageAnswer.Data); // the reason why the call fail
}
}
}