.net返回的字符串被截断

时间:2011-08-17 03:43:08

标签: c# dll

我返回一个html字符串作为函数的返回值。返回字符串有点长(但没有比较字符串数据类型的限制)。但是返回的字符串被截断了。

我试图将它转换为StringBuilder而没有任何好处。

P.S。我的班级在.dll里面,我试图从外面访问它,

出了什么问题,我该怎么办?

我在这里消费:

        string st = asso.getHtmlReport();

        FileStream fs = File.OpenWrite("file.html");

        StreamWriter sw = new StreamWriter(fs);

        sw.Write(st);

这是字符串

        public string getHtmlReport()
    {
        string html = "<html><head><title>Association</title></head><body>" +
    "<table >" +
        "<tr align=\"left\">" +
        "<th>t</th>" +
        "<th>" + name1 + "</th>" +
        "<th>Avg rise</th>" +
        "<th>" + name2 + "</th>" +
        "<th>Avg rise</th>" +
        "<th>Difference</th>" +
        "<th>Direction</th>" +
        "</tr>" +
        "<tr>"+
        "<td style=\"padding-left:10px;padding-right:20px;\" valign=\"top\">" +
            seriesPrint(t) +
        "</td>" +
        "<td style=\"padding-left:10px;padding-right:20px;\" valign=\"top\">" +
            seriesPrint(series1) +
        "</td>" +
        "<td style=\"padding-left:10px;padding-right:20px;\" valign=\"top\">" +
            seriesPrint(avg1) +
        "</td>" +
        "<td style=\"padding-left:10px;padding-right:20px;\" valign=\"top>" +
            seriesPrint(series2) +
        "</td>" +
        "<td style=\"padding-left:10px;padding-right:20px;\" valign=\"top\">" +
            seriesPrint(avg2) +
        "</td>" +
        "<td style=\"padding-left:10px;padding-right:20px;\" valign=\"top\">" +
            seriesPrint(diff) +
        "</td>" +
        "<td style=\"padding-left:10px;padding-right:20px;\" valign=\"top\">" +
            seriesPrint(dir) +
        "</td>" +
        "</tr>"+ "</table>" +
    "<div style=\"padding:10px; position:absolute; right:0px; top:0px; width:300px; border:this solid black; background-color:Black; color:White;\">" +
        "<span style=\" font-weight:bolder; font-size: 2em; color: White;\">Results</span><br />" +
        "<span style=\" font-weight:bolder; font-size: 1em; color: White;\">Total records : " + series1.Length + "</span><br />" +
        "<span style=\" font-weight:bolder; font-size: 1em; color: White;\">Average error : " + avgError() + "</span><br />" +
        "<span style=\" font-weight:bolder; font-size: 1em; color: White;\">Together : " + support() + "</span><br />" +
        "<span style=\" font-weight:bolder; font-size: 1em; color: White;\">Opposite : " + (series1.Length - support()) + "</span><br />" +
    "</div>" +
"</body></html>";
        return html;

    }

1 个答案:

答案 0 :(得分:2)

您需要在编写后刷新流。

sw.Flush();