<%@ Control Language="C#" ClassName="SourceShow" %>
<%@ Import Namespace="System.Drawing" %>
<%@ Import Namespace="System.IO" %>
<%@ Import Namespace="System.Text" %>
<script runat="Server">
private String _path="";
private String _encode="Shift_JIS";
private Color _forecolor=Color.FromName("White");
private String _bgcolor="Black";
private String _ext=".aspx;.ascx;.asmx;.xml;.sql;.vb;.cs";
public String FilePath {set {_path=value;}}
public String FileEncoding {set {_encode=value;}}
public String ForeColor {set {_forecolor=Color.FromName(value);}}
public String BgColor {set {_bgcolor=value;}}
public String Extension {set {_ext=value;}}
public void Page_Load(Object sender, EventArgs e){
    bool flag=false;
    String[] aryExt=_ext.Split(';');
    for(int i=0;i<aryExt.Length;i++){
        if(_path.EndsWith(aryExt[i])){
            flag=true;
            break;
        }
    }
    if(flag){
        using(StreamReader reader=new StreamReader(Server.MapPath(_path),Encoding.GetEncoding(_encode))){
            StringBuilder builder=new StringBuilder();
            while(reader.Peek()>-1){
                String line=Server.HtmlEncode(reader.ReadLine());
                builder.Append(line.Replace("\t","&nbsp;&nbsp;&nbsp;&nbsp;") + "<br />");
            }
            table.Rows[0].Cells[0].BgColor=_bgcolor;
            output.ForeColor=_forecolor;
            output.Text=builder.ToString();
            reader.Close();
        }
    }else{
        output.Text="指定されたファイルの内容は表示できません。";
    }
}
</script>
<table id="table" runat="Server"
    border="0" cellpadding="10">
<tr>
    <td>
        <asp:Label id="output" runat="Server" />
    </td>
</tr>
</table>