Get resource without knowing absolute path

Question Get resource without knowing absolute path

  • dimanche 30 avril 2006 16:22
     
     

     

    Hi all,

    I'm working on a C# windows application. I want to get access to a file in my application. This file is in my project and I want to access it without having to put the hard-coded full path.

    So, I want to do something like :

    <code>

    Assembly a = Assembly.GetExecutingAssembly();

    Stream stream = a.GetManifestResourceStream("KwenTest.resources");

    </code>

    But after this, I want to know the absolute path. But I think that the class Stream does not provide any information about this.

    So, what can I do ?

Toutes les réponses

  • dimanche 30 avril 2006 18:16
    Modérateur
     
     

    hi,

    i asked question close to this one

    http://forums.microsoft.com/MSDN/ShowPost.aspx?PostID=369382&SiteID=1

    hope this helps

  • lundi 1 mai 2006 00:35
     
     

    Strange thing happened to me the other day, I had a need to do the same thing.  So I pressed F1 in the C# Express IDE and started reading about resources, got mixed results but found my way.  For me, I had to embedd a file first through the Project properties menu.  I found the resource tab there and was able to load up an existing file.  No problem, but here's were I thought it was a little strange/interesting.  The embeded resource was acting like a string, not a file.  But the really cool thing is that the path was built in to the intellisense.  Turns out the path acted like a pointer as follows?: 

    string temp = namespace.class.properties.resources.resourcemanager.getxxxxxxxx;

     

    That's how I got it to work for me.

  • lundi 1 mai 2006 08:24
    Modérateur
     
     
    You have a file saved as an embedded resource, i'm mean that you want to pul out a embedded file in you resource?

    Or do you want to get the path of your application or assembly?
  • lundi 1 mai 2006 10:36
     
     

     

    Ok, here is what I want to do in reality :

    <code>

    ResourceManager resourceManager = ResourceManager.CreateFileBasedResourceManager("KwenTest", "W:/Applications/Test/KwenTest/KwenTest/Be/Kwen/KwenTest/Resources", null);

    this.Text = resourceManager.GetString("ListForm_User_Title", new CultureInfo("en"));

    </code>

    I want to apport internationalisation to my application. Two methods exist and it is this one that is good for me.

    But I want to replace the full path by something like : "Be/Kwen/KwenTest/Resources" because this directory is in my application and my application must still work in any location on the computer.

    And I found the way to access a resource (assembly.getManifestResourceStream()) but with this Stream object I can't construct a resourceManager.

    Thank you for everything...

  • mardi 2 mai 2006 10:48
     
     

    In Java, there is the possibility to do this :

    URL url = this.getClass().getResource("be/kwen/kwentest/resource/files/KwenTest.resources")

    Is there any possibility to do this in C# ?