如何在C#里讲aspx里的title内容取出来
aspx文件是通过路径声明的FileInfo,我想讲他转换为XML来读,但是aspx的前两行无效,请问该怎么办~~?...
aspx文件是通过路径声明的FileInfo,我想讲他转换为XML来读,但是aspx的前两行无效,请问该怎么办~~?
展开
3个回答
展开全部
如果你取本页的Title,直接用Label1.Text= this.Title;
如果你要读取一个aspx文件内的<title>标记内的值,可以用我的代码:
protected void Button1_Click(object sender, EventArgs e)
{
System.IO.StreamReader sr1 = System.IO.File.OpenText("D:\\0_Published\\website2\\showcs.aspx");
String input1 = "",s="";
Boolean goon=true;
int a, b;
while ((input1 = sr1.ReadLine()) != null && goon)
{
a=input1.IndexOf("<title>");
if (a>=0)
{
b = input1.IndexOf("</title>");
if (b - a - 7 == 0)
s = "无标题";
else
s = input1.Substring(a + 7, b - a - 7);
goon = false;
}
}
Label1.Text= s;
sr1.Close();
sr1.Dispose();
}
如果你要读取一个aspx文件内的<title>标记内的值,可以用我的代码:
protected void Button1_Click(object sender, EventArgs e)
{
System.IO.StreamReader sr1 = System.IO.File.OpenText("D:\\0_Published\\website2\\showcs.aspx");
String input1 = "",s="";
Boolean goon=true;
int a, b;
while ((input1 = sr1.ReadLine()) != null && goon)
{
a=input1.IndexOf("<title>");
if (a>=0)
{
b = input1.IndexOf("</title>");
if (b - a - 7 == 0)
s = "无标题";
else
s = input1.Substring(a + 7, b - a - 7);
goon = false;
}
}
Label1.Text= s;
sr1.Close();
sr1.Dispose();
}
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询