473,405 Members | 2,272 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,405 software developers and data experts.

File reading problem

Hi I'm having problem reading a file from my program and I think it's from a
procedure I'm using but I don't see where I'm going wrong. Here is the code:

public bool AllowUsage()

{

OperatingSystem os = Environment.OSVersion;

AppDomain ad = Thread.GetDomain();

ad.SetPrincipalPolicy(PrincipalPolicy.WindowsPrinc ipal);

WindowsPrincipal wp = (WindowsPrincipal)Thread.CurrentPrincipal;
if(os.Platform == System.PlatformID.Win32NT &&
wp.IsInRole(WindowsBuiltInRole.Administrator) == true)

{

return true;

}

else

{

return false;

}

}

Antd then I call it here:

void MainFormLoad(object sender, System.EventArgs e)

{

if(!this.AllowUsage())

{

MessageBox.Show("You are not an administrator on this system. Program usage
denied.", "ConfigBackup", MessageBoxButtons.OK, MessageBoxIcon.Stop);

this.Close();

}
// Read the Konfig.ini file and store the results

using(StreamReader FStream = new StreamReader("Konfig.ini"))

{

string[] confOptions = new String[9];

string Line;

int i = 0;
while((Line = FStream.ReadLine()) != null)

{

confOptions[i] = Line;

i++;

}

this.textBox1.Text = confOptions[0];

this.textBox2.Text = confOptions[1];

this.textBox3.Text = confOptions[2];

this.textBox4.Text = confOptions[3];

this.textBox5.Text = confOptions[4];

this.textBox6.Text = confOptions[5];

this.textBox7.Text = confOptions[6];

this.textBox8.Text = confOptions[7];

this.textBox9.Text = confOptions[8];

}

this.label7.Text = "phpMyAdmin v" + this.textBox1.Text;

this.label8.Text = "Apache HTTP Server v" + this.textBox2.Text;

this.label9.Text = "MySQL Database Server v" + this.textBox3.Text;

this.label10.Text = "PHP v" + this.textBox4.Text;

}

Can anyone help me?
Nov 16 '05 #1
2 2450
Well, I don't see anything particularly wrong, what problem are you having?

--
Adam Clauss
ca*****@tamu.edu

"Sabin Finateanu" <fs****@rdslink.ro> wrote in message news:e9*************@TK2MSFTNGP12.phx.gbl...
Hi I'm having problem reading a file from my program and I think it's from a
procedure I'm using but I don't see where I'm going wrong. Here is the code:

public bool AllowUsage()

{

OperatingSystem os = Environment.OSVersion;

AppDomain ad = Thread.GetDomain();

ad.SetPrincipalPolicy(PrincipalPolicy.WindowsPrinc ipal);

WindowsPrincipal wp = (WindowsPrincipal)Thread.CurrentPrincipal;
if(os.Platform == System.PlatformID.Win32NT &&
wp.IsInRole(WindowsBuiltInRole.Administrator) == true)

{

return true;

}

else

{

return false;

}

}

Antd then I call it here:

void MainFormLoad(object sender, System.EventArgs e)

{

if(!this.AllowUsage())

{

MessageBox.Show("You are not an administrator on this system. Program usage
denied.", "ConfigBackup", MessageBoxButtons.OK, MessageBoxIcon.Stop);

this.Close();

}
// Read the Konfig.ini file and store the results

using(StreamReader FStream = new StreamReader("Konfig.ini"))

{

string[] confOptions = new String[9];

string Line;

int i = 0;
while((Line = FStream.ReadLine()) != null)

{

confOptions[i] = Line;

i++;

}

this.textBox1.Text = confOptions[0];

this.textBox2.Text = confOptions[1];

this.textBox3.Text = confOptions[2];

this.textBox4.Text = confOptions[3];

this.textBox5.Text = confOptions[4];

this.textBox6.Text = confOptions[5];

this.textBox7.Text = confOptions[6];

this.textBox8.Text = confOptions[7];

this.textBox9.Text = confOptions[8];

}

this.label7.Text = "phpMyAdmin v" + this.textBox1.Text;

this.label8.Text = "Apache HTTP Server v" + this.textBox2.Text;

this.label9.Text = "MySQL Database Server v" + this.textBox3.Text;

this.label10.Text = "PHP v" + this.textBox4.Text;

}

Can anyone help me?

Nov 16 '05 #2
Well, first of all, try debugging in, see where it is failing.

There are a couple things that *could* be causing problems:
using(StreamReader FStream = new StreamReader("Konfig.ini")) If something else has changed the current directory of your program, this line may fail as it will not be looking in the right
folder for Konfig.ini.
string[] confOptions = new String[9];
string Line;
int i = 0;
while((Line = FStream.ReadLine()) != null)
{
confOptions[i] = Line;
i++;
}
This will fail if your ini file is malformed. Since it is just reading as many lines as possible from the file, i has the potential
to go over (or under) 9. So you could either get null's left in your array, or get an index out of bounds exception.

A different way to it would be:
string contents = FStream.ReadToEnd();
string []confOptions = contents.Split("\r\n");
if (confOptions.Length != 9)
MessageBox.Show("Invalid Konfig.ini!");

This will read in the entire file and put each line of the file into confOptions, which I believe is your intent from the while
loop, but this safely does it such that no unhandled exceptions should occur.

Adam Clauss
ca*****@tamu.edu

-----Original Message-----
From: Sabin Finateanu [mailto:fs****@rdslink.ro]
Sent: Friday, July 23, 2004 5:30 PM
To: ca*****@tamu.edu
Subject: Re: File reading problem

The data from the file doesn't appear in my form. I have this
problem since
I've introduced the procedure.

"Adam Clauss" <ca*****@tamu.edu> wrote in message
news:<Ov*************@TK2MSFTNGP12.phx.gbl>...
Well, I don't see anything particularly wrong, what problem are you

having?

--
Adam Clauss
ca*****@tamu.edu

"Sabin Finateanu" <fs****@rdslink.ro> wrote in message

news:e9*************@TK2MSFTNGP12.phx.gbl... Hi I'm having problem reading a file from my program and I think it's
from a procedure I'm using but I don't see where I'm going wrong. Here is the
code:
public bool AllowUsage()

{

OperatingSystem os = Environment.OSVersion;

AppDomain ad = Thread.GetDomain();

ad.SetPrincipalPolicy(PrincipalPolicy.WindowsPrinc ipal);

WindowsPrincipal wp = (WindowsPrincipal)Thread.CurrentPrincipal;
if(os.Platform == System.PlatformID.Win32NT &&
wp.IsInRole(WindowsBuiltInRole.Administrator) == true)

{

return true;

}

else

{

return false;

}

}

Antd then I call it here:

void MainFormLoad(object sender, System.EventArgs e)

{

if(!this.AllowUsage())

{

MessageBox.Show("You are not an administrator on this system. Program
usage denied.", "ConfigBackup", MessageBoxButtons.OK, MessageBoxIcon.Stop);
this.Close();

}
// Read the Konfig.ini file and store the results

using(StreamReader FStream = new StreamReader("Konfig.ini"))

{

string[] confOptions = new String[9];

string Line;

int i = 0;
while((Line = FStream.ReadLine()) != null)

{

confOptions[i] = Line;

i++;

}

this.textBox1.Text = confOptions[0];

this.textBox2.Text = confOptions[1];

this.textBox3.Text = confOptions[2];

this.textBox4.Text = confOptions[3];

this.textBox5.Text = confOptions[4];

this.textBox6.Text = confOptions[5];

this.textBox7.Text = confOptions[6];

this.textBox8.Text = confOptions[7];

this.textBox9.Text = confOptions[8];

}

this.label7.Text = "phpMyAdmin v" + this.textBox1.Text;

this.label8.Text = "Apache HTTP Server v" + this.textBox2.Text;

this.label9.Text = "MySQL Database Server v" + this.textBox3.Text;

this.label10.Text = "PHP v" + this.textBox4.Text;

}

Can anyone help me?




Nov 16 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: fabrice | last post by:
Hello, I've got trouble reading a text file (event viewer dump) by using the getline() function... After 200 - 300 lines that are read correctly, it suddenly stops reading the rest of the...
8
by: Brandon McCombs | last post by:
This may be the wrong group but I didn't see anything for VC++ so I'm trying here. I have a C++ book by Deitel and Deitel that says I can use fstream File("data.dat", ios::in | ios::out |...
1
by: Need Helps | last post by:
Hello. I'm writing an application that writes to a file a month, day, year, number of comments, then some strings for the comments. So the format for each record would look like:...
0
by: Lokkju | last post by:
I am pretty much lost here - I am trying to create a managed c++ wrapper for this dll, so that I can use it from c#/vb.net, however, it does not conform to any standard style of coding I have seen....
7
by: John Dann | last post by:
I'm trying to read some binary data from a file created by another program. I know the binary file format but can't change or control the format. The binary data is organised such that it should...
0
by: Fabrice | last post by:
Hello, (Alain) Tis is a part of my code to retrieve text from hastable in memory cache, by reading (befor) a resources file. Thanks for your help. /1/ The resources file * I have create a...
2
by: ERingmae | last post by:
Hi, The environment is .NET 2.0, the language is C# and the problem is reading XSD file with xs:redefine section correctly to a XMLDataDocument.DataSet. What I am trying to do: I am trying...
1
AdrianH
by: AdrianH | last post by:
Assumptions I am assuming that you know or are capable of looking up the functions I am to describe here and have some remedial understanding of C programming. FYI Although I have called this...
6
by: efrenba | last post by:
Hi, I came from delphi world and now I'm doing my first steps in C++. I'm using C++builder because its ide is like delphi although I'm trying to avoid the vcl. I need to insert new features...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.