none
Accessing Embedded resource text file from a DLL. RRS feed

  • Question

  •  I have created an Dll for integrating in my project i have to embed text file for some data access .I have embed this file by setting property "Build Action" as Embbeded resource .Now I am not able to access it in my project .I am getting following error

    Could not find file 'C:\Documents and Settings\USER\Desktop\WindowsFormsApplication2\WindowsFormsApplication2\bin\Debug\MyFile.txt'.

    How can I access the embedded TEXT file in my DLL.


    SaiVaibhav@Acumen

    Tuesday, July 17, 2012 5:17 AM

Answers

  • Hi Vaibhav,

    Welcome to the MSDN Forum.

    Please try this code:

    Assembly ass = Assembly.Load("WinApp_pictureBox");
    ManifestResourceInfo reInfo = ass.GetManifestResourceInfo("WinApp_pictureBox.Resources.resources");
    Stream str = ass.GetManifestResourceStream("WinApp_pictureBox.Resources.resources");
    ResourceReader reader = new ResourceReader(str);
    string strType = "";
    byte[] resourceData = null;
    reader.GetResourceData("msdn2008", strType, resourceData);

    The resource data is stored in resouceData variable.

    I hope this will be helpful.

    Best regards,


    Mike Feng
    MSDN Community Support | Feedback to us
    Please remember to mark the replies as answers if they help and unmark them if they provide no help.

    Wednesday, July 18, 2012 9:37 AM
    Moderator

All replies

  • Thanks for your help but it can't help me,I am getting null.

    I am using my Dll with some other project.


    SaiVaibhav@Acumen

    Tuesday, July 17, 2012 9:04 AM
  • Hi Vaibhav,

    Welcome to the MSDN Forum.

    Please try this code:

    Assembly ass = Assembly.Load("WinApp_pictureBox");
    ManifestResourceInfo reInfo = ass.GetManifestResourceInfo("WinApp_pictureBox.Resources.resources");
    Stream str = ass.GetManifestResourceStream("WinApp_pictureBox.Resources.resources");
    ResourceReader reader = new ResourceReader(str);
    string strType = "";
    byte[] resourceData = null;
    reader.GetResourceData("msdn2008", strType, resourceData);

    The resource data is stored in resouceData variable.

    I hope this will be helpful.

    Best regards,


    Mike Feng
    MSDN Community Support | Feedback to us
    Please remember to mark the replies as answers if they help and unmark them if they provide no help.

    Wednesday, July 18, 2012 9:37 AM
    Moderator