Research on script resources in ASP. NET 2.0 (2)

Source: Internet
Author: User
Research on script resources in ASP. NET 2.0 (2)
Author: Truly

In the previous article, we mainly introduced the following. NET 2.0 resource file, and use webforms. JS is used as an example to make a key analysis. Some friends asked me how to obtain all the resource files. There are many methods.

You can use our familiar reflector to export all resource files (using the reflector. filedisassembler plug-in), or use the following method:

Traverse all resources:

Attribute [] ABC = System. Web. UI. webresourceattribute. getcustomattributes (assembly. getassembly ( Typeof (System. Web. UI. Page )));

Int I =   0 ;
Foreach (Attribute In ABC)
{
If (A. typeid. tostring () =   " System. Web. UI. webresourceattribute " )
{
I ++ ;
Response. Write (system. Web. UI. webresourceattribute) (a). webresource +   " \ R \ n " );
}
}
Response. Write ( " <Br> total quantity: " + I );

Export all resource files:

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;
StringName= "";
Webresourceattribute wra;

foreach (attribute a in ABC)
{< br> If (. typeid. tostring () = " system. web. UI. webresourceattribute " )
{< br> 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/>");
}
}

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

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.