对文件的BuildAction以content,resource两种方式的读取

在Demo项目中,新建文件夹Files,其中放置file1.txt, file2.txt

1. file1.txt的BuildAction为content:

Stream streamWithContent = Application.GetResourceStream(new Uri("Files/file1.txt", UriKind.Relative)).Stream;
String ssWithContent = new StreamReader(streamWithContent).ReadToEnd();

 

2. file2.txt的BuildAction为resource:

Stream streamWithResource = Application.GetResourceStream(new Uri("/Demo:component/Files/file2.txt", UriKind.Relative)).Stream;
String stringWithResource = new StreamReader(streamWithResource).ReadToEnd();
posted @ 2012-02-29 15:06  devbian  阅读(328)  评论(0编辑  收藏  举报