SPWorkflowTask.AlterTask throws "Specified method is not supported" - sharepoint

I'm trying to call AlterTask on a newly created Sharepoint task to add extended properties to my task, and a NotSupportedException is thrown.
What's going on?

The newly created task is actually a SharePoint ListItem. ExtendedProperties is specifically a Workflow Task property.
As per the MSDN documentation:
The content type of the item passed to the task parameter is not derived from the WorkflowTask content type.
This means that Content Type of the SPListItem that represents your new Task must be set to "Workflow Task" before the AlterTask method can be called on it:
Dim selectedTaskList As SPList = web.Lists(taskListName)
' Create a new task item
Dim newTask As SPListItem = selectedTaskList.Items.Add()
' Turn the new task item into a Workflow Task
Dim newTaskContentType As Microsoft.SharePoint.SPContentType = web.AvailableContentTypes("Workflow Task")
newTask("ContentTypeId") = newTaskContentType.Id
' Now the AlterTask method will work. (assume you've alreade declared a hashtable of properties to set)
Microsoft.SharePoint.Workflow.SPWorkflowTask.AlterTask(newTask, myHashTable, True)

Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
Dim IntItemID As Integer
Dim siteId As Guid = SPContext.Current.Site.ID
Dim webId As Guid = SPContext.Current.Web.ID
Using objSpSite As New SPSite(siteId)
Using objSpWeb As SPWeb = objSpSite.OpenWeb(webId)
If Not Page.Request.QueryString("ItemID") Is Nothing And Page.Request.QueryString("ItemID") <> "" Then
IntItemID = CInt(Page.Request.QueryString.Item("ItemID").ToString)
Panel1.Visible = False
txtID.Text = IntItemID.ToString
Dim objList As SPList = objSpWeb.Lists("RequestList")
Dim objListItem As SPListItem = objList.Items.GetItemById(IntItemID)
dtPermission.SelectedDate = objListItem("PermissionDate")
dtTimeFrom.SelectedDate = objListItem("PermissionFromTime")
dtTimeTo.SelectedDate = objListItem("PermissionToTime")
cmbType.SelectedValue = objListItem("PermissionType")
'dtCreated.SelectedDate = objListItem("")
Else
IntItemID = 0
txtID.Text = "New"
dtCreated.SelectedDate = Today
txtCreatedBy.Text = objSpWeb.CurrentUser.Name
Dim objServiceContext As SPServiceContext = SPServiceContext.GetContext(objSpSite)
Dim objUserProfileManager As New UserProfileManager(objServiceContext)
Dim objUserProfile As UserProfile
Dim strUserAccount As String
strUserAccount = objSpWeb.CurrentUser.LoginName.Replace("i:0#.w|", "")
If objUserProfileManager.UserExists(strUserAccount) Then
objUserProfile = objUserProfileManager.GetUserProfile(strUserAccount)
Try
txtManager.Text = objUserProfile.GetManager.AccountName
Catch ex As Exception
txtManager.Text = ex.Message
End Try
End If
Panel2.Visible = False
End If
End Using
End Using
End Sub
Protected Sub cmdSubmit_Click(sender As Object, e As EventArgs) Handles cmdSubmit.Click
Dim siteId As Guid = SPContext.Current.Site.ID
Dim webId As Guid = SPContext.Current.Web.ID
Using objSpSite As New SPSite(siteId)
Using objSpWeb As SPWeb = objSpSite.OpenWeb(webId)
objSpWeb.AllowUnsafeUpdates = True
Dim list As SPList = objSpWeb.Lists("RequestList")
Dim item As SPListItem = list.Items.Add()
item("PermissionDate") = dtPermission.SelectedDate
item("PermissionFromTime") = dtTimeFrom.SelectedDate
item("PermissionToTime") = dtTimeTo.SelectedDate
item("PermissionType") = cmbType.SelectedValue
item("PermissionApprover1") = txtManager.Text
item.Update()
list.Update()
objSpWeb.AllowUnsafeUpdates = False
End Using
End Using
End Sub
Protected Sub cmdApprove_Click(sender As Object, e As EventArgs) Handles cmdApprove.Click
Dim siteId As Guid = SPContext.Current.Site.ID
Dim webId As Guid = SPContext.Current.Web.ID
Using objSpSite As New SPSite(siteId)
Using objSpWeb As SPWeb = objSpSite.OpenWeb(webId)
Dim objList As SPList = objSpWeb.Lists("RequestList")
Dim objListItem As SPListItem = objList.Items.GetItemById(CInt(txtID.Text))
Dim objWFTask As SPWorkflowTask = objListItem.Tasks(0)
If objWFTask Is Nothing Then
' no matching task
Return
End If
' alter the task
Dim ht As New Hashtable()
ht("Status") = "Complete"
ht("PercentComplete") = 1.0F
SPWorkflowTask.AlterTask(TryCast(objWFTask, SPListItem), ht, True)
End Using
End Using

