Featured post

c# - Usage of Server Side Controls in MVC Frame work -

i using asp.net 4.0 , mvc 2.0 web application. project requiremrnt have use server side control in application not possibl in noraml case. ideally want use adrotator control , datalist control. i saw few samples , references in codepleax mvc controllib howwver found less useful. can tell how utilize theese controls in asp.net application along mvc. note: please provide functionalities related adrotator , datalist controls not equivalent functionalities thanks in advace. mvc pages not use normal .net solution makes use of normal .net components impossible. a normal .net page use event driven solution call different methods service side mvc use actions , view completly different way handle things. also, mvc not use viewstate normal .net controlls require. found article discussing mixing of normal .net , mvc.

c# - Clean approach to finding a folder's parent -


i have piece of code searches folder given starting directory. once folder found need name of it's parent. following piece of code works terribly ugly. have flag, "sessionfound" assist breaking nested foreach loops. following works. hoping eyes on , see if suggestions on how make less verbose , bit more concise.

thanks.

    private void setprojectfolder(string sessionid)         {  //ioc container gives root directory begin search.             string[] supportdirs = directory.getdirectories(applicationcontainer.supportdirectory);             bool sessionfound = false;              foreach (string directory in supportdirs)             {                 if (!sessionfound)                 {                     foreach (string folder in directory.getdirectories(directory))                     {                         if (!sessionfound)                         {                             foreach (string productsubfolder in directory.getdirectories(folder))                             {                                 if (productsubfolder.contains(sessionid))                                 {                                     _productname = directory.getparent(productsubfolder).parent.name;                                     sessionfound = true;                                     break;                                 }                             }                         }                         else                         {                             break;                         }                     }                 }                 else                 {                     break;                 }             }         } 

try this:

private void setprojectfolder(string sessionid)     {         //this simulate contains statement         string searchpattern = string.format("*{0}*", sessionid);         string[] supportdirs = directory.getdirectories(applicationcontainer.supportdirectory, searchpattern);          foreach (string filteredfolder in supportdirs)         {             _productname = directory.getparent(filteredfolder).name;             break;         }     } 

Comments

Popular posts from this blog

c# - Usage of Server Side Controls in MVC Frame work -

cocoa - Nesting arrays into NSDictionary object (Objective-C) -

ios - Very simple iPhone App crashes on UILabel settext -