简体   繁体   English

如何在Visual Studio中将文件添加到项目名称空间?

[英]how to add files to the project namespace in visual studio?

i am having a problem in adding the image files to project namespace. 我在将图像文件添加到项目名称空间时遇到问题。 I'm trying to do this like........ 我正在尝试这样做........

Step 1:Going to add existing item menu. 第1步:添加现有项目菜单。

Step 2:Then browsing to the file that i want to add and simply adding it. 步骤2:然后浏览到我要添加的文件,然后简单地添加它。

But when I'm trying to read this file by this method------- 但是当我试图通过这种方法读取这个文件时

Assembly myAssembly = Assembly.GetExecutingAssembly();
Stream myStream = myAssembly
        .GetManifestResourceStream("namespace.filename.fileExtension");
img = new Bitmap(myStream);

I get null in myStream. 我在myStream中得到null。 I think there is some other way to add files to the namespace of the project because previously I have added some files and the same method is working for those files. 我认为还有其他方法可以将文件添加到项目的名称空间,因为以前我已经添加了一些文件,并且相同的方法适用于这些文件。

Anybody knowing the answer please help. 任何知道答案的人都可以帮助。

Rregards, Madhup Madhup Rregards

Have you marked those files to be an embedded resource (solution explorer)? 您是否已将这些文件标记为嵌入式资源(解决方案资源管理器)? Also - try it without the extension. 另外-不带扩展名即可尝试。 You can use GetManifestResourceNames to check what is available. 您可以使用GetManifestResourceNames来检查可用的内容。

I think that you need to set the compile-property of the file to 'embedded resource'. 我认为您需要将文件的编译属性设置为“嵌入式资源”。 You find this propert by selecting th file in the solution explorer and then go to the properties window (F4). 通过在解决方案资源管理器中选择文件,然后转到属性窗口(F4),可以找到此属性。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何将cpp文件添加到Visual Studio 2008? - How to add cpp files to Visual Studio 2008? Visual Studio是否向资源文件添加了名称空间? - Did visual studio add namespace to resource file? 如何将自定义“项目项节点”添加到Visual Studio Flavored Project - How to add custom 'project item nodes' to Visual Studio Flavoured Project Visual Studio,如何添加项目,但不保存对原始项目的更改? - Visual Studio, how to add a project, but not save changes to the original project? 如何发布使用文本文件的Visual Studio项目2008? - how to publish a visual studio project 2008 that uses text files? Visual Studio:如何创建一个可以编译 2 个 exe 文件的项目? - Visual Studio: how to create a project that would compile 2 exe files? 如何在Visual Studio 2008中将整个文件夹添加到安装项目 - How to add an Entire folder to Setup Project in Visual Studio 2008 如何在普通项目Visual Studio 2008上添加快捷方式do文件 - How to add a shortcut do file on normal project Visual Studio 2008 有人知道如何在Visual Studio中将安装文件添加到安装项目中吗? - someone knows how to add a setup file into a setup project in visual studio? 如何通过Visual Studio DTE添加安装项目? - How to add a Setup project through Visual Studio DTE?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM