c# getting informaion from xml file - c#

A want get all information which are in located in <forecast_conditions></forecast_conditions> tag for first ta I use
var for_cod = from currentCond in xdoc.Root.Descendants("current_conditions")
select currentCond;
I don;t know how to get information from 2,3 <forecast_conditions></forecast_conditions> tags because it have same names, maybe you have any ideas?
xml file: http://www.google.com/ig/api?weather=vilnius&hleng=eng

I am not sure what you exactly need. If you want to get all forecast_conditions for in a result set you can use this simple query
var query = from t in doc.Descendants("forecast_conditions")
select t;
You may wanna see Weather Information from Google Weather using ASP.NET and LINQ to XML, also check out this article Using Google Weather API In A C# Application. Its not using LINQ though. Also check out this thread C# Pull XML data from google's weather API

Related

Sharepoint Lookup values

I have one sharepoint list which is using Lookup Field, whose source is pointing to other list in the same site (Master data). While using OData query i don't see that column in my result.
If I use OData url with "FieldValuesAsText" I can see data. Also, I have tried using ContentType Expand and filter but i have no luck in finding.
Since, my list is very big and want to retrieve data in minimum number of calls. looking for some kind of approach or URL which will help me achieve the same
Try to expand look up field to get real value like this:
/_api/web/lists(guid'')/items?$select=Title,LookupFieldName1/FieldToBeExpanded1,LookupField2/FieldToBeExpanded2&$expand=LookupFieldName1,LookupFieldName2
In this endpoint, FieldToBeExpand1 should be the same as the column where lookup get from:

SalesForce - Get all the fields of an object using .Net SDK or Api

We have our system from where we want to push the records (e.g. Contact, Account, Opportunity, etc.) to SalesForce.
To achieve this, we have used ForceToolKit for .Net. We are able to insert\update the records successfully using the ForceToolKit functions.
Example:
dynamic contact = new ExpandoObject();
contact.FirstName = "FirstName";
contact.LastName = "Last";
contact.Email = "test#test.com";
contact.MobilePhone = "1234567890";
var successResponse = await forceClient.CreateAsync("Contact", contactList);
The Issue we are facing is as mentioned below.
In our source system, we have few custom fields which are not standard field in SalesForce and it can be different for different users.
So, first we have to map the custom fields between our source system and the SalesForce.
We want to fetch all the fields of SalesForce object in order to map the fields.
We are unable to find any function in ForceToolkitForNet.
As described here, we have tried QueryById function by using the dynamic return type, but it is throwing an exception.
var contactFields = await forceClient.QueryByIdAsync<dynamic>("Contact", successResponse.Id);
Exception: "SELECT FROM Contact where Id = '{contactId}' Incorrect syntax near FROM".
What are the ways to get the fields of any object of SalesForce.
Can anyone help us on getting the fields of an object using SalesForceToolkit or SalesForceApi?
SOQL doesn't have a SELECT * FROM Account concept, you need to learn the fields beforehand. You have few options here.
You can use "describe" calls. I've recently answered similar question but it was about REST API: https://stackoverflow.com/a/48436870/313628, I think your solution is SOAP-based.
If you'd be doing this by hand...
Start here: https://developer.salesforce.com/docs/atlas.en-us.api.meta/api/sforce_api_calls_list_describe.htm
List of all objects visible to your user: describeGlobal()
Get details (incl field names) for one object: describeSobject() or more: describeSobjects()
As you're using the toolkit - there's a chance these methods already are in there somewhere. Experiment a bit. Between the C# examples under the links I gave you and the library you should be able to figure something out.
I mean I'm naive but just searching the repo for "describe" looks promising: https://github.com/developerforce/Force.com-Toolkit-for-NET/search?utf8=%E2%9C%93&q=describe&type=, maybe this example
There's also a way to not learn this info at runtime but consume a WSDL file generated out of Salesforce with all fields & generate C# code out of it. The downside is that you'd need to regenerate it every time you want to support new object/field in your app. Read about "Enterprise WSDL" to get started.
Last but not least - there are more or less friendly tools that dump the Salesforce metadata. i'm a fan of https://www.datasert.com/products/realforce/ but just have a look around. Hell, even exporting some records with DataLoader will give you all field names if that's all you need.

Query XML to filter down to

I'm trying to create a list that is the results of an inner join between two xml lists and then filter on an external list of keys that are in a DataTable. A code example is not necessary as long as I can be pointed to something explaining how to do it.
Whut I'm working with is the returned data from Microsoft Cognitive Services Text Analytics Topic Detection. There are two sections in the XML. The first is the list of items I need to get. The other has a list of keys I have references for.
An example of the returned XML is on their Quick Start page. Do a find on page for: >>> "status": "Succeeded" <<< to get to it.
You'll see in the bottom part, the "topicAssignments" section, of the example XML the value "documentId": "1", That's the key I have in the DataTable. The Document also has one-to-many "topicId" associated to it. That's where the relationship is set between the "topics" section and the "topicAssignments" section
Thanks in advance.
As often as not, writing up the question clarified my ideas enough to Google it successfully.
https://www.google.com/search?q=linq+inner+join+on+xml&rlz=1C1CHFX_enUS631US631&oq=linq+inner+join+on+xml
https://blogs.msdn.microsoft.com/wriju/2008/03/24/linq-to-xml-join-xml-data/
http://www.c-sharpcorner.com/blogs/joins-using-linqtoxml1

facebook graph api get posts by ids

I am trying to pull a small group of feed/post objects from Facebook Graph API from an array of post ids.
string[] postids = {1234,1235,1236}
Could someone kindly show me the query string that request the posts?
I've tried using (but I know it's not correct)
https://graph.facebook.com/me/feed?ids=1234,1235,1236
No luck
I figured it out. I was pulling from the feed end point in one query and the ids were different based on the query.
You need to include the api version number in your Get request. For example, your URL should look like this:
https://graph.facebook.com/v2.8/?ids=1234,1235,1236

OpenXML: Read text between two document fields using OpenXML SDK

I'm new to programming with the OpenXML SDK and I've tried excessively to locate and read text that is between two document fields, but never really succeeded. There are tons of samples and tutorials on the web about almost everything you can think of doing with the OpenXML SDK, from setting watermarks to doing merge mail, but not only one about processing document fields.
My word document looks something like this:
{ Field1 } data { Field2 }
and what I want to do, is to read the data that is between Field1 and Field2.
I succeeded to the point to locate all the fields I need like this:
var qryFieldCode = (from p in procDoc.MainDocumentPart.Document.Body.Descendants()
where p.GetType() == typeof(FieldCode)
select p).ToList();
But what can I do to read the text that is between those fields I found?
Any help is greatly appreciated.
Find your first field (much like above) and then get an .ElementsAfterSelf.TakeWhile until where p.GetType() doesn't = typeof(FieldCode). Then just get the .Value of that query and you'll have your text. This won't be a great solution if you have things like tables between your two fields, but for your example above, it will work.

Categories