I am trying to read the same file twice.
I have been using a FileUpload
to look up the file. I was successful in the first read where I find out how many lines the file have, using the next code in C# ans asp.net:
Stream data_file;
data_file=FileUpload1.PostedFile.InputStream;
string line;
int elements;
StreamReader sr = new StreamReader(data_file);
line = sr.ReadLine();
while (line != null)
{
elements = elements + 1;
line = sr.ReadLine();
}
sr.Close();
With this number I can now create an array of array by setting fist how many elements the array is going to hold. The array this time is going to hold the number from the file something like this:
datafile:
1,1
2,3
arrayL[0][0]=1
arrayL[0][1]=1
arrayL[1][0]=2
arrayL[1][0]=3
so the code to do this is the next:
double [][] dime= new double [elements][];
string[] div;
string line2;
int nn=0;
StreamReader ssr = new StreamReader(data_file);
line2 = ssr.ReadLine();
while (line2 != null)
{
dimen[nn] = new double[2];
for (int m2 = 0; m2 < 2; m2++)
{
div=line2.Split(new Char[] { ' ', ',', '\t' });
dimenc[nn][m2] = Convert.ToDouble(div[m2]);
}
nn=nn+1;
line2 = ssr.ReadLine();
}
ssr.Close();
However, the array says that it is empty but I know if I used the second part of the code in a complete diferrent method/ second button but if it is in the same method it does not work so my question is:
What's wrong? Why the second streamreader is not working?
>? So you can feed your list with your data on the first iteration. This way, you dont need to iterate twice on the same data. A list of list might not be the best structure to use, may be List would fit better. But I think you get the idea.
– NLemay Nov 16 '12 at 16:47