SubmitwithFile - C#
Copy
// DocumentNOW V2 SubmitWithFile example
// force TLS 1.2 if .net < 4.6
ServicePointManager.SecurityProtocol = System.Net.SecurityProtocolType.Tls12;
Guid accountContextID = new Guid(<fromYourAccount>);
Guid templateID = new Guid(<yourTemplateId>);
// assuming we set the namespace on the service proxy to DocNow ...
// there are multiple bindings for submit, so pass in whichever you want to use
DocNow.SubmitServiceClient submitter = new DocNow.SubmitServiceClient("BasicHttpBinding_ISubmitService");
DocNow.FileDocument doc = new DocNow.FileDocument();
doc.ContextIdentifier = accountContextID;
doc.Template = new DocNow.Template();
doc.Template.Id = templateID;
doc.Metadata = new DocNow.Metadata();
doc.Metadata.UserName = "me@mydomain.com";
doc.Metadata.DocumentName = "testing" + DateTime.Today.Ticks.ToString();
// omit this if an EnvelopeId is specified
doc.Metadata.ExpirationDate = DateTime.Today.AddDays(5);
// if this document exists in an envelope created by CreatEnvelope, pass an EnvelopeId
// doc.Metadata.EnvelopeId = envelopeID;
// doc.Metadata.EnvelopeIdSpecified = true;
// template parameters will be relative to the template you are using, this is just an example
doc.Template.Parameters = new DocNow.Parameter[4];
doc.Template.Parameters[0] = new DocNow.Parameter();
doc.Template.Parameters[1] = new DocNow.Parameter();
doc.Template.Parameters[2] = new DocNow.Parameter();
doc.Template.Parameters[3] = new DocNow.Parameter();
doc.Template.Parameters[0].Name = "Signatory 1 Email Address";
doc.Template.Parameters[0].Value = "mysigner@mydomain.com";
doc.Template.Parameters[1].Name = "Signatory 1 First Name";
doc.Template.Parameters[1].Value = "John";
doc.Template.Parameters[2].Name = "Signatory 1 Last Name";
doc.Template.Parameters[2].Value = "Doe";
doc.Template.Parameters[3].Name = "Passed in data";
doc.Template.Parameters[3].Value = "xxxxxxxxxxxxxxx";
string docPath = "C:\\yourdocument.docx";
byte[] bytes = File.ReadAllBytes(docPath);
doc.UnderlyingFile = new DocNow.UnderlyingFile();
doc.UnderlyingFile.Data = bytes;
doc.UnderlyingFile.FileType = DocNow.SupportedFileType.DOCX; //adjust appropriately
DocNow.DocumentResult[] results = submitter.SubmitWithFile(new DocNow.FileDocument[] { doc });
if (results.Length > 0)
{
if (results[0].Exceptions != null)
{
StringBuilder sb = new StringBuilder();
foreach (DocNow.DocumentException exception in results[0].Exceptions)
{
sb.AppendFormat("{0} : {1}{2}", exception.Severity.ToString(), exception.Value, Environment.NewLine);
}
Console.WriteLine(sb.ToString());
}
else
{
// documentID will be results[0].Id;
// authtoken for the document will be results[0].AuthToken;
}
}