0

In my page I will get the ID from link parameters, with that ID I will search the database for the file path, after reading the file and storing its contents I want to put its contents inside my <pre> tag... So I will have a literal in which the text for it will be:

Code.Text = "<pre>" + File Contents in string + "</pre>";

My question is how will I insert the contents there if I need to read the file line by line into an string array, unless I read it all into one string, BUT that will make the text look like one huge line in the page.

Also, is it going to conflict with literal syntax(?) definitions, since for quotes we have to do \" instead of " ...?

datalekz
  • 129
  • 1
  • 14
  • What have you tried? Can we see your code? And \" isn't 'literal syntax', it's used to escape characters in constants *only*, not in variable values. Meaning: `var s = "\""; MessageBox.Show(s);` will show a message box with just a double quote `"` – wgraham Jun 20 '13 at 17:17
  • @wgraham I know it isn't literal syntax and thanks for correcting me anyways, wouldn't figure out the term any time soon :b ... – datalekz Jun 21 '13 at 08:46

1 Answers1

1

If you are working with literal control, you use the StringBiulder And Append properties becouse It let you put any HTML code from code behind. Something like:

    //Declare your String Builder
    private StringBuilder stb = new StringBuilder();

And also you could have any proccess when you read the file, and split it by any char like \n

        string readFile = //Any Method that you read you file string.
        string[] tokens = readFile.Split('\n');
        stb.Append("<pre>");

        foreach (string s in tokens)
        {
            stb.Append( s + "<\br>");
        }
        stb.Append("</pre>");

finally you attach the Stringbuilder value to you Literal

YourLiteral.Text = stb.ToString();

I hope that help, and you won't have the value in one line. And remember the carring return need be in the string file to the split works.

Cheers

Wilfredo P
  • 4,070
  • 28
  • 46