c#


DocuSign - RestApi v2 - download document using C#


I'm trying to retrieve a signed document via RestAPI v2 with below code.
url = baseURL + "/accounts/" + "3602fbe5-e11c-44de-9e04-a9fc9aa2aad6" + "/envelopes/" + envId + "/documents/combined";
HttpWebRequest request4 = (HttpWebRequest)WebRequest.Create(url);
request4.Method = "GET";
request4.Headers.Add("X-DocuSign-Authentication", authHeader);
request4.Accept = "application/pdf";
request4.ContentType = "application/json";
request4.ContentLength = 0;
HttpWebResponse webResponse4 = (HttpWebResponse)request4.GetResponse();
StreamReader objSR = new StreamReader(webResponse4.GetResponseStream());
StreamWriter objSW = new StreamWriter(#"C:\Users\reddy\Desktop\Docusign\test_" + envId + ".pdf");
objSW.Write(objSR.ReadToEnd());
objSW.Close();
objSR.Close();
With above code, I'm able to save a PDF file but something is not right. Can someone help me fix my buggy code.
Downloaded Document:
Original document:
Option 1: You can simply use the System.Net.WebClient class
string url = baseURL + "/accounts/" + accountId + "/envelopes/" + envId + "/documents/combined";
string path = #"C:\Users\reddy\Desktop\Docusign\test_" + envId + ".pdf";
using (var wc = new System.Net.WebClient())
{
wc.Headers.Add("X-DocuSign-Authentication", authHeader);
wc.DownloadFile(url, path);
}
Option 2 : Copy the input stream to the output FileStream
var request = (HttpWebRequest)WebRequest.Create(url);
request.Method = "GET";
request.Headers.Add("X-DocuSign-Authentication", authHeader);
using (var response = (HttpWebResponse)request.GetResponse())
{
using (var stream = File.Create(path))
response.GetResponseStream().CopyTo(stream);
}
Option 3 : Using the DocuSign C# SDK
See full code here
var envApi = new EnvelopesApi();
var docStream = envApi.GetDocument(accountId, envelopeId, "combined");
using (var stream = File.Create(filePath))
docStream.CopyTo(stream);
Also see this answer

Related Links

Unable to cast object in WPF MultiValueConverter
Epplus Hyper Link without Under-line
I get an error while trying to assign Dictionary<string, object> to a string variable
Comparing Arrays while using substrings
Invalid column name when inserting - Entity Framework
Socketio - flask server and c# client
Error when I am trying to establishing a client and server connection using SignalR
Destroy Image after loading it to ImageList in C#
Need help in integrating libvlc with drm encrypted media content [.mlv file]
C# deserialize datetime from xml
Change Database Source Depending on Login Credentials
Debug / release mode — different behavior [duplicate]
Implementing custom popup menul IntelliSense support on visual studio
Automapper based convertion from Datatable to generic type not working
Live FLV streaming in C# WebApi
Difference DNX and .NET Core

Categories

HOME
google-cloud-pubsub
marie
mobile
ldap
window.open
android-ndk
highmaps
watson-iot
runtime
gcloud
openbsd
watson-dialog
element
google-closure-compiler
tag-cloud
k-means
google-calendar-api3
md2
google-street-view
sonarlint
polybase
serenity-js
prepros
ecmascript-2017
grunt-contrib-uglify
datanucleus
inspec
scripting-language
dynamics-ax-2012-r3
jbossfuse
spring-data-gemfire
recreate
qt-designer
favorites
ragel
stencyl
lex
scalamock
ssdp
pyexcel
collation
quartz
bzip2
test-kitchen
libzip
azure-data-catalog
easyquery
denodo
vertex
sharpssh
boost-regex
google-scholar
directinput
alarmmanager
universe
recurring
sprockets
gdi
sbt-proguard
boost-bind
angular-i18n
calc
dcast
dday
ios8-share-extension
webservices-client
serial-communication
updating
om
log4cxx
photogrammetry
launcher
jsonschema2pojo
clearcanvas
agent-based-modeling
rails-migrations
class-library
cab
record-locking
mosix
pudb
spawn
generator-expression
mmo
blotter
tasklist
junit-rule
wpml
hypertable
aspmenu-control
diazo
capitalization
youtube.net-api
dongle
xslt-grouping
bootstrap-protocol
disk-based

Resources

Encrypt Message