none
Read value of Taxonomy Field of item in a Sandbox Solution

    질문

  • I have uploaded a sandbox solution in the SharePoint Online Site Collection. Basically the sandbox needs to fetch the properties of item of List or Library of a site. The code works perfectly for all properties except for the Managed Metadata field.

    The code block is:

     spWeb = SPContext.Current.Web.Site.OpenWeb(webGuid);               
            var spList = spWeb.Lists[listID];
            var spItem = spList.GetItemById(itemID);
    
            foreach (SPField field in spItem.Fields)
            {
                var value = spItem[field.InternalName];
                if (value != null)
                    props.Add(field, value);
             }

    The line spItem[field.InternalName] throws exception when the field is Managed Metadata. Any idea to get the value of managed metadata field of item in a Sandbox solution would be greatly appreciated.

    Thanks

    Prakash


    tandukar


    • 편집됨 pkt30 2012년 3월 23일 금요일 오후 2:37
    2012년 3월 23일 금요일 오후 2:34

답변

모든 응답

  • what is the exception your receive?

    Blog | SharePoint Field Notes Dev Tool | ClassMaster

    2012년 3월 23일 금요일 오후 5:21
  • The exception is : System.RunTime.Serialization.SerializationException

    Message : Type 'Microsoft.SharePoint.Taxonomy.TaxonomyFieldValue' in Assembly 'Microsoft.SharePoint.Taxonomy, Version=14.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c' is not marked as serializable.

    Server stack trace:
       at System.Runtime.Serialization.FormatterServices.InternalGetSerializableMembers(RuntimeType type)
       at System.Runtime.Serialization.FormatterServices.GetSerializableMembers(Type type, StreamingContext context)
       at System.Runtime.Serialization.Formatters.Binary.WriteObjectInfo.InitMemberInfo()
       at System.Runtime.Serialization.Formatters.Binary.WriteObjectInfo.InitSerialize(Object obj, ISurrogateSelector surrogateSelector, StreamingContext context, SerObjectInfoInit serObjectInfoInit, IFormatterConverter converter, ObjectWriter objectWriter)
       at System.Runtime.Serialization.Formatters.Binary.ObjectWriter.Serialize(Object graph, Header[] inHeaders, __BinaryWriter serWriter, Boolean fCheck)
       at System.Runtime.Serialization.Formatters.Binary.BinaryFormatter.Serialize(Stream serializationStream, Object graph, Header[] headers, Boolean fCheck)
       at System.Runtime.Remoting.Channels.BinaryServerFormatterSink.SerializeResponse(IServerResponseChannelSinkStack sinkStack, IMessage msg, ITransportHeaders& headers, Stream& stream)
       at System.Runtime.Remoting.Channels.BinaryServerFormatterSink.ProcessMessage(IServerChannelSinkStack sinkStack, IMessage requestMsg, ITransportHeaders requestHeaders, Stream requestStream, IMessage& responseMsg, ITransportHeaders& responseHeaders, Stream& responseStream)

    While debugging the above code, in the foreach block, the field type of the Managed Metadata field is Invalid, while for other normal types, it is of correct type.

    Is this the limitation of the Sandbox solution?


    tandukar

    2012년 3월 25일 일요일 오전 4:18
  • According to the link below managed metadata / term stores are only available to internal sites and not for public web sites in Office 365. It is possible you are hitting the built in enterprise keywords field. This may be available in the sandbox OM but will produce an error. Just a guess.

    http://community.office365.com/en-us/f/152/t/44830.aspx


    Blog | SharePoint Field Notes Dev Tool | ClassMaster

    2012년 3월 26일 월요일 오후 2:51
  • Microsoft.SharePoint.Taxonomy.dll is not allowed in sandbox solution and that's why you're getting an exception. You can get string value of managed metadata field by calling GetFormattedValue:

    string value = spItem.GetFormattedValue(field.InternalName);
    • 답변으로 제안됨 msznwska 2012년 4월 27일 금요일 오전 8:54
    2012년 4월 11일 수요일 오전 11:06
  • I believe when you pull value the way it's suggested you end up with term title

    In case you need term id,

    you can use this one:

    var relatedNoteFldStaticName = {You metadata column static name}+"0";

    2012년 9월 11일 화요일 오후 10:12