首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 网站开发 > asp.net >

asp.net中怎么创建JS文件

2012-01-01 
asp.net中如何创建JS文件?我是这样写的:publicvoidcj(Objectsender,EventArgse){intshuliangInt32.Parse(

asp.net中如何创建JS文件?
我是这样写的:
public   void   cj(Object   sender,EventArgs   e)
    {
        int   shuliang=Int32.Parse(ts.Text);
        string   sqlstring= "select   top   "+shuliang+ "bt,url_shtml   from   news   where   lx= ' "+ddl.SelectedItem.Text+ " '   order   by   ID   DESC ";
DataSet   ds=new   DataSet();
SqlDataAdapter   adap=new   SqlDataAdapter(sqlstring,conn);
adap.Fill(ds, "news ");
StreamWriter   sw=File.CreateText(Server.MapPath( "../JS/ "+ddl.SelectedItem.Value+ ".js "));
//FileStream   fs=new   FileStream(Server.MapPath( "../JS/ "+ddl.SelectedItem.Value+ ".js ",FileMode.Create,FileAccess.Write));
//StreamWriter   sw=new   StreamWriter(fs,Encoding.Default);
for(int   i=0;i <shuliang;i++)
{
sw.WriteLine( "document.write( ' <a   href=shtml/news/ "+ds.Tables[ "news "].Rows[i][ "url_shtml "].ToString()+ "   target=_blank> "+ds.Tables[ "news "].Rows[i][ "bt "].ToString()+ " </a> ') ");
}
sw.Flush();
sw.Close();
    }
可是创建的JS文件乱码!怎么回事啊???在线狂等!!!

[解决办法]
我觉得你要是写文本用TextWrite比较好,因为stream write一般是用来写入byte的,或者你将字符串转为byte数组好了,用System.Text.Encording,这样

热点排行