如何嵌入在.NET程序集的文本文件?文本文件、程序、NET

由网友(别秀恩爱i)分享简介:我想嵌入一个文本文件中的一个组件,这样我就可以加载文本,而不必从磁盘读取它,使我需要的一切都包含在exe文件中。 (所以它更便携)I would like to embed a text file in an assembly so that I can load the text without having to...

我想嵌入一个文本文件中的一个组件,这样我就可以加载文本,而不必从磁盘读取它,使我需要的一切都包含在exe文件中。 (所以它更便携)

I would like to embed a text file in an assembly so that I can load the text without having to read it from disk, and so that everything I need is contained within the exe. (So that it's more portable)

有没有办法做到这一点?我认为一些与资源文件?

Is there a way to do this? I assume something with the resource files?

如果你能,你怎么做,你怎么programaticaly加载文本转换成字符串?

And if you can, how do you do it and how do you programaticaly load the text into a string?

推荐答案

右键单击该项目文件,选择属性。

Right-click the project file, select Properties.

在打开,转至资源选项卡,如果它在标签页中间的只是一个蓝色的链接窗口,单击它,以创建一个新的资源。

In the window that opens, go to the Resources tab, and if it has just a blue link in the middle of the tab-page, click it, to create a new resource.

然后从上面的标签页的工具栏,选择添加一个新的文本文件,给它一个名称,它会被添加到您的项目,并开辟了。

Then from the toolbar above the tab-page, select to add a new text file, give it a name, it will be added to your project and opened up.

如果你走得很远得到这个,然后在code,你可以输入Resources.TheNameYouGaveTheTextFileHere,您可以访问其内容。请注意,第一次使用的资源类中的一类,你需要添加一个using指令(按Ctrl +打字资源得到菜单让VS来为你做它之后)。

If you get this far, then in your code you can type in Resources.TheNameYouGaveTheTextFileHere and you can access its contents. Note that the first time you use the Resources class in a class, you need to add a using directive (hit Ctrl+. after typing Resources to get the menu to get VS to do it for you).

如果事情是不清楚上面的介绍,请发表评论,我会编辑它,直到它是完整的还是有道理的:)

If something was unclear about the above description, please leave a comment and I'll edit it until it is complete or makes sense :)

阅读全文

相关推荐

最新文章