Related

Read from Excel - write to CSV in different column order

I need to understand if there is a possibility, within VB.NET, to be able to read the columns of an Excel file and write them out to a CSV file in a different order.
In practice, the Excel file we are sent has 6 columns: "amount", "branch", stock "," proposal "," quantity "," type ". The company management system accepts the text file with the columns in a different order: "branch", "stock", "amount", "quantity", "type", "proposal". This creates a problem for me because when I go to convert it my ERP fails to recognize that the column is in a different position.
I arrive at the concrete question, I would like to have the possibility to read the columns and make it possible through a script to be able to position them according to the position I decide.
I tried this code for import and convert to txt, but I need another script:
Imports System.IO
Imports ExcelDataReader
Imports System.Text
Public Class Form1
Dim tables As DataTableCollection
Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
Using ofd As OpenFileDialog = New OpenFileDialog() With {.Filter = "(*.xls)|*.xls|(*.xls)|*.xlsx"}
If ofd.ShowDialog() = DialogResult.OK Then
txtFileName.Text = ofd.FileName
Using Stream = File.Open(ofd.FileName, FileMode.Open, FileAccess.Read)
Using reader As IExcelDataReader = ExcelReaderFactory.CreateReader(Stream)
Dim result As DataSet = reader.AsDataSet(New ExcelDataSetConfiguration() With {
.ConfigureDataTable = Function(__) New ExcelDataTableConfiguration() With {
.UseHeaderRow = True}})
tables = result.Tables
cboSheet.Items.Clear()
For Each table As DataTable In tables
cboSheet.Items.Add(table.TableName)
Next
End Using
End Using
End If
End Using
End Sub
Private Sub cboSheet_SelectedIndexChanged(sender As Object, e As EventArgs) Handles cboSheet.SelectedIndexChanged
Dim dt As DataTable = tables(cboSheet.SelectedItem.ToString())
dgProposte.DataSource = dt
End Sub
Private Sub Button2_Click(sender As Object, e As EventArgs) Handles Button2.Click
Dim writer As TextWriter = New StreamWriter("C:\Users\antonio\Desktop\Prova.txt")
For i As Integer = 0 To dgProposte.Rows.Count - 2 Step +1
For j As Integer = 0 To dgProposte.Columns.Count - 1 Step +1
writer.Write(vbTab & dgProposte.Rows(i).Cells(j).Value.ToString() & vbTab & "")
Next
writer.WriteLine("")
Next
writer.Close()
MessageBox.Show("Dati Esportati")
End Sub
The tables that you get from importing the Excel sheet(s) have their column names set, and you can index the column by its name.
So, and with a little adjustment to factor out some methods:
Imports System.IO
Imports ExcelDataReader
Public Class Form1
Dim tables As DataTableCollection
Private Sub WriteToCsv(tableName As String, filename As String)
Dim columnWriteOrder = {"branch", "stock", "amount", "quantity", "type", "proposal"}
Using writer As TextWriter = New StreamWriter(filename)
Dim tbl = tables(tableName)
For i As Integer = 0 To dgProposte.Rows.Count - 2
Dim vals As New List(Of String)
For j As Integer = 0 To columnWriteOrder.Length - 1
Dim val = tbl.Rows(i).Item(columnWriteOrder(j)).ToString()
vals.Add(val)
Next
writer.WriteLine(String.Join(vbTab, vals))
Next
End Using
End Sub
Private Sub PopulateSheetNames()
cboSheet.Items.Clear()
For Each table As DataTable In tables
cboSheet.Items.Add(table.TableName)
Next
End Sub
Private Sub cboSheet_SelectedIndexChanged(sender As Object, e As EventArgs) Handles cboSheet.SelectedIndexChanged
If cboSheet.SelectedIndex >= 0 Then
Dim tableName = cboSheet.SelectedItem.ToString()
Dim dt As DataTable = tables(tableName)
dgProposte.DataSource = dt
End If
End Sub
Private Sub bnLoad_Click(sender As Object, e As EventArgs) Handles bnLoad.Click
Using ofd As OpenFileDialog = New OpenFileDialog() With {.Filter = "(*.xlsx)|*.xlsx|(*.xls)|*.xls", .InitialDirectory = "C:\temp"}
If ofd.ShowDialog() <> DialogResult.OK Then
Exit Sub
End If
txtFileName.Text = ofd.FileName
Using Stream = File.Open(ofd.FileName, FileMode.Open, FileAccess.Read)
Using reader As IExcelDataReader = ExcelReaderFactory.CreateReader(Stream)
Dim edsc = New ExcelDataSetConfiguration() With {
.ConfigureDataTable = Function(__) New ExcelDataTableConfiguration() With {
.UseHeaderRow = True}}
Dim result As DataSet = reader.AsDataSet(edsc)
tables = result.Tables
End Using
End Using
PopulateSheetNames()
End Using
End Sub
Private Sub bnSaveAsCsv_Click(sender As Object, e As EventArgs) Handles bnSaveAsCsv.Click
If cboSheet.SelectedIndex < 0 Then
MessageBox.Show("Please select a sheet name.", "No sheet name selected", MessageBoxButtons.OK, MessageBoxIcon.Information)
Exit Sub
End If
Dim sheetName = cboSheet.SelectedItem.ToString()
If Not String.IsNullOrEmpty(sheetName) Then
WriteToCsv(sheetName, "C:\temp\Prova.csv")
MessageBox.Show("Dati Esportati.", "Dati Esportati", MessageBoxButtons.OK, MessageBoxIcon.Information)
End If
End Sub
End Class
I changed the names of the buttons because "Button1" and "Button2" are not descriptive.
(I set the .InitialDirectory of the OpenFileDialog because it was convenient for me.)
Why you don't map a DTO of your data table?
Public Class MioDto
Property campoUno As String
Property campoDue As String
'...ecc
End Class
and then you can fill a dto in a cicle or so...
Dim a As New MioDto() With {.campoUno="...", campoDue="..."}
or if you want you can use
https://github.com/AutoMapper/AutoMapper
When you have a Dto class filled you can use it for generate your txt with youor preferred order.

