1

I'm trying to show test run log (text file in a windows server) to the user if he/she clicks a link.

So far I'm able to return the string but the formatting is lost (no newlines) when displayed in the browser.

public string GetTestLog(...)
{ 
    return File.ReadAllText(logFileUrl);
}

How can I keep the formatting of the string?

2 Answers 2

1

You could return the file with test/plain contentType and then it should render properly as a text file...

public ActionResult GetTestLog(...)
{
    return new FileContentResult(File.ReadAllBytes(logFileUrl), "text/plain");
}

If you are rendering it as HTML, you have to replace all newlines with <br/> or enclose it in a TEXTAREA or PRE.

Sign up to request clarification or add additional context in comments.

Comments

0

You can display the output inside ah HTML PRE tag to preserve the original formatting.

http://www.w3.org/TR/html5/the-pre-element.html#the-pre-element

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.