Copied to clipboard

Flag this post as spam?

This post will be reported to the moderators as potential spam to be looked at


  • Simon steed 376 posts 688 karma points
    Nov 22, 2012 @ 19:17
    Simon steed
    0

    Saving date values via api problems

    Hi

    Wierd one here. I've got a member record with a DOB field set to Date Picker type. Using the following code to add the record to the member (new member created)

     Member newMember = Member.GetMemberFromEmail([email protected]);

    newMember = Member.MakeNew("My Name", MemberType, author);

    umbraco.cms.businesslogic.property.Properties props = newMember.GenericProperties;

    // do all the other property updates here as well.... DateTime dob; if (DateTime.TryParse('13/10/1950', out dob)) // also happens with dates like 05/10/1947 props.First(p => p.PropertyType.Alias == "dOB").Value = XmlConvert.ToString(dob, XmlDateTimeSerializationMode.RoundtripKind);

    newMember.Save(); // <-- exception thrown here as below

     

    Problem is we are getting exceptions when saving the member:

    Error adding member with email address :[email protected], error displayed: System.InvalidCastException: Specified cast is not valid.     at umbraco.editorControls.datepicker.DateData.ToXMl(XmlDocument d)     at umbraco.cms.businesslogic.property.Property.ToXml(XmlDocument xd)     at umbraco.cms.businesslogic.Content.XmlPopulate(XmlDocument xd, XmlNode& x, Boolean Deep)     at umbraco.cms.businesslogic.member.Member.generateXmlWithoutSaving(XmlDocument xd)     at umbraco.cms.businesslogic.member.Member.XmlGenerate(XmlDocument xd)     at umbraco.cms.businesslogic.member.Member.Save()     at SimonAntony.ImportModuleDT.UploadMembers(IList`1 import, Int32 SiteHomepageID, List`1 nodesList, Int32 ClubID) 

    Any ideas what could be wrong here - surely if the DateTime object can parse the input value, the xml converted string should be valid for Umbraco?

  • Richard Terris 273 posts 715 karma points
    Nov 27, 2012 @ 10:14
    Richard Terris
    0

    Short in the dark here Simon, but would .Value.ToString() = XmlConvert.... work?

     

  • Simon steed 376 posts 688 karma points
    Nov 27, 2012 @ 10:35
    Simon steed
    0

    Not sure m8, basically the code has worked fine for a while then suddenly started to throw exceptions and unsure as to why. Now I cannot get it to work at all so we've had to remove it temporarily - wierd one for sure but i'll give it a shot

Please Sign in or register to post replies

Write your reply to:

Draft