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/>");
}
}