Publicdictionary<string,string>getsourcediskselements (String section) { section="["+Section ; Dictionary<string,string> Keytovalue =Newdictionary<string,string>(); //Open the file stream and start reading the file using(StreamReader sin =NewStreamReader (NewFileStream (Path, FileMode.Open, FileAccess.Read, FileShare.Read))) { for(String str = sin.) ReadLine (); str! =NULL; str =sin. ReadLine ()) {if(str. Trim (). StartsWith (section, stringcomparison.ordinalignorecase))//some section has comment. { for(str = sin.) ReadLine (); str! =NULL&&!str. Trim (). StartsWith ("["); str = sin. ReadLine ())//loop for Get string, until to next, or end of file. { if(! String.IsNullOrEmpty (str. Trim ()) &&!str. Trim (). StartsWith (";"))//Drop the comment line and empty line.//Remove the restriction of name-value, because there is no = case. 20100309.str. Contains (' = ') && only get the name-value pair line.{string[] keyvalues= str. Split ('='); if(section. Equals ("[SourceDisksNames")) { string[] Nocommentvalues = keyvalues[1]. Split (';'); stringRealvalue = nocommentvalues[0]. Trim (); String[] Sourcediskcfg= Realvalue.split (',');//Disk-description[,[tag-or-cab-file],[unused],[path],[flags][,tag-file]] (tag-file:windows XP and later versions of Windows)String Diskpath =String.Empty; if(Sourcediskcfg.length >3) Diskpath= sourcediskcfg[3]. Trim (); if(Diskpath. StartsWith ("\"")) Diskpath=removequotes (Diskpath); if(! String.IsNullOrEmpty (Diskpath) && Diskpath. StartsWith (".")) Diskpath= Diskpath. Substring (Diskpath. IndexOf ('\\')); //20150112 if(! String.IsNullOrEmpty (Diskpath) &&!diskpath. StartsWith ("\\")) Diskpath="\\"+Diskpath; Keytovalue.add (keyvalues[0]. Trim (), Diskpath); } Else { string[] Nocommentvalues = keyvalues[1]. Split (';'); stringRealvalue = nocommentvalues[0]. Trim (); Keytovalue.add (keyvalues[0]. Trim (), realvalue); } } } Break; } } } returnKeytovalue; }View Code
C # loops through file streams, reads by rows