C#中有什么资源中的文件路径? [英] C# whats the file path within Resource?

查看:86
本文介绍了C#中有什么资源中的文件路径?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如果文件位于Properties.Resouce上,它的路径是什么?



If a file located on Properties.Resouce, what the path about it?

string strCon ="Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" + filepath +"....





文件路径应该记下什么?



whats the filepath should to write down?

推荐答案

默认情况下,项目资源中的文件都嵌入在程序集中。所以您可以使用代码以字节[]的形式访问它们

by default files in the project resource are embedded in the assembly. so you can access them as byte[] using the code
[ProjectName].[Resources].[FileName]



在你的情况下因为你需要文件路径而无法工作。所以你必须明确告诉编译器将文件复制到应用程序目录。只需在资源文件夹中选择文件,在解决方案资源管理器中,右键单击并属性。这将为您提供复制到输出目录选项,将其设置为复制a lways。然后当你构建你的应用程序时,它会弹出Resources文件夹下的输出目录。

修改你的代码如下,以适应变化




which in your case won't work because you need the file path.So you have to explicitly tell the compiler to copy the file to the application directory. Just select the file in the resources folder, inside the solution explorer, right click and "Properties". That would give you an option "Copy to output directory" set it to "Copy always". then when you build your application it would pop up in the output directory under "Resources" folder.
Modify your code as below to accommodate the changes

string strCon ="Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" + System.Windows.Forms.Application.StartupPath+"\\Resources\\"+[filename]+"....





希望有帮助

祝你好运



hope that helped
good luck


你好b $ b基恩,



您可以使用以下代码访问Properties.Resouce中的文件:



.. \ bin \ Debug \ {YourFileName}





如果您有任何疑问,请告诉我。

请提供投票这是否对您有所帮助。



谢谢,

Imdadhusen
Hi Kean,

You can access the file which is inside the Properties.Resouce using following code:

..\bin\Debug\{YourFileName}


Please do let me know, if you have any doubt.
Please provide Vote if this would be helpful to you.

Thanks,
Imdadhusen


这篇关于C#中有什么资源中的文件路径?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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