Sub or Function Not Defined Error - Sub in Class Module

I am attempting to pass values from an ADODB.Recordset into a Class Module and am receiving the Sub or Function Not Defined Error when I call Call PopulateJHAData(GeneralInfo.Range("genLoanProg"), CStr(nm)) from within the function to get the data from the recordset; I know i dont need Call in front of the sub; I was just seeing if it made any difference. I can already imagine that there are a host of other items that are wrong with this code since I am just now getting into how to use Class Modules.
'---Class Loan Info
Public LoanNumber As String
Public InterestRate As String
Public OriginalAmount As Double
Public OriginationDate As String
Public MaturityDate As Date
Public NextPaymentDate As Date
Public PaymentAmount As Double
Public Census As String
Public RateNumber As Long
Public Margin As String
Public RoundTo As String
Public RateCeiling As String
Public RateChangeDate As Date
Public ARMNotice As String
Public QualifiedMortgageCode As String
Public ln1098 As String
Public CallReportCode As String
Public CollateralCode As String
Public PurposeCode As String
Public HPML As String
Public LoanTypeCode As String
Public Flood As String
Public CLTV As String
Public Branch As Long
Public FHLBElig As String
Public RepToCB As String
Public Occupancy As String
Public tName As String
Public eNumber As Long
Public Sub PopulateJHAData(ByVal LoanProg As String, ByVal TableName As String, ByVal JHALoanInfo As ADODB.Recordset)
Select Case Left(LoanProg, 4)
Case Is = "FHLB", "Cons", "15yr"
InterestRate = Trim(JHALoanInfo.Fields("Rate").Value)
LoanAmount = Trim(JHALoanInfo.Fields("OrigAmnt").Value)
LoanDate = Trim(JHALoanInfo.Fields("OrigDate").Value)
MaturityDate = Trim(JHALoanInfo.Fields("MatDate").Value)
NextPaymentDate = Trim(JHALoanInfo.Fields("NextPmtDate").Value)
PaymentAmount = Trim(JHALoanInfo.Fields("PaymentAmt").Value)
Census = Trim(JHALoanInfo.Fields("Census").Value)
QualifiedMortgageCode = Trim(JHALoanInfo.Fields("QMCode").Value)
ln1098 = Trim(JHALoanInfo.Fields("ln1098").Value)
CallReportCode = Trim(JHALoanInfo.Fields("CallRep").Value)
CollateralCode = Trim(JHALoanInfo.Fields("ColCode").Value)
PurposeCode = Trim(JHALoanInfo.Fields("PurpCode").Value)
HPML = Trim(JHALoanInfo.Fields("HPML").Value)
LoanTypeCode = Trim(JHALoanInfo.Fields("LnTypeCode").Value)
Flood = Trim(JHALoanInfo.Fields("Flood").Value)
CLTV = Trim(JHALoanInfo.Fields("CombLTV").Value)
Branch = Trim(JHALoanInfo.Fields("Branch").Value)
FHLBElig = Trim(JHALoanInfo.Fields("EligFHLV").Value)
RepToCB = Trim(JHALoanInfo.Fields("RepCB").Value)
Occupancy = Trim(JHALoanInfo.Fields("Occupancy").Value)
Case Else
InterestRate = Trim(JHALoanInfo.Fields("Rate").Value)
LoanAmount = Trim(JHALoanInfo.Fields("OrigAmnt").Value)
LoanDate = Trim(JHALoanInfo.Fields("OrigDate").Value)
MaturityDate = Trim(JHALoanInfo.Fields("MatDate").Value)
NextPaymentDate = Trim(JHALoanInfo.Fields("NextPmtDate").Value)
PaymentAmount = Trim(JHALoanInfo.Fields("PaymentAmt").Value)
Census = Trim(JHALoanInfo.Fields("Census").Value)
RateNumber = Trim(JHALoanInfo.Fields("RateNum").Value)
Margin = Trim(JHALoanInfo.Fields("Margin").Value)
RoundTo = Trim(rs.Fields("RoundTo").Value)
RateCeiling = Trim(rs.Fields("RateCeiling").Value)
RateChangeDate = Trim(rs.Fields("RateChangeDate").Value)
ARMNotice = Trim(rs.Fields("ArmNot").Value)
QualifiedMortgageCode = Trim(JHALoanInfo.Fields("QMCode").Value)
ln1098 = Trim(JHALoanInfo.Fields("ln1098").Value)
CallReportCode = Trim(JHALoanInfo.Fields("CallRep").Value)
CollateralCode = Trim(JHALoanInfo.Fields("ColCode").Value)
PurposeCode = Trim(JHALoanInfo.Fields("PurpCode").Value)
HPML = Trim(JHALoanInfo.Fields("HPML").Value)
LoanTypeCode = Trim(JHALoanInfo.Fields("LnTypeCode").Value)
Flood = Trim(JHALoanInfo.Fields("Flood").Value)
CLTV = Trim(JHALoanInfo.Fields("CombLTV").Value)
Branch = Trim(JHALoanInfo.Fields("Branch").Value)
FHLBElig = Trim(JHALoanInfo.Fields("EligFHLV").Value)
RepToCB = Trim(JHALoanInfo.Fields("RepCB").Value)
Occupancy = Trim(JHALoanInfo.Fields("Occupancy").Value)
End Select
End Sub
Sub LoanInfoGrab()
uName = Environ("username")
empName = StrConv(Left(uName, Len(uName) - 1), vbProperCase)
Dim lnNum As String
lnNum = GeneralInfo.Range("genLoanNumber")
msgCap = "Hello " & empName & "," & vbCrLf & _
"The data for " & lnNum & " is not available, or unable to be retrieved." & _
"This loan will need to be manually checked."
Dim LoanRecordGrab As clsLoanInfo
'passing in all potential table names/sources in array
Set LoanRecordGrab = getLoanInfoRecord(Array(CNCTTP08, BHSCHLP8))
Dim nm
If LoanRecordGrab Is Nothing Then
MsgBox msgCap, vbExclamation, "Error Getting Data"
Else
rem not sure if this should be the sub from the class module or if it should be LoanRecordGrab.
'PopulateJHAData GeneralInfo.Range("genLoanProg"), CStr(nm) yet.
End If
JHACheckFormat
Dim lnData As Range, cData1 As Range, cData2 As Range
Set lnData = JHACheck.Range("H7:H32")
Set cData1 = JHACheck.Range("H35:H41")
Set cData2 = JHACheck.Range("K35:K41")
If loanData.Range("CIF_2") = vbNullString Then
CompareJHACheck lnData, cData1
Else
CompareJHACheck lnData, cData1, cData2
End If
End Sub
Function getLoanInfoRecord(arrNames) As clsLoanInfo
Dim conn As New ADODB.Connection
Dim rs As New ADODB.Recordset
Dim SQL As String, nm, okSql As Boolean
Dim LoanRecordGrab As clsLoanInfo
Dim lNum As Range: Set lNum = GeneralInfo.Range("genLoanNumber")
conn.Open CONNSTR
'try each provided name: exit loop on successful query
For Each nm In arrNames
SQL = getLoanDBGrabSQL(CStr(nm), lNum)
On Error Resume Next
rs.Open SQL, conn 'try this name
If Err.Number = CONNECTIONERROR Then
okSql = False
Else
okSql = True
End If
On Error GoTo 0 'cancel on error resume next
If okSql Then
If rs.EOF Then
'rs.MoveFirst
Do While Not rs.EOF
Set LoanRecordGrab = New clsLoanInfo 'create an instance to populate
Call PopulateJHAData(GeneralInfo.Range("genLoanProg"), CStr(nm)) 'Sub or Function not Defined happens here
rs.MoveNext
Loop
End If
Exit For 'done trying names
End If
Next nm
If rs.State = adStateOpen Then rs.Close
If conn.State = adStateOpen Then conn.Close
Set getLoanInfoRecord = LoanRecordGrab
End Function

