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.
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
Please state the version of your Umbraco instance.
Hi, I am using umbraco v 4.7.1.1 (Assembly version: 1.0.4393.24044)
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 :-)
is working on a reply...