Posts

Showing posts from July, 2014

Umbraco Razor For Each Check for ODD and Even

This script is for something else (an rss feed from Vimeo), but the bits to check for ODD and EVEN are Highlighted in Yellow

@using umbraco.MacroEngines
@inherits DynamicNodeContext
@using System.Xml;


<div id="portfolio-wrapper" style="position: relative; overflow: hidden; height: 921px;" class="isotope">
@{ var odd = true; }
@{
    //Get the XML from remote URL
    XmlDocument xml = new XmlDocument();

    //URL currently hardcoded - but you could use a macro param to pass in URL
    xml.Load("******");


    //Select the nodes we want to loop through
    XmlNodeList nodes = xml.SelectNodes("//item");


    //Traverse the entire XML nodes.
    foreach (XmlNode node in nodes)
    {

        //Get the value from the <title> node
        var title = node.SelectSingleNode("title").InnerText;



        //Get the value from the <description> node

        var description = node.SelectSingleNode("description").Inn…

Umbraco Razor List Random Pages from a specific node from anywhere on the site and exclude by Node Type Alias

@inherits umbraco.MacroEngines.DynamicNodeContext
@{
var siteInfoPage = @Model.NodeById(1064);

<h3><a href="@siteInfoPage.Url" title="@siteInfoPage.pageNavigationName">Popular Pages</h3>
<ul>


@foreach (var thisPage in @Model.NodeById(1064).Descendants().Where("visible && NodeTypeAlias != \"Faq\"").Random(7))
{
<li><a href="@thisPage.Url">@thisPage.pageHeadingName</a></li>
}

</ul>
}

Umbraco Razor Writing to a Text File by getting a Querystring and Reading From a Text File

Please see this great post:
http://www.asp.net/web-pages/tutorials/files,-images,-and-media/working-with-files


Reading From:

@using System.IO;

@{
    var result = "";
    Array userData = null;
    char[] delimiterChar = {','};

    var dataFile = Server.MapPath("~/App_Data/MyTextFile.txt");

    if (File.Exists(dataFile)) {
        userData = File.ReadAllLines(dataFile);
        if (userData == null) {
result = "failed";
            @Html.Raw("The file is empty");
        }
    }
    else {
        result = "failed";
            @Html.Raw("The file does not exist. MyTextFile.txt");
    }


}

@{

        if (result == "") {

            foreach (string dataLine in userData) {

                foreach (string dataItem in dataLine.Split(delimiterChar)) {
                    @dataItem
                }

            }

        }
}

Writing To from a Querystring:


@using System.IO;



@{
var qInput = "";
    if (Request[&…

Umbraco JQuery Search with drop down selection, Usinc C# Razor