Reading a property file

Last post 06-26-2008 1:47 PM by bonafiden. 8 replies.

Sort Posts:

  • Reading a property file

    06-25-2008, 10:10 AM
    • Member
      25 point Member
    • bonafiden
    • Member since 02-18-2007, 9:08 AM
    • Posts 187

    I need to read a property file, which is in the project folder, without exact indication of the location. In other words, I need analog of Java's statement:

    InputStream propStream = Thread.currentThread().getContextClassLoader().getResourceAsStream(CONFIGURATION_RULES_FILE);

    How can I do this in ASP.NET? 

     

  • Re: Reading a property file

    06-26-2008, 8:24 AM
    • All-Star
      89,437 point All-Star
    • SGWellens
    • Member since 01-02-2007, 9:27 PM
    • Twin Cities, MN
    • Posts 7,308
    • Moderator
      TrustedFriends-MVPs

    Are you looking for something like this?

     

            String[] Contents;
            String FullPath;
    
            FullPath = Server.MapPath(@"~\MyConfif.config");
            
            Contents = File.ReadAllLines(FullPath);
     
    Steve Wellens

    My blog
  • Re: Reading a property file

    06-26-2008, 9:17 AM
    • Member
      25 point Member
    • bonafiden
    • Member since 02-18-2007, 9:08 AM
    • Posts 187

    I need to do this in dll, so I cannot use neither Server object, nor Web.config file.

  • Re: Reading a property file

    06-26-2008, 9:54 AM
    • All-Star
      89,437 point All-Star
    • SGWellens
    • Member since 01-02-2007, 9:27 PM
    • Twin Cities, MN
    • Posts 7,308
    • Moderator
      TrustedFriends-MVPs

    You can pass a reference to the Server object to the dll.

    You can read any kind of text file.

    Steve Wellens

    My blog
  • Re: Reading a property file

    06-26-2008, 10:01 AM
    • Member
      25 point Member
    • bonafiden
    • Member since 02-18-2007, 9:08 AM
    • Posts 187

    Is there any other way, beside using Server object and config file as parameter? Can I somehow read file, that is located in same directory as dll source code, same as in Java example?

  • Re: Reading a property file

    06-26-2008, 12:04 PM
    • All-Star
      89,437 point All-Star
    • SGWellens
    • Member since 01-02-2007, 9:27 PM
    • Twin Cities, MN
    • Posts 7,308
    • Moderator
      TrustedFriends-MVPs

    The RelativeSearchPath of the AppDomain will contain the directory of the dll.

    You cannot get the directory of the source code because that may not exist at runtime...after deploying.

     

    namespace ClassLibrary1
    {
        public class Class1
        {
            public void MyFunction()
            {
                 AppDomain currentDomain = AppDomain.CurrentDomain;
                 currentDomain.RelativeSearchPath;
            }
     
    Steve Wellens

    My blog
  • Re: Reading a property file

    06-26-2008, 12:37 PM
    • Member
      25 point Member
    • bonafiden
    • Member since 02-18-2007, 9:08 AM
    • Posts 187

    Thank you for trying to help :-)

    But why this works in Java (please see statement at the beginning of the thread)?

  • Re: Reading a property file

    06-26-2008, 1:33 PM
    • All-Star
      89,437 point All-Star
    • SGWellens
    • Member since 01-02-2007, 9:27 PM
    • Twin Cities, MN
    • Posts 7,308
    • Moderator
      TrustedFriends-MVPs

    bonafiden:
    But why this works in Java (please see statement at the beginning of the thread)?

    If you want to know why something works in Java, perhaps a Java forum would be a more appropriate place to ask your question.

    This is an Asp.net forum.

     

    Steve Wellens

    My blog
  • Re: Reading a property file

    06-26-2008, 1:47 PM
    • Member
      25 point Member
    • bonafiden
    • Member since 02-18-2007, 9:08 AM
    • Posts 187

    I jaust have to reproduce same functionality (translate from Java) in ASP.NET, that's why I am trying to make sure that I am doing the same thing.

Page 1 of 1 (9 items)