在FileOpen中使用资源 [英] Using Resources With FileOpen

查看:62
本文介绍了在FileOpen中使用资源的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述



我的vb.net项目的资源中有一些.txt文件.我正在尝试使用以下命令:

Hi,

I have some .txt files in the resources of my vb.net project. I am trying to use the command:

FileOpen(1, "FILE NAME", OpenMode.Input)



如何使用资源位置作为文件名?

谢谢



How do I use my resource location as the file name?

Thanks

推荐答案

您将.Txt文件放置在资源丰富的项目的Debug文件夹中.然后,您可以使用以下代码动态获取此路径:
You place your .Txt file in Debug folder of your Project insted of Resourses.Then you can get this path dynamically using following code :
Dim Path As String = My.Application.Info.DirectoryPath
'It returns the Path of the Debug folder where your Exe file created.


获取资源文件夹路径的代码:


Code to get Resource folder path :

Dim Path As String = My.Application.Info.DirectoryPath
Path = Path.Substring(0, Path.LastIndexOf("\"))
Path = Paht.Substring(0, Path.LastIndexOf("\")) & "\Resources"
MessageBox.Show(Path)



希望对您有所帮助.



I hope it will help you.


如果将文本文件放在.resx资源中,则不需要任何内容​​即可读取它.一旦创建资源,就会创建一个自动生成的源文件.看一下这个文件:它具有一个静态类(模块)和一个静态("Shared")属性;此属性的名称将与原始文件的名称相同或接近.直接在代码中使用此属性:其值将等于源文本文件的内容.

您可以在许多其他情况下使用此规则.假设您有一个PNG文件,并将其添加到某些资源文件中.自动生成的文件中的属性的类型将为Bitmap.您可以直接使用它.您无需读取资源流或类似内容.

—SA
If you put your text file in the .resx resource, you don''t need anything to read it. As soon as you create a resource, an auto-generated source file is created. Look at this file: it has a static class (module) and a static ("Shared") property in it; the name of this property will be the same or close to the name of your original file. Use this property directly in your code: its value will be equal to the content of the source text file.

You can use this rule for many other cases. Suppose you have a PNG file and added it to some resource file. The property in the auto-generated file will be of the type Bitmap; and you can use it directly. You won''t need to read resource stream or anything like that.

—SA


这篇关于在FileOpen中使用资源的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