关于VB.NET中的资源文件夹 [英] About resource folder in VB.NET
本文介绍了关于VB.NET中的资源文件夹的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我在我的vb.net项目的资源文件夹中添加了一个xml文件和文本,我想在我的代码中使用它如何访问这些文件?
我尝试过:
我试图使用
My.resources。<文件名>
但它不起作用
I have one xml file and text added in the resource folder of my vb.net project and i want to use it in my code how can i access those files??
What I have tried:
I tried to use
My.resources.<filename>
but its not working
推荐答案
假设您已将文件添加为资源,请在解决方案资源管理器中选择文件并确保Build Action属性设置为Embedded Resource
然后你可以得到这样的文字:
Assuming you have added the files as resources, select the file(s) in the Solution Explorer and make sure the "Build Action" property is set to "Embedded Resource"
You can then get to the text like this:
Dim filetext As String
Dim ass As Assembly = GetType(yourClassName).Assembly
Using reader As New StreamReader(ass.GetManifestResourceStream("yourNamespace.yourTextFile.txt"))
fileText = reader.ReadToEnd()
End Using
您还可以使用
fileText = My.Resources.Resource1.yourFileName
如果您是以这种方式加载XML然后记得使用 LoadXml
方法和不 加载
因为文件将作为(大)字符串返回而不是文件名
If you are loading XML in this way then remember to use the LoadXml
method and not Load
because the file will have been returned as a (large) string NOT a file name
这篇关于关于VB.NET中的资源文件夹的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文