7.11.13

Update taxonomy field Process Batch Data TaxonomyFieldValueCollection

public static string XmlToUpdate(List<XmlDataDoc> lstKeyValues, string InternalColmnName, string listGuid, bool isDocLibrary)
        {
            StringBuilder methodBuilder = new StringBuilder();
            string batchFormat =
                "<?xml version=\"1.0\" encoding=\"UTF-8\"?>" +
                "<ows:Batch OnError=\"Continue\">{0}</ows:Batch>";
            string methodFormat = "<Method ID=\"{0}\">" +
                "<SetList>{1}</SetList>" +
                "<SetVar Name=\"Cmd\">Save</SetVar>" +
                "<SetVar Name=\"ID\">{2}</SetVar>" +
                "<SetVar Name=\"urn:schemas-microsoft-com:office:office#{3}\">{4}</SetVar>" +

//Requiredf only for Document Library             
 ((isDocLibrary) ? "<SetVar Name=\"owsfileref\">{5}</SetVar>" : "") +
           
   "</Method>";
           
              foreach (XmlDataDoc KeyValue in lstKeyValues)
            {
                methodBuilder.AppendFormat(methodFormat, KeyValue.ID, listGuid, KeyValue.ID, InternalColmnName, KeyValue.Value, KeyValue.RelativeUrl);
            }
            return string.Format(batchFormat, methodBuilder.ToString());
        }

        public static string XmlToNew(List<Dictionary<string, string>> lstColNameEtValue, string listGuid)
        {
            string batchFormat =
                "<?xml version=\"1.0\" encoding=\"UTF-8\"?>" +
                "<ows:Batch OnError=\"Continue\">{0}</ows:Batch>";
            StringBuilder methodFormat = new StringBuilder();
            foreach (Dictionary<string, string> items in lstColNameEtValue)
            {
                methodFormat.Append("<Method ID=\"LaunchMeta\">" +
                    "<SetList>" + listGuid + "</SetList>" +
                    "<SetVar Name=\"Cmd\">Save</SetVar>" +
                    "<SetVar Name=\"ID\">New</SetVar>");
                foreach (KeyValuePair<string, string> ColNameEtValue in items)
                {
                    methodFormat.Append("<SetVar Name=\"urn:schemas-microsoft-com:office:office#" + ColNameEtValue.Key + "\">" + ColNameEtValue.Value + "</SetVar>");
                }
                methodFormat.Append("</Method>");
            }
            return string.Format(batchFormat, methodFormat.ToString());
        }
       
public static string TaxoCollToXmlInput(TaxonomyFieldValueCollection TaxoColl)
        {
            string metaList = string.Empty;
            foreach (TaxonomyFieldValue itm in TaxoColl)
            {
                metaList += itm.WssId + ";#" + itm.Label + "|" + itm.TermGuid + ";";
            }
            return metaList;
        }
    }

    public class XmlDataDoc
    {
        public int ID { get; set; }
        //item.file.RelativeUrl not item.url
        public string RelativeUrl { get; set; }
        public string Value { get; set; }
    }
}

No comments:

Post a Comment