Add Property.Value thats is not a string Options
Zach
Posted: Saturday, October 06, 2007 12:11:55 AM
Rank: Devotee

Joined: 8/15/2007
Posts: 30
So, as I threatened to do in an earlier post, I'm writing a user control to pull URL parameters into the document. It seems to me the best place to put them would be as a property in the current node. Looking at the Property class in umbraco nodeFactory, it looks like it can only be a string. What I would ultimately like to do is set it up something like:

Code:

<data alias="URLParameters">
    <param name="Flies">
        <value>PMD</value>
        <value>BWO</value>
    </param>
    <param name="Rods">
        <value>Sage</value>
        <value>Winston</value>
        <value>Zebco</value>
    </param>
</data>


Both of the parameters shown would are comma separated lists in this example. I can get the parameters fine, but can anyone offer some insight on where to go from here? Thanks!
Zach
Posted: Saturday, October 06, 2007 12:13:42 AM
Rank: Devotee

Joined: 8/15/2007
Posts: 30
These won't be stored in the actual xml, they'll just be pulled in if they're present on the URL in that instance.
Zach
Posted: Saturday, October 06, 2007 4:10:12 AM
Rank: Devotee

Joined: 8/15/2007
Posts: 30
Well, I think I found something that works. This will manipulate the XML instance in the background to add URL parameters. Feel free to take a look if you're interested and please don't hesitate to critique. I apologize about being so active on the board... it's just so hard to find good information.

Code:

<%@ Control Language="C#" ClassName="InsertURLParams" %>
<%@ Import Namespace="System.Text" %>
<%@ Import Namespace="System.Collections" %>
<%@ Import Namespace="System.Xml" %>
<%@ Import Namespace="System.Xml.XPath" %>
<%@ Import Namespace="umbraco" %>
<%@ Import Namespace="umbraco.presentation.nodeFactory" %>

<script runat="server">

    private string _params = "";
    private char _splitchar = ',';
    
    public string ParamsToInsert
    {
        get { return _params; }
        set { _params = value; }
    }

    public char SplitChar
    {
        set { _splitchar = Convert.ToChar(value); }
    }
        
    protected void Page_Load(object sender, EventArgs e)
    {
        Node curNode = Node.GetCurrent();
        StringBuilder paramSB = new StringBuilder();

        XmlDocument myDoc = content.Instance.XmlContent;
        XmlNode airportNode = myDoc.SelectSingleNode("//node[@id=" + curNode.Id + "]");
        XmlNode dataNode = airportNode.SelectSingleNode("data[@alias='URLParameters']");

        if (!dataNode == null)
        {
            foreach (XmlNode cNode in dataNode.SelectNodes("*"))
            {
                dataNode.RemoveChild(cNode);
            }
        }
        else
        {
            dataNode = myDoc.CreateNode("element", "data", "");
            XmlAttribute dataAlias = myDoc.CreateAttribute("alias");
            dataAlias.InnerText = "URLParameters";
            dataNode.Attributes.Append(dataAlias);
        }

        try
        {
            foreach (string key in _params.Split(','))
            {
                XmlElement paramNode = myDoc.CreateElement("param");
                XmlAttribute alias = myDoc.CreateAttribute("alias");
                alias.InnerText = key;
                paramNode.Attributes.Append(alias);

                foreach (string myVal in Request.Params[key].Split(_splitchar))
                {
                    XmlElement valElem = myDoc.CreateElement("value");
                    valElem.InnerText = myVal;
                    paramNode.AppendChild(valElem);
                }
                dataNode.AppendChild(paramNode);
            }
        }
        catch
        {
            throw;
        }

        airportNode.AppendChild(dataNode);
    }

</script>


Users browsing this topic
Guest


You cannot post new topics in this forum.
You cannot reply to topics in this forum.
You cannot delete your posts in this forum.
You cannot edit your posts in this forum.
You cannot create polls in this forum.
You cannot vote in polls in this forum.