VB.NET: Excel Crashes when Updating Data in a Word Chart

Update: Releasing objects has no effect on Excel crashing. The problematic line is:
Dim wChartData = wChart.ChartData
I have written a VB.Net application that opens a word document, iterates through the inline shapes, and updates each chart with data from the database. Sometimes Excel will crash when opening the sheet containing the chart data. Can anyone tell me how I fix this?
Here is the code that iterates through the shapes:
wApp = New Word.Application
wApp.Visible = True
wDoc = wApp.Documents.Add("Some_File_Name.docx")
Console.WriteLine("Updating Charts")
Dim chartName As String
For Each wShape As Word.InlineShape In wDoc.InlineShapes
If wShape.HasChart = Core.MsoTriState.msoTrue Then
If wShape.Chart.HasTitle Then
chartName = wShape.Chart.ChartTitle.Text
Else
chartName = "NO_TITLE"
End If
UpdateChart(wShape.Chart, reportID, reportTitle,
reportUser, curriculumYear, chartName)
End If
Next
The UpdateChart subroutine grabs a SQL query and some options related to the chart, then fires off the FillChartData subroutine below:
Public Sub FillChartData(ByRef wChart As Word.Chart, ByVal sql As String,
Optional ByVal addDataPointsToLabels As Boolean = False)
If sql = "" Then Exit Sub
Dim cmd = O.factory.CreateCommand()
cmd.CommandText = sql
cmd.Connection = O.con
O.factory.CreateDataAdapter()
Dim adapter = O.factory.CreateDataAdapter
adapter.SelectCommand = cmd
Dim dt As New System.Data.DataTable()
Dim ds As New System.Data.DataSet()
adapter.Fill(ds, "report_name")
dt = ds.Tables(0)
Dim wChartData = wChart.ChartData
Dim wChartWb As Excel.Workbook = wChartData.Workbook
Dim wChartSheet As Excel.Worksheet = wChartWb.Sheets(1)
Dim title As String = "No title"
If wChart.HasTitle Then title = wChart.ChartTitle.Text.ToString
Dim r As Excel.Range
r = wChartSheet.Range("A1")
r.CurrentRegion.Clear()
For i = 0 To dt.Columns.Count - 1
Dim c As System.Data.DataColumn = dt.Columns(i)
r.Offset(0, i).Value2 = c.ColumnName
Next
r = wChartSheet.Range("A2")
For Each row As System.Data.DataRow In dt.Rows
For i = 0 To row.ItemArray.Count - 1
r.Offset(0, i).Value2 = row.Item(i)
Next
r = r.Offset(1)
Next
r = wChartSheet.Range("A1")
If addDataPointsToLabels Then
While r.Value <> ""
r.Value &= " " & r.Offset(1).Value
r = r.Offset(0, 1)
End While
End If
wChartWb.Close()
releaseObject(r)
releaseObject(wChartSheet)
releaseObject(wChartWb)
releaseObject(wChartData)
r = Nothing
wChartSheet = Nothing
wChartWb = Nothing
wChartData = Nothing
GC.Collect()
End Sub
The releaseObject subroutine is as follows:
Private Sub releaseObject(ByVal obj As Object)
Try
System.Runtime.InteropServices.Marshal.ReleaseComObject(obj)
obj = Nothing
Catch ex As Exception
MessageBox.Show(ex.ToString)
obj = Nothing
End Try
End Sub
And here's the crash report:
Problem signature:
Problem Event Name: APPCRASH
Application Name: EXCEL.EXE
Application Version: 15.0.5007.1000
Application Timestamp: 5a5eb36d
Fault Module Name: EXCEL.EXE
Fault Module Version: 15.0.5007.1000
Fault Module Timestamp: 5a5eb36d
Exception Code: c0000005
Exception Offset: 002b71c8
OS Version: 6.1.7601.2.1.0.256.4
Locale ID: 1033
Additional information about the problem:
LCID: 1033
skulcid: 1033
Read our privacy statement online:
http://go.microsoft.com/fwlink/?linkid=104288&clcid=0x0409
If the online privacy statement is not available, please read our privacy statement offline:
C:\Windows\system32\en-US\erofflps.txt
Thanks for your help!
You need to Activate the Word ChartData object to begin the inter-process communication between Word and Excel.
The example below is a simplified demonstration of code pattern and contains no error handling. This example also demonstrates releasing out of scope COM objects via the garbage collector. See this answer for more discussion on this COM clean-up procedure.
This code was verified against Office 2007.
Imports System.Runtime.InteropServices
Imports Excel = Microsoft.Office.Interop.Excel
Imports Word = Microsoft.Office.Interop.Word
Public Class Form1
Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
InterOpWork("Embedded Excel Chart.docx")
COMCleanup()
End Sub
Sub InterOpWork(filePath As String)
Dim appWord As New Word.Application
Dim doc As Word.Document = appWord.Documents.Open((filePath))
Dim shp As Word.InlineShape = doc.InlineShapes(1)
Dim ch As Word.Chart = shp.Chart
Dim chData As Word.ChartData = ch.ChartData
chData.Activate() ' **** This is what your code is missing
Dim wb As Excel.Workbook = DirectCast(chData.Workbook, Excel.Workbook)
Dim appExcel As Excel.Application = DirectCast(wb.Application, Excel.Application)
Dim ws As Excel.Worksheet = DirectCast(wb.Worksheets("Sheet1"), Excel.Worksheet)
Dim rng As Excel.Range = ws.Range("B2:B4")
Dim dataToChange As Object(,) = DirectCast(rng.Value2, Object(,))
For i As Int32 = dataToChange.GetLowerBound(0) To dataToChange.GetUpperBound(0)
dataToChange(i, 1) = i * 2 + (5 - i)
Next
rng.Value = dataToChange
wb.Save()
wb.Close(False)
appExcel.Quit()
doc.Save()
doc.Close(False)
appWord.Quit()
End Sub
Private Sub COMCleanup()
Do
GC.Collect()
GC.WaitForPendingFinalizers()
Loop While Marshal.AreComObjectsAvailableForCleanup
End Sub
End Class

The data could not be converted

I had a working function call the Docusign SOAP API and now all of the sudden its not working. I get the error "The data could not be converted" when I call the CreateEnvelopeFromTemplatesAndForms method. Here is my code.
Dim _userName As String = ""
Dim _apiUrl As String = "https://demo.docusign.net/api/3.0/api.asmx"
Dim _accountId As String = "d90f6802-fa06-42b4-ac3b-5959c3905002"
Dim _password As String = "WWWxyz123"
Dim _email As String = "JGarland#etgroup.net"
Dim _integratorKey As String = "ETGX-1f61c95b-06bd-400b-9604-f247fda0238c"
Sub Main()
'GetSignatureSpot(Nothing)
'GetPDF()
'GetCertificate()
'Exit Sub
_userName = "[" + _integratorKey + "]"
_userName = _userName & _email
Dim _apiClient As DocuSign.DSAPIServiceSoapClient = New DocuSign.DSAPIServiceSoapClient("DSAPIServiceSoap", _apiUrl)
_apiClient.ClientCredentials.UserName.UserName = _userName
_apiClient.ClientCredentials.UserName.Password = _password
Dim envelopeInfo As DocuSign.EnvelopeInformation = New DocuSign.EnvelopeInformation()
envelopeInfo.AccountId = _accountId
envelopeInfo.EmailBlurb = "Please Sign Your Loan Documents"
envelopeInfo.Subject = "Please Sign Your Loan Documents"
'Recipients
Dim recipient1 As DocuSign.Recipient = New DocuSign.Recipient()
recipient1.UserName = "John Doe"
recipient1.Email = "Support#etgroup.net"
recipient1.Type = DocuSign.RecipientTypeCode.Signer
recipient1.RoutingOrder = 1
recipient1.RoutingOrderSpecified = True
recipient1.RoleName = "Borrower 1"
recipient1.ID = "1"
Dim recipient2 As DocuSign.Recipient = New DocuSign.Recipient()
recipient2.UserName = "Jane Doe"
recipient2.Email = "JGarland#etgroup.net"
recipient2.Type = DocuSign.RecipientTypeCode.Signer
recipient2.RoutingOrder = 2
recipient2.RoutingOrderSpecified = True
recipient2.RoleName = "Borrower 2"
recipient2.ID = "2"
Dim signers(1) As DocuSign.Recipient
signers(0) = recipient1
signers(1) = recipient2
'Create draft with all the composite template information
Dim status As DocuSign.EnvelopeStatus
Dim compositTemplate(1) As DocuSign.CompositeTemplate
Dim template As DocuSign.CompositeTemplate
Dim template2 As DocuSign.CompositeTemplate
'Template 1
template = CreateTemplate(1, "Attorney Selection Notice", "F364E20C-D0E6-4735-89E2-8891424BA364", signers, "AttorneySelection.pdf")
compositTemplate(0) = template
'Template 2
template2 = CreateTemplate(2, "Notice of No Oral", "F5A536C3-81AB-4C32-B56A-9F764624C3C4", signers, "NoticeOral.pdf")
compositTemplate(1) = template2
status = _apiClient.CreateEnvelopeFromTemplatesAndForms(envelopeInfo, compositTemplate, True)
End Sub
Private Function CreateTemplate(sequence As Integer, templateName As String, templateID As String, signers() As DocuSign.Recipient, docPath As String) As DocuSign.CompositeTemplate
Dim template As DocuSign.CompositeTemplate = New DocuSign.CompositeTemplate()
'Server Template
Dim serverTemplate As DocuSign.ServerTemplate = New DocuSign.ServerTemplate()
serverTemplate.Sequence = sequence
serverTemplate.TemplateID = templateID
Dim serverTemplates(0) As DocuSign.ServerTemplate
serverTemplates(0) = serverTemplate
template.ServerTemplates = serverTemplates
'Inline Template
Dim inlineTemplate As DocuSign.InlineTemplate = New DocuSign.InlineTemplate()
inlineTemplate.Sequence = "1"
inlineTemplate.Envelope = New DocuSign.Envelope()
inlineTemplate.Envelope.Recipients = signers
inlineTemplate.Envelope.AccountId = _accountId
Dim inlineTemplates(0) As DocuSign.InlineTemplate
inlineTemplates(0) = inlineTemplate
template.InlineTemplates = inlineTemplates
'Document.
template.Document = New DocuSign.Document()
template.Document.ID = "1"
template.Document.Name = ""
template.Document.PDFBytes = System.IO.File.ReadAllBytes(path:=docPath)
template.Document.FileExtension = "pdf"
Return template
End Function
It looks like there were issues with the DocuSign Demo environment (server) recently, according to the DocuSign Trust Center. This is most likely what was causing your issues.
These issues are currently resolved and your envelopes should be working again now. For reference, this is the DocuSign Trust Center with monitoring on the DEMO environment:
https://trust.docusign.com/system-status/demo

GetListitems not returning expected result

I have created a windows application using list.asmx (getlistitems method) to download documents from a document library which is on another server. I am able to access document names, url, etc. When I use following code to download a file, it is returning html of the login page as content of each file that I am trying to download.
Any thoughts?
Dim spAuthentication As New Authentication()
spAuthentication.Url = authenticationWSAddress
spAuthentication.CookieContainer = New CookieContainer()
Dim spLists As New Lists()
spLists.Url = listWSAddress
'Try to login to SharePoint site with Form based authentication
Dim loginResult As LoginResult = spAuthentication.Login(userName, password)
Dim cookie As New Cookie()
'If login is successfull
If loginResult.ErrorCode = LoginErrorCode.NoError Then
'Get the cookie collection from the authenticatin web service
Dim cookies As CookieCollection = spAuthentication.CookieContainer.GetCookies(New Uri(spAuthentication.Url))
'Get the specific cookie which contains the security token
cookie = cookies(loginResult.CookieName)
'Initialize the cookie container of the list web service
spLists.CookieContainer = New CookieContainer()
'set the cookie of list web service to the authenticatio cookie
spLists.CookieContainer.Add(cookie)
'Dim responseNode As XmlNode = spLists.GetListCollection()
'response = responseNode.InnerXml
Dim query As String = "<mylistitems><Query><Where><Eq><FieldRef Name='FileDirRef' /><Value Type='Url'>DocLib/Property Documents/BELASERA AT FULTON (lax10027)/Master Meter Invoices</Value></Eq></Where></Query><QueryOptions><ViewAttributes Scope='RecursiveAll' IncludeRootFolder='False' /><IncludeAttachmentUrls>TRUE</IncludeAttachmentUrls><ViewFields><FieldRef Name='EncodedAbsUrl'/></ViewFields></QueryOptions></mylistitems>"
Dim doc As New XmlDocument()
doc.LoadXml(query)
Dim dt As DataTable = Nothing
Dim queryNode As XmlNode = doc.SelectSingleNode("//Query")
Dim viewNode As XmlNode = doc.SelectSingleNode("//ViewFields")
Dim optionNode As XmlNode = doc.SelectSingleNode("//QueryOptions")
Dim retNode As XmlNode = spLists.GetListItems("DocLib", String.Empty, queryNode, viewNode, String.Empty, optionNode, Nothing)
Dim ds As New DataSet()
Using sr As New StringReader(retNode.OuterXml)
ds.ReadXml(sr)
End Using
If ds.Tables("Row") IsNot Nothing AndAlso ds.Tables("Row").Rows.Count > 0 Then
dt = ds.Tables("Row").Copy()
For Each myrow As DataRow In dt.Rows
' myrow.Item(0) contains url of the document
If myrow.Item(0) IsNot Nothing AndAlso myrow.Item(0) <> "" Then
DownLoadAttachmentold(myrow.Item("ows_EncodedAbsUrl"), RemoveLookupID(myrow.Item("ows_FileLeafRef")))
End If
Next
End If
Public Shared Sub DownLoadAttachment(ByVal strURL As String, ByVal strFileName As String)
Dim myWebClient As New WebClient()
Dim DestinationFolder As String = "C:\\DownLoads\\"
Form2.RTBStatus.AppendText("Downloading File " + strFileName + " from " + strURL + " .......")
' The DownloadFile() method downloads the Web resource and saves it into the current file-system folder.
myWebClient.DownloadFile(strURL, DestinationFolder + strFileName)
'Form2.RTBStatus.AppendText("Successfully Downloaded file ""{0}"" from ""{1}""", "C:\\DownLoads\\" + strFileName, strURL)
Form2.RTBStatus.AppendText((ControlChars.Cr + "Downloaded file saved in the following file system folder:" + ControlChars.Cr + ControlChars.Tab + DestinationFolder))
End Sub
DownloadAttachment also needs to make (forms-based) authenticated HTTP requests.
An example in C# below:
request = (HttpWebRequest)WebRequest.Create(strURL);
request.Credentials = System.Net.CredentialCache.DefaultCredentials;//adapt for your FBA
request.AllowWriteStreamBuffering = false;
response = (HttpWebResponse)request.GetResponse();
Stream s = response.GetResponseStream();
FileStream fs = new FileStream(#"C:\DownLoads\"+strFileName, FileMode.Create);

Resources