简体   繁体   中英

Copying Data from Microsoft CRM SDK collection to a CSV file or Excel File. (data-dump)

Here is the information about the development environment pertaining to my work computer:

-Microsoft Visual Studio Enterprise 2015 Version 14.0.35123.00 Update 2

-Microsoft Dynamics CRM installed on a remote server.

Our ASP.NET C# application communicates to the Microsoft Dynamics CRM server using the Microsoft CRM SDK.

I'm trying to do analysis of data by grabbing a large collection of information that our ASP.NET C# application retrieves from the Microsoft Dynamics CRM server.

In the following snapshot picture, the C# code retrieves data from Microsoft Dynamics CRM using a result object of type Microsoft.Xrm.Sdk.EntityCollection:

在此处输入图片说明

Could someone please tell me how I could quickly just programmatically copy the data in the said collection to a csv file or an Excel file?

Writing it to file is the easiest part, use StringBuilder iterate through all the attributes to build a string and use File.WriteAllText and write all the data to the file. But the big question is in what format? If you cannot read back what you have written there is no point in writing all the data to a file. Converting SDK objects to JSON string is a bit tricky.

I'd suggest to flatten the objects out (DTO) serialize it to JSON and write it to the file, so you can read it out and re-convert it to an SDK type easily.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM