Original article address:
Http://www.cnblogs.com/huizhang212/archive/2012/03/09/ResFile.html
Some resource files are preset in the project more or less during application development. With development tools, we can add resource files to projects for use in programs.
I. BuildAction
1. There are three common statuses of BuildAction attributes: Content | Resource | None.
Files whose BuildAction attribute is set to Conten will be directly packaged in xap files as independent files.
Files whose BuildAction attribute is set to Resource will be embedded into the dll file in the xap package.
Files whose BuildAction property is set to None will not be stored in any form in the xap package
2. Select Content or Resource.
Microsoft explained that "Content" is better than "Resource. Because Windows Phone 7 optimizes the file and network stream, but the Memory stream does not. Set to the Content type. These files will exist in the xap package as independent files. If they are set to resource, they will be compiled into the dll. If these files are set as Resource, they need to be read and put into the file during playback, which reduces the performance. Therefore, if your program contains a large number of media files, it is better to set their BuildAction to "Content" for better performance.
Ii. Read and Write resource files
1. resource files are read-only and cannot be written.
2. Read the resource file.
// Resource file path
String path = "/Res/test.txt ";
// Read the file content
String content = String. Empty;
// Resource Type File Processing
Try
{
StreamResourceInfo reader = Application. GetResourceStream (new Uri (path, UriKind. Relative ));
If (reader! = Null)
{
Using (StreamReader streamReader = new StreamReader (reader. Stream ))
{
Content = streamReader. ReadToEnd ();
}
}
}
Catch (Exception ex)
{
// Read failed
}