Copied to clipboard

Flag this post as spam?

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


  • Steven Shiells 5 posts 25 karma points
    Mar 22, 2012 @ 11:48
    Steven Shiells
    0

    Display media item contents using template.

    Hi there,

    I have written an extension that uploads a number of text files as media items and I would like to be able to display the contents of the file using some code in the template and I am unsure where to start.

    I have had a look around the forum and did a goolge search but was unable to find anything that I could use.

    Any help would be much appreciated.

    Thanks,

    Steven

  • Grant Thomas 291 posts 324 karma points
    Mar 22, 2012 @ 12:01
    Grant Thomas
    0

    Please state the version of your Umbraco instance.

  • Steven Shiells 5 posts 25 karma points
    Mar 22, 2012 @ 12:02
    Steven Shiells
    0

    Hi, I am using umbraco v 4.7.1.1 (Assembly version: 1.0.4393.24044)

  • Steven Shiells 5 posts 25 karma points
    Mar 22, 2012 @ 12:38
    Steven Shiells
    0

    I found a solution using razor;

          @if(Model.HasProperty("file") && !String.IsNullOrEmpty(Model.GetProperty("file").Value)){

            string filePath = Server.MapPath(@Model.MediaById(Model.file).umbracoFile);
            if (File.Exists(filePath))
            {
              @File.ReadAllText(filePath);
            }
          }

    If there are any cleaner solutions feel free to let me know :-)

Please Sign in or register to post replies

Write your reply to:

Draft