對於Asp.Net 2.0中指令碼資源的研究(2)

來源:互聯網
上載者:User
對於Asp.Net 2.0中指令碼資源的研究(2)
Author: Truly

在上篇文章中我們主要介紹了.net 2.0 中的資源檔,並以WebForms.js為例做了重點分析,有朋友問我如何擷取所有的資源檔,方法有很多中。

可以使用我們熟悉的Reflector匯出所有資源檔(利用Reflector.FileDisassembler外掛程式),也可以使用下面的方法:

遍曆所有資源:

Attribute[] abc = System.Web.UI.WebResourceAttribute.GetCustomAttributes(Assembly.GetAssembly(typeof(System.Web.UI.Page))) ;

int i = 0;
foreach (Attribute a in abc)
{
    if (a.TypeId.ToString() == "System.Web.UI.WebResourceAttribute")
    {
        i++;
        Response.Write(((System.Web.UI.WebResourceAttribute)(a)).WebResource + "\r\n");
    }
}
Response.Write("<br>總數量:"+ i);

匯出所有的資源檔:

Assembly assm = Assembly.GetAssembly(typeof(System.Web.UI.Page));
Attribute[] abc = System.Web.UI.WebResourceAttribute.GetCustomAttributes(assm);

Stream stream;
System.IO.FileStream sr;
byte[] bt;
string name = "";
WebResourceAttribute wra;

foreach (Attribute a in abc)
{
    if (a.TypeId.ToString() == "System.Web.UI.WebResourceAttribute")
    {
        wra = (WebResourceAttribute)a;
        name = wra.WebResource;

        stream = assm.GetManifestResourceStream(name);
        if (stream == null)
            continue;
        bt = new byte[stream.Length];
        stream.Read(bt, 0, (int)stream.Length);
        sr = new FileStream(@"f:\resource\" + name, FileMode.Create);

        sr.Write(bt, 0, bt.Length);
        sr.Close();
        stream.Close();

        Response.Write(a.TypeId.ToString() + "<br />");
    }
}

相關文章

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.