Copied to clipboard

Flag this post as spam?

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


  • John C Scott 473 posts 1183 karma points
    Feb 22, 2011 @ 10:53
    John C Scott
    0

    getting a record in .net

    am able to retrieve a record from a contour form. In XSLT this works fine. I have the GUID of the record as query string parameter.

    The XSLT is very very simple and looks like this:

    <xsl:variable name="recordId" select="umbraco.library:RequestQueryString('id')"/>
    <xsl:template match="/">
    <xsl:value-of select="umbraco.contour:GetRecord($recordId)"/>
    </xsl:template>

    This works perfectly and gives me exactly the data I need. However I need to do exactly the same thing from a .net user control. I can't work this out, and as usual it's probably because I am being stupid, but I'd really appreciate some help in trying to do the same thing as C#.

     

     

         string formId = Request.QueryString["id"].ToString();
         RecordStorage rs = new RecordStorage();
         Record r = rs.GetRecord(formId);
         RecordsViewer viewer = new RecordsViewer();
         XmlNode xml = viewer.GetSingleXmlRecord(r, new System.Xml.XmlDocument());

     

    I've cobbled this code together from various online samples. However the error I get when I try and execute this is:
    Specified cast is not valid.
    This is on the line I've marked in red above.
    Any samples or pointers to do this very simple thing would be much appreciated.
    I just need to get all the field values in a list for the specified record.
    Struggling as all the samples I'm finding seem to be much more complex than this.
    What the XSLT gives me is perfect, but I can't get that into my user control. I've been thinking about it but I can't see any way to do this.

     

  • Ravi Motha 290 posts 500 karma points MVP 8x c-trib
    Feb 22, 2011 @ 12:59
    Ravi Motha
    0

     just want to check that the querystring is full? and presuming you are getting the  record value.

    You could do something like this..which may be closer to what you are comfortable  with

    http://stackoverflow.com/questions/1496850/select-xmlnode-by-id-using-xpath

  • John C Scott 473 posts 1183 karma points
    Feb 22, 2011 @ 13:04
    John C Scott
    0

    thanks Ravi - yes I am definitely getting a value for the formId

    lost my formatting when i posted the code snippet and when I tried to edit what i posted i got an xslt error

    it is the line      Record r = rs.GetRecord(formId); that is getting the error

    when i set debug on this I am definitely seeing that the formId is set in the same way as the xslt version

    thanks for the tip though that does look useful

    so this should work?

    would you say that this should return a record that i can get field data from?

     


  • Ravi Motha 290 posts 500 karma points MVP 8x c-trib
    Feb 22, 2011 @ 13:15
    Ravi Motha
    1

    aha, I just saw the following from another contour post, it may be as simple as this 


    Umbraco.Forms.Core.Record record = storage.GetRecord(new Guid(yourStringGUID));

     where the your string should be guid. so we need to check the format of your querystring, 

    I got that from here:

    http://our.umbraco.org/forum/umbraco-pro/contour/7163-Change-status-of-a-form-submission

  • John C Scott 473 posts 1183 karma points
    Feb 22, 2011 @ 14:32
    John C Scott
    0

    trying this now :D

  • John C Scott 473 posts 1183 karma points
    Feb 22, 2011 @ 14:40
    John C Scott
    0

    AHAAA that works - thank you Mr Motha

    so essentially what I did wrong was passing the guid as a string and not converting into a guid type

    makes sense really :)

    strongly typed - don't you just love it :D

  • Ravi Motha 290 posts 500 karma points MVP 8x c-trib
    Feb 22, 2011 @ 14:48
    Ravi Motha
    0

    no fuss, glad to help

     

Please Sign in or register to post replies

Write your reply to:

Draft