Click here to Skip to main content
15,905,967 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
hi,

i have a filename file001.mmgr of string[,] type how can i display the filename in label in form load

What I have tried:

int count = 0;
          if (resp!= "")
          {
              XmlDocument readDoc = new XmlDocument();
              readDoc.LoadXml(resp);
              count = readDoc.SelectNodes("college/sno").Count;
              filename = new string[count, 1];
              // alternately, _doc.Load( _strFilename); to read from a file.
              XmlNodeList xfile_name = readDoc.GetElementsByTagName("file_name");

              for (i = 0; i < count; i++)
              {
                  filename[i, 0] = xfile_name[i].InnerText;

              }
              //lbldssFilename.Text = filename[i].ToString();
              string[,] dfilename = filename;
              lbldssFilename.Text = dfilename.ToString();
          }
          else
          {
              string[,] a = new string[1, 0];
          }
      }
Posted
Updated 12-Jul-18 18:10pm

1 solution

Based on what you have posted, dfilename/filename is a MultiDimensional Array / Object and .ToString() will print out the name of the Object. The easiest way is to use Linq to select all the file names and then use the string.join method to display all the items in comma separator.

C#
using System;
using System.Linq;

public class Program
{
	public static void Main()
	{
		var filenames = new string[2, 2];
		filenames[0, 0] = "abcd00";
		filenames[0, 1] = "abcd01";
		filenames[1, 0] = "abcd10";
		filenames[1, 1] = "abcd11";
		
		string[,] dfilename = filenames;
		
		var fName = from string filename in dfilename
                     select filename;
		
		Console.WriteLine("dfilename: " + string.Join(",", fName));  
	}
}

Output:
dfilename: abcd00,abcd01,abcd10,abcd11
 
Share this answer
 
Comments
Member 13846964 13-Jul-18 1:26am    
@Bryian thank you for your suggestion i will try it, but i need to display file name in label how can i do it..

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900