jasonsalas
IS-IT--Management
Hi everyone,
I'm developing a custom control in which I sift through the contents of an XML document and populate a jagged array (actually, it's an array with a variable number of elements, but always has 2 values for each element).
I'm trying to loop through the array, but I keep getting the error message: "Cannot apply indexing with [] to an expression of type 'System.Array' when trying to access the values with my code. It looks cut-and-dry (or so I thought), but it won't work.
Here's my code:
private Array GetFiles(string fileProperty)
{
FileStream fs = new FileStream(fileProperty,FileMode.Open,FileAccess.Read);
StreamReader sr = new StreamReader(fs);
DataSet ds = new DataSet();
ds.ReadXml(sr);
fs.Close();
DataTable table = ds.Tables[0];
DataRow[] rows = table.Select();
// POPULATE THE ARRAY HERE
string[][] arrSubmissions = new string[rows.Length][];
for(int i=0;i<rows.Length;i++)
{
arrSubmissions = new string[2] { rows["link"].ToString(),rows["title"].ToString() };
}
return arrSubmissions;
}
protected override void Render(HtmlTextWriter writer)
{
// call the private helper method
Array sl = GetFiles(DataFile);
for(int i=0;i<sl.Length;i++)
{
for(int j=0;j<sl.Length;j++)
{
// THIS LINE CAUSES THE ERROR
writer.Write("{0},sl[j]);
}
}
}
Any ideas?
I'm developing a custom control in which I sift through the contents of an XML document and populate a jagged array (actually, it's an array with a variable number of elements, but always has 2 values for each element).
I'm trying to loop through the array, but I keep getting the error message: "Cannot apply indexing with [] to an expression of type 'System.Array' when trying to access the values with my code. It looks cut-and-dry (or so I thought), but it won't work.
Here's my code:
private Array GetFiles(string fileProperty)
{
FileStream fs = new FileStream(fileProperty,FileMode.Open,FileAccess.Read);
StreamReader sr = new StreamReader(fs);
DataSet ds = new DataSet();
ds.ReadXml(sr);
fs.Close();
DataTable table = ds.Tables[0];
DataRow[] rows = table.Select();
// POPULATE THE ARRAY HERE
string[][] arrSubmissions = new string[rows.Length][];
for(int i=0;i<rows.Length;i++)
{
arrSubmissions = new string[2] { rows["link"].ToString(),rows["title"].ToString() };
}
return arrSubmissions;
}
protected override void Render(HtmlTextWriter writer)
{
// call the private helper method
Array sl = GetFiles(DataFile);
for(int i=0;i<sl.Length;i++)
{
for(int j=0;j<sl.Length;j++)
{
// THIS LINE CAUSES THE ERROR
writer.Write("{0},sl[j]);
}
}
}
Any ideas?