Results 1 to 4 of 4

Thread: Trouble reading .ini file from debugger

  1. #1

    Thread Starter
    Fanatic Member
    Join Date
    Aug 2005
    Location
    Wisconsin
    Posts
    788

    Trouble reading .ini file from debugger

    I am trying to read an .ini file to get an ip address and port to connect to while I am debugging and developing and app for windows mobile 6.5.
    Here is the code I am suing but it is not finding the file. Probably not doing something correctly and that is what I am asking to find.
    Code:
            public String GetIP()
            {
                try
                {
                    String path = System.IO.Path.GetDirectoryName(System.Reflection.Assembly.GetExecutingAssembly().GetName().CodeBase);
    
                    using (StreamReader sr = new StreamReader(path + "\\somename.ini"))
                    {
                        String line;
                        String IPAddress = "NONE";
                        while ((line = sr.ReadLine()) != null)
                        {
                            char[] delimiterChar = { '=' };
    
                            String[] settings = line.Split(delimiterChar);
    
                            String temp = settings[0];
                            String tempIP = settings[1];
                            if (temp == "IP")
                            {
                                IPAddress = tempIP;
                                return IPAddress;
                            }
                        }
                        if (IPAddress.Length > 0)
                        {
                            return IPAddress;
                        }
                        else
                        {
                            return "ERROR";
                        }
                    }
                }
                catch (Exception ex)
                {
                    String errMsg = ex.Message;
                    return "0";
                }
            }

  2. #2
    PowerPoster techgnome's Avatar
    Join Date
    May 2002
    Posts
    34,687

    Re: Trouble reading .ini file from debugger

    Is the ini file in the same folder where the app is? and I DO NOT mean in the folder where the project is... when you run the app, it compiles it to a folder, likely the bin/debug folder... is the ini file THERE?

    -tg
    * I don't respond to private (PM) requests for help. It's not conducive to the general learning of others.*
    * I also don't respond to friend requests. Save a few bits and don't bother. I'll just end up rejecting anyways.*
    * How to get EFFECTIVE help: The Hitchhiker's Guide to Getting Help at VBF - Removing eels from your hovercraft *
    * How to Use Parameters * Create Disconnected ADO Recordset Clones * Set your VB6 ActiveX Compatibility * Get rid of those pesky VB Line Numbers * I swear I saved my data, where'd it run off to??? *

  3. #3

    Thread Starter
    Fanatic Member
    Join Date
    Aug 2005
    Location
    Wisconsin
    Posts
    788

    Re: Trouble reading .ini file from debugger

    When I look at the path the beginning is "\\Program Files\\Program Name\\somename.ini". I will check the bin/debug folder.


    **It is in the bin\debug folder**
    Last edited by mojo69; Sep 27th, 2011 at 02:17 PM.

  4. #4

    Thread Starter
    Fanatic Member
    Join Date
    Aug 2005
    Location
    Wisconsin
    Posts
    788

    Re: Trouble reading .ini file from debugger

    When I hard code the path ("C:\\Program Files\\Program Name\\somename.ini") then I get an error ("Could not find part of the path \\C:\\Program Files\\Program Name\\somename.ini"). Looks like it has has added and extra str of "\\" to the path.

    I am only using the emulator in VS2008 to debug this. Could this be the issue?

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width