加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 百科 > 正文

Identifying multiple/single values of metadata and recording

发布时间:2020-12-15 22:31:58 所属栏目:百科 来源:网络整理
导读:Steps Involved: 1. Open Visual Studio 2013 (Run as administrator). 2. Go to File= New = Project. 3. Select Console Application in the Visual C# node from the installed templates. 4. Enter the Name and click on Ok . 5. In the solution explo

Steps Involved:

1.OpenVisual Studio 2013(Run as administrator).

2.Go to File=> New => Project.

3.SelectConsole Applicationin theVisual C#node from the installed templates.

4.Enter theNameand click onOk.

5.In the solution explorer,right click onReferencesfolder and then click onAdd Reference.

6.Add the following assemblies from 15 hive (C:Program FilesCommon Filesmicrosoft sharedWeb Server Extensions15ISAPI).

a.Microsoft.SharePoint.Client.dll

b.Microsoft.SharePoint.Client.Runtime.dll

c.Microsoft.SharePoint.Client.Taxonomy.dll

7.Open Program.cs file and replace the code with the following

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

using Microsoft.SharePoint.Client;
using Microsoft.SharePoint.Client.Taxonomy;
using System.Xml;
using System.IO;

namespace IdentifyMetadataColumns
{
    class Program
    {
        static void Main(string[] args)
        {
            ClientContext context = new ClientContext("http://sp2dev/en-us");
            ListCollection listsColl = context.Web.Lists;
            context.Load(listsColl);
            context.ExecuteQuery();
            XmlTextWriter writer = new XmlTextWriter("recordValues.xml",null);
            writer.Formatting = Formatting.Indented;
            writer.WriteStartElement("lists");
            foreach(List list in listsColl){
                writer.WriteStartElement("list");
                writer.WriteAttributeString("listName",list.Title);

                Console.WriteLine(list.Title + ":"); 
                FieldCollection collField = list.Fields;
                context.Load(collField,fields => fields.Include(field => field.Title));
                context.ExecuteQuery();
                foreach (Field field in collField)
                {
                    //if (field is TaxonomyField) {
                    //    Console.WriteLine("success---------");
                    //    return;
                    //}
                    TaxonomyField taxFiled = field as TaxonomyField;
                    if (taxFiled != null)
                    {
                        try
                        {                            
                            context.Load(taxFiled);
                            context.ExecuteQuery();                                                   
                            if (taxFiled.AllowMultipleValues)
                            {
                                //Multiple                                    
                                Console.WriteLine("t" + taxFiled.InternalName + "t"+"Multiple");
                                writer.WriteStartElement("MetadataColumn");
                                writer.WriteAttributeString("name",taxFiled.InternalName);
                                writer.WriteElementString("values","Multiple");
                                writer.WriteEndElement();
                            }
                            else
                            {
                                //Single
                                Console.WriteLine("t" + taxFiled.InternalName + "t" + "Single");
                                writer.WriteStartElement("MetadataColumn");
                                writer.WriteAttributeString("name","Single");
                                writer.WriteEndElement();
                            }                                                                                           
                            continue;
                        }//try end
                        catch (ArgumentException exception)
                        {
                            Console.WriteLine("fail");
                            throw new ArgumentOutOfRangeException(Resources.GetString("AllFieldsNotFetched"),exception);
                        }
                    }//if end
                                                      
                }//foreach field end
                writer.WriteEndElement();               
            }//foreach list end            
            writer.WriteEndElement();
            writer.Close(); 
            Console.ReadLine();
        }
    }
}

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读