|
-
Sep 27th, 2011, 10:54 AM
#1
Thread Starter
Fanatic Member
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";
}
}
-
Sep 27th, 2011, 11:48 AM
#2
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
-
Sep 27th, 2011, 01:37 PM
#3
Thread Starter
Fanatic Member
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.
-
Sep 27th, 2011, 02:26 PM
#4
Thread Starter
Fanatic Member
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
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|