public string GetFieldCreator(ClientContext ctx, Web web, string fieldName)
        {
            try
            {
                var retVal = new Dictionary <string, string>();
                var js     = new JavaScriptSerializer();
                var field  = GetField(ctx, web, fieldName);
                if (web == null)
                {
                    web = ctx.Site.RootWeb;
                }
                if (field == null)
                {
                    OnVerboseNotify($"No information found for {fieldName}");
                    return(string.Empty);
                }
                var schemaXml = FieldTokenizer.DoTokenSubstitutionsAndCleanSchema(ctx, web, field);
                retVal.Add(field.InternalName, schemaXml);

                return(js.Serialize(retVal));
            }
            catch (Exception ex)
            {
                OnVerboseNotify($"Error getting schema for {fieldName} - {ex}");
                return(string.Empty);
            }
        }
        public void GetFieldCreator(ClientContext ctx, Web web, string fieldName, AppManifestBase manifest)
        {
            try
            {
                var existingFieldCreators = manifest.Fields;

                existingFieldCreators = existingFieldCreators ?? new Dictionary <string, string>();

                var field = GetField(ctx, web, fieldName);
                if (field != null)
                {
                    OnVerboseNotify($"Got field creation information for {fieldName}");
                    var schemaXml = FieldTokenizer.DoTokenSubstitutionsAndCleanSchema(ctx, field);
                    existingFieldCreators[field.InternalName] = schemaXml;
                }
                else
                {
                    OnVerboseNotify($"No information found for {fieldName}");
                }

                manifest.Fields = existingFieldCreators;
            }
            catch (Exception ex)
            {
                OnVerboseNotify($"Error getting schema for {fieldName} - {ex}");
            }
        }
Ejemplo n.º 3
0
 private void CheckIsDisplayNameOverideOrAdditionalField(ListCreator listCreator, Field field,
                                                         ContentTypeCollection ctypes, ClientContext ctx)
 {
     foreach (var ctype in ctypes)
     {
         foreach (var ctypeField in ctype.Parent.Fields)
         {
             if (ctypeField.Id == field.Id)
             {
                 if (field.Title == ctypeField.Title)
                 {
                     return;
                 }
                 if (ctypeField.Title == "Title")
                 {
                     listCreator.TitleFieldDisplayName = field.Title;
                 }
                 //Ignore LinkTitle, etc...
                 if (field.Title != "Title")
                 {
                     listCreator.FieldDisplayNameOverrides.Add(ctypeField.Id.ToString(), field.Title);
                 }
                 return;
             }
         }
     }
     //TODO: More precise match against the Type attribute for WorkflowStatus
     if (field.FromBaseType || field.SchemaXml.Contains("WorkflowStatus"))
     {
         return;
     }
     //The field is not in any of the list content types
     try
     {
         var schemaXml   = FieldTokenizer.DoTokenSubstitutionsAndCleanSchema(ctx, field);
         var displayName = schemaXml.GetXmlAttribute("DisplayName");
         schemaXml = schemaXml.SetXmlAttribute("Name", displayName.Replace(" ", "_x0020_"));
         listCreator.AdditionalFields.Add(field.InternalName, schemaXml);
     }
     catch
     {
         // ignored
     }
 }