CAML query not retrieving all fields using vb.net VS2019 and Sharepoint online - vb.net

I was asked to write an app at work that grabs an Employee list from our Sharepoint online site for eventual auto updating. The part I am stuck on is retrieving all of the fields of my employee list.
I would think that my query would simply bring back all of the fields that I see on my sharepoint list. But I admit that at this point that I do not have the best understanding of CAML.
So, I start to loop through each item in my Allitems object to create a datarow for each row of info so I can have a nice little data-table to display to the user. When the line of code runs to find item.("First Name") , I get the message that it is not in the list and that I may need to explicitly query it. Same with all of the other fields with a space. My AllItems object is bringing back all columns with the names that do not have a space (ie. Department, Title, Location, Email) which is strange to me.
Apparently, I do not understand Sharepoint enough and what the fields are called with a space.
I also see some C# examples with another method for the query object : query.ViewFields . I do not have this option for my query object. Also, can someone recommend another Sharepoint imports that would be beneficial here besides the ones that I am using?
Any help and advice would be greatly appreciated. Even an entirely different way of getting this data would be appreciated.
Also, I left only 4 of the datarow fields in the below code since it is failing on "First Name" to keep the code uncluttered. Since that would be the same reason for all of the other fields that are not comming back in my query.
Chris
Imports Microsoft.SharePoint
Imports Microsoft.SharePoint.Client
Try
Dim cred = New SharePointOnlineCredentials(txtUserName.Text, secureString)
Dim ctx = New Microsoft.SharePoint.Client.ClientContext(siteUrl)
ctx.Credentials = cred
Dim web As Web = ctx.Web
Dim list As List = web.Lists.GetByTitle(siteList)
ctx.Load(list)
ctx.ExecuteQuery()
Dim query As CamlQuery = CamlQuery.CreateAllItemsQuery()
query.ViewXml = "<View Scope='RecursiveAll'><Query><ViewFields><FieldRef Name='First Name'/><FieldRef Name='Last Name'/><FieldRef Name='Office Phone'/><FieldRef Name='Email'/><FieldRef Name='Cell Phone'/><FieldRef Name='Department'/><FieldRef Name='Location'/></ViewFields></Query></View>"
Dim AllItems As ListItemCollection = list.GetItems(query)
ctx.Load(AllItems)
ctx.ExecuteQuery()
If AllItems.Count > 0 Then
Dim dt As New DataTable
Dim dRow As DataRow
Dim dcID As New DataColumn("Id")
dcID.DataType = Type.GetType("System.String")
Dim dcFName As New DataColumn("First Name")
dcFName.DataType = Type.GetType("System.String")
Dim dcLName As New DataColumn("Last Name")
dcLName.DataType = Type.GetType("System.String")
Dim dcTitle As New DataColumn("Title")
dcTitle.DataType = Type.GetType("System.String")
dt.Columns.Add(dcID)
dt.Columns.Add(dcFName)
dt.Columns.Add(dcLName)
dt.Columns.Add(dcTitle)
For Each item As ListItem In AllItems
dRow = dt.NewRow()
dRow("Id") = item.Id
dRow("First Name") = item("First Name")
dRow("Last Name") = item("Last Name")
dRow("Title") = item("Title")
dt.Rows.Add(dRow)
Next
DGVList.DataSource = dt
End If
Catch ex As Exception
Console.WriteLine(ex.Message)
End Try

Ok, it seems that the CAML was correct. I just did not know the internal names on the Sharepoint site. Once I obtained a list of the internal field names (not the display ones like I naively thought), I no longer ran into any errors. The answer was not so hard once I realized that I was querying fields that did not exist. It makes perfect sense that Visual Studio would yell at me for it.

Related

How can i set the value from the last row in an specific column in a variable in VB.Net

I'm develop an application using forms in vb.net with visual studio 2019
I have code in the event click for one button
Dim oda As New OleDbDataAdapter
Dim ods As New DataSet
Dim consulta As String
Dim cadena As New OleDbConnection
Dim comando As New OleDbCommand
Try
cadena.Open()
comando = New OleDbCommand("Insert into QRQC (Nombre,NumControl,Fecha,Hora,Turno)" &
"values(txt_nombre,txt_numControl,lbl_fecha,lbl_hora,cBox_turno)", cadena)
consulta = "Select *From QRQC"
oda = New OleDbDataAdapter(consulta, cadena)
ods.Tables.Add("QRQC")
oda.Fill(ods.Tables("QRQC"))
Dim row As Integer
row = ods.Tables("QRQC").Rows.Count - 1
courrentId = ods.Tables("QRQC")(row)("ID_QRQC").ToString()
frm_newPt2.lbl_folioQRQC.Text = courrentId
cadena.Close()
Catch ex As Exception
MsgBox("Error al generar el registro en la base de datos", vbCritical, "Aviso")
Console.WriteLine(ex)
cadena.Close()
GoTo skip
End Try
Everything goes perfectly, but when I delete some record on my DB this part of the code always return the value 102
courrentId = ods.Tables("QRQC")(row)("ID_QRQC").ToString()
How can i solve this problem?
First of all, your insert command is wrong, and will not work.
You have "values(txt_nombre. etc etc."
But that is just a string and NOT the actual values from the form. So you are actually going to "instert txt_nombre" into that table and NOT the value of that label or text box on the form!!!
So you need to fix and get your insert command working FIRST.
And if this is just editing data then consider using the data binder, since navigation, editing, deleting and saving of data to/from the table can occur 100% automatic whiteout ANY code on your part.
so first up is to fix that insert command. You can't JUST use a string with the names of the controls else that would actually as noted try to insert the names of the controls as text and NOT the values of the controls.
And lets clean up a few other things. No need for a dataset, since a dataset is a SET of tables - we only dealing with one table (so use a data table).
But as noted, before we mess with data tables, we have to fix that insert command.
It will, can look like this:
Dim strSQL As String
strSQL = "Insert into QRQC (Nombre,NumControl,Fecha,Hora,Turno) " &
"VALUES(#nombre,#numControl,#fecha,#hora,#turno)"
Using cmdSQL As New OleDbCommand(strSQL,
New OleDbConnection(My.Settings.TestDB))
cmdSQL.Parameters.Add("#nombre", OleDbType.Integer).Value = txt_nombre.Text
cmdSQL.Parameters.Add("#numControl", OleDbType.Integer).Value = txt_numControl.Text
cmdSQL.Parameters.Add("#fecha", OleDbType.Integer).Value = lbl_fecha.Text
cmdSQL.Parameters.Add("#hora", OleDbType.Integer).Value = lbl_hora.Text
cmdSQL.Parameters.Add("#turno", OleDbType.Integer).Value = txt_nombre.Text
cmdSQL.Connection.Open()
cmdSQL.ExecuteNonQuery()
End Using
So you have to "replace" the string values in the sql with the ACTUAL values you are using.
You also don't show where/how you setup your connection to the database. I guessed that you used the applications settings and the connection builder - so you have to change TestDB to your actual connection that you used.
The above will thus get your insert command working.
At that point, you can post a new question in that after you do a insert, how to get the new autonumber primary key, or whatever else you wanted to do, but your insert statement as written will not work.
As noted, perhaps it better to use data bound controls. This will result in a Access like design experience, and you not having to write ANY code to edit a table in vb.net.
And it not clear if the control names I used are correct (or they are even controls on the form), but if they are, then ".Text" is required to grab the values. You have to of course change (check) that the control names I used and guessed are correct.
You also have to change the data type "integer" I used in above to the correct data types. For text I recommend you use .VarWChar

VS reportviewer how do i create a rdlc file

I am new to reportviewer and struggling with the concepts.
I realise that I am probably being very stupid here. I have tried reading up on the reportviewer but not found any tutorials except those that drag and drop datasets. which is not what I want to do.
I want to create a report from a single datatable at first just as a learning exercise.
I have created a dataset added the table to it and have tried this code but I get an error: 'The report definition for report "C:\Users\Mike\BM\Reports\" has not been specified. Object reference not set to an instance of an object'
I don't really understand what the 'The report definition' bit means?
I would appreciate some guidance please.
Dim MyTestDS As New DataSet
Dim myTestTable As New DataTable
myTestTable = Data.Accounts.Table.Copy
MyTestDS.Tables.Add(myTestTable)
Dim DSReport As New ReportDataSource()
DSReport.Name = "MyTestDS"
DSReport.Value = MyTestDS.Tables(0)
Dim PathReport As String = "C:\Users\Mike\BM\Reports\"
ReportViewer1.LocalReport.ReportEmbeddedResource = PathReport
ReportViewer1.LocalReport.DataSources.Clear()
ReportViewer1.LocalReport.DataSources.Add(DSReport)
ReportViewer1.LocalReport.Refresh()
ReportViewer1.RefreshReport()
As a learning exercise, I think is better not using embedded resource so you can simply specify the complete report path of your rdlc file; for example:
ReportViewer1.LocalReport.ReportPath = "C:\Users\Mike\BM\Reports\YourReportFile.rdlc"
If you want to use an embedded report, I think you have to get it like this:
Get Embedded Resource
Copy YourReportFile.rdl to YourReportFile.rdlc

Retrieve Lotus Notes Domino directoy groups and users

Using Studio 2013 VB.
I am attempting to retrieve group members from our Lotus Notes Domino directory - but I cannot get past this error: "A protocol error occurred. Failed, invalid authentication method specified." I was assuming (maybe incorrectly) that this could be done using DirectorySearcher as we do for our Active Directory.
I have tried retrieving various data with the same results. My research seems to indicate a problem with the ldapsettings but I am using the same alias and specific ldapsettings used by other in-house scripts (albeit written in perl). So the ldapsettings still might be the problem.
The line of code that fails is:
Dim result As SearchResult = searcher.FindOne
The value of searcher.Filter is (&(objectclass=dominoGroup)(cn=mydominogroup))
So this looks like it is build right.
Any help with errors in my code - or even suggestions to accomplish this task a better way are appreciated.
Here is my code:
dim grp as String = "mydominogroup"
Using dEntry As New DirectoryEntry("LDAP://mycompanyldapsettings")
dEntry.Username = myadminaccount
dEntry.Password = myadminpassword
Using searcher As New DirectorySearcher(dEntry)
searcher.Filter = String.Format("(&(objectclass=dominoGroup)(cn={0}))", grp)
Dim result As SearchResult = searcher.FindOne <--fails here
If result Is Nothing Then
"report group not found"
Else
Dim members As Object = result.GetDirectoryEntry.Invoke("Members", Nothing)
If members Is Nothing Then
"report no members found in group"
Else
For Each member As Object In CType(members, IEnumerable)
Dim currentMember As New DirectoryEntry(member)
If currentMember.SchemaClassName.ToLower = "user" Then
Dim props As PropertyCollection = currentMember.Properties
"get and list the user pros("someattribute").Value)"
End If
Next
End If
End If
End Using
End Using
Decided to call an external Process to solve this.

is there a way to query IEmployeePayrollInfo with QuickBooks SDK?

I am starting to work with the QuickBooks SDK, and so far I am able to query Employees no problem, like so:
_sessionManager.OpenConnection("", "<software>")
_sessionManager.BeginSession("", ENOpenMode.omDontCare)
Dim requestSet As IMsgSetRequest = GetLatestMsgSetRequest(_sessionManager)
' Initialize the message set request object
requestSet.Attributes.OnError = ENRqOnError.roeStop
Dim empQuery As IEmployeeQuery = requestSet.AppendEmployeeQueryRq()
' Do the request and get the response message set object
Dim responseSet As IMsgSetResponse = _sessionManager.DoRequests(requestSet)
Dim response As IResponse = responseSet.ResponseList.GetAt(0)
Dim empRetList As IEmployeeRetList = response.Detail
....
_sessionManager.EndSession()
_sessionManager.CloseConnection()
Which will give me a list of employees which I can iterate through. This works well for the basic employee data, such as name, date of birth, etc. but there is a EmployeePayrollInfo property that does not seem to be returned with the IEmployeeQuery.
I see that there is an interface IEmployeePayrollInfo but I have not as yet been able to figure out if there is a way to query it. I see that there are report related payroll info queries, but I am trying to query the EmployeePayrollInfo directly, to retrieve the vacation information. Is this something that can be done with QBFC?
EDIT
I was able to get this working, see accepted answer below.
Open Quickbooks.
Go to the Edit menu and click Preferences.
In the Preferences window, click Integrated Applications in the list on the left.
Click the Company Preferences tab.
Select the application with which you are connecting to QuickBooks.
Click Properties.
Check "Allow this application to access Social Security Numbers, customer credit card information, and other personal data"
The employee data should now include EmployeePayrollInfo. Please comment if this does not work.
For anyone searching for the same functionality, the only information I was able to find seems to indicate that Intuit has specifically excluded this functionality from the QuickBooks SDK for security reasons. What we ended up doing to solve our problem is create a custom report in QuickBooks that included all of the information that we needed, exported it as a CSV file, and then import it accordingly in our software. Same end result, but a couple more steps than we were originally hoping for. Hopefully Intuit will change their mind about excluding this from the SDK.
UPDATE
I have finally been able to query the EmployeePayrollInfo, what was needed was adding "EmployeePayrollInfo" to the query itself like so:
empQuery.IncludeRetElementList.Add("EmployeePayrollInfo")
So now the code looks like this:
Dim sessionManager As New QBSessionManager
sessionManager.OpenConnection2("", "<software>", ENConnectionType.ctLocalQBD)
sessionManager.BeginSession("", ENOpenMode.omDontCare)
Dim requestSet As IMsgSetRequest = sessionManager.CreateMsgSetRequest("US", 12, 0)
requestSet.Attributes.OnError = ENRqOnError.roeStop
Dim empQuery As IEmployeeQuery = requestSet.AppendEmployeeQueryRq()
empQuery.IncludeRetElementList.Add("EmployeePayrollInfo") ' this line did the trick!
Dim responseSet As IMsgSetResponse = sessionManager.DoRequests(requestSet)
Dim response As IResponse = responseSet.ResponseList.GetAt(0)
Dim empRetList As IEmployeeRetList = response.Detail
If empRetList.Count > 0 Then
For i As Integer = 0 To empRetList.Count - 1
Dim emp As IEmployeeRet = empRetList.GetAt(i)
If emp IsNot Nothing Then
' do something with the queried data
End If
Next
End If
sessionManager.EndSession()
sessionManager.CloseConnection()

Sharepoint 2010 VB.net adding to list

Hey all i am looking to add some data to a list in my sharepoint site.
The following code is what i am trying to use:
Dim siteUrl As String = "http://thespsite/sandbox/"
Dim clientContext As New ClientContext(siteUrl)
Dim oList As List = clientContext.Web.Lists.GetByTitle("demoT")
Dim listCreationInformation As New ListItemCreationInformation()
Dim oListItem As ListItem = oList.AddItem(listCreationInformation)
oListItem("Title") = "testing this out"
oListItem("Priority") = "(2) Normal"
oListItem("AssignedTo") = "Lastname, Firstname"
oListItem.Update()
clientContext.ExecuteQuery()
My list is called demoT and the fields Title, Priority and Assigned To are all fields i wish to add to the list. Of course the Lastname, Firstname is filled out with a actual name from the SPDB.
However, this is the error i get:
An exception of type 'Microsoft.SharePoint.Client.ServerException'
occurred in Microsoft.SharePoint.Client.Runtime.dll but was not
handled in user code
Additional information: Invalid data has been used to update the
list item. The field you are trying to update may be read only.
I do know that Comments exist since i see it on my list... just don't know why it wont allow me to add? If i comment that part of the code out and run it, it posts to the list just fine.
The Sharepoint Designer HTML code for the Assigned To part is:
<SharePoint:FormField runat="server" id="ff2{$Pos}" ControlMode="New"
FieldName="AssignedTo" __designer:bind="{ddwrt:DataBind('i',concat('ff2',$Pos),
'Value','ValueChanged','ID', ddwrt:EscapeDelims(string(#ID)),'#AssignedTo')}"/>
<SharePoint:FieldDescription runat="server" id="ff2description{$Pos}"
FieldName="AssignedTo" ControlMode="New"/>
What could i be missing to prevent it from adding that field?
My first guess is that the format for your "Assigned To" field is wrong. See here to get started:
https://sharepoint.stackexchange.com/questions/21168/setting-user-column-value-via-client-object-model