本文介绍了sharepoint 2013通过控制台应用程序c#将具有列名的共享点列表项导出为CSV的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何通过控制台应用程序将具有列名称的sharepoint 2013导出共享点列表项到CSV?


MCTS Sharepoint 2010,MCAD dotnet,MCPDEA,SharePoint Lead

How to do sharepoint 2013 export sharepoint list items with column names to CSV via console app?


MCTS Sharepoint 2010, MCAD dotnet, MCPDEA, SharePoint Lead

推荐答案

您可以使用客户端对象模型来实现此目的.

You can use Client Object Model to achieve this.

一个演示供您参考:

class Program
    {
        static void Main(string[] args)
        {
            try
            {


                var configSites = (NameValueCollection)ConfigurationManager.GetSection("Sites");
                foreach (var key in configSites.Keys)
                {
                    Uri siteUri = new Uri(configSites.GetValues(key as string)[0]);
                    var siteUrls = configSites.GetValues(key as string);
                    var context = new ClientContext(siteUri.ToString());
                    if (siteUrls != null)
                    {
                        string realm = TokenHelper.GetRealmFromTargetUrl(siteUri);

                        string accessToken = TokenHelper.GetAppOnlyAccessToken(TokenHelper.SharePointPrincipal, siteUri.Authority, realm).AccessToken;





                        using (var clientContext = TokenHelper.GetClientContextWithAccessToken(siteUri.ToString(), accessToken))
                        {

                            const string filePath = @"Your .CSV Path";
                            StreamReader streamReader = new StreamReader(filePath);
                            while (!streamReader.EndOfStream)
                            {

                                string[] totalData = new string[System.IO.File.ReadAllLines(filePath).Length];
                                string strName = string.Empty;
                                string strPartNumber = string.Empty;
                                string strSurName = string.Empty;
                                DateTime dtToday = DateTime.Now;


                                if (streamReader != null)
                                {
                                    Console.Write("while reading");

                                    totalData = streamReader.ReadLine().Split('|');

                                    if (totalData.Length > 1)
                                    {
                                        strName = totalData[1];
                                    }
                                    if (totalData.Length > 2)
                                    {
                                        strSurName = totalData[2];
                                    }

                                    if (totalData.Length > 5)
                                    {
                                        strPartNumber = totalData[5];
                                    }
                                    List spList = clientContext.Web.Lists.GetByTitle("Your Custom List Name");

                                    ListItemCreationInformation creationInfo = new ListItemCreationInformation();
                                    ListItem oListItem = spList.AddItem(creationInfo);
                                    oListItem["Name"] = strName;
                                    oListItem["Title"] = strSurName;
                                    oListItem["Surname"] = strSurName;
                                    oListItem["BirthDate"] = dtToday;
                                    oListItem.Update();
                                    clientContext.ExecuteQuery();
                                }

                            }
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                Console.Write(ex.Message);
            }


        }
    }

更多信息:

https://sharepoint.stackexchange.com/questions/183105/importing-data-from-csv-to-sharepoint-online-list-using-console-application-usi

http://www.c-sharpcorner.com/uploadfile/bhushangawale/以编程方式导出sharepoint-list-list/

谢谢

温迪


这篇关于sharepoint 2013通过控制台应用程序c#将具有列名的共享点列表项导出为CSV的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

11-03 00:46