Respondida Obtaining column attributes from SharePoint

  • viernes, 13 de abril de 2012 19:56
     
     

    Hello all,

    Is there a way, such as a console app, to obtain the out of the box column attributes for SharePoint?  I'm making custom lists in Visual Studio and I'd like to use the out of the box columns provided by SharePoint.  Such as if I wanted to use "start date" i can write a program that will give me Start Date's attributes like:

    ID="...." Name="...." DisplayName="...." Type="...." etc. 

    I would I go about coding a small program that will provide this info?

    Thanks,

    Shaun

Todas las respuestas

  • viernes, 13 de abril de 2012 20:30
     
     Respondida Tiene código

    You can use the following code to get the schema for a built in sharepoint field, given the name of the field and a URL of a site.

     public static string GetSchemaXmlForBuiltInField(string siteURL, string fieldName)
    {
                string schema = string.Empty;
                Guid fieldID = Guid.Empty;
                var result = from f in typeof(SPBuiltInFieldId).GetFields() where f.Name == fieldName select f;
    
                if (result != null && result.Count() == 1)
                {
                    FieldInfo fi = result.FirstOrDefault();
                    fieldID = (Guid)fi.GetValue(fi);
                }
    
    
                using (SPSite site = new SPSite(siteURL))
                {
    
                    using (SPWeb web = site.OpenWeb())
                    { 
                        
                        SPField builtInField = web.AvailableFields[fieldID];
                        schema = builtInField.SchemaXml;
                        
                    }
                
                }
    
                return schema;
    
            
    }


    Blog | SharePoint Field Notes Dev Tool | ClassMaster

    • Marcado como respuesta Shaun Cline martes, 17 de abril de 2012 18:37
    •  
  • martes, 17 de abril de 2012 18:37
     
     

    Hey thanks Steve, sorry it took so long to get back to you.  We haven't put SharePoint Manager on our server yet so I was tinkering with another way to get the attributes.  Thanks for the help, shaun.