퇴근5분전


SBS 전자 자막의뢰 Web사이트 구축하면서 
로그파일관리 페이지를 만들면서 작성했던 부분임.
간단한 재귀로 하위 디렉토리들을 추가 하게 됨. 

 /// <summary>
 /// 폴더 이하 파일&디렉토리 검색해서 트리뷰에 추가하는 재귀 함수
 /// </summary>
 /// <param name="sDirectoryName"></param>
 /// <returns></returns>
 private TreeNode GetTreeNodes(string sDirectoryName, string rootPath)
 {

  string[] fileNames = Directory.GetFiles(sDirectoryName);
  string[] directoryNames = Directory.GetDirectories(sDirectoryName);

  int fileCount = fileNames.Length;

  //TreeNode root = new TreeNode(sDirectoryName.Replace(rootPath, ""));
  TreeNode root = new TreeNode(string.Format("{0} : {1}", sDirectoryName.Replace(rootPath, ""), fileCount), sDirectoryName.Replace(rootPath, ""));

  foreach (string dir in directoryNames)
  {
   if( dir.Replace(sDirectoryName+"\\","") == ".svn") continue;
   TreeNode tnode = GetTreeNodes(dir, sDirectoryName+@"\");    // 재귀!
   tnode.SelectAction = TreeNodeSelectAction.Select;      // 포스트백 발생하지 않게 됨.
   root.ChildNodes.Add(tnode);
  }
  //foreach (string fileName in fileNames)
  //{
  //    TreeNode tnode2 = new TreeNode(fileName.Replace(sDirectoryName + "\\", ""));
  //    tnode2.SelectAction = TreeNodeSelectAction.None;
  //    root.ChildNodes.Add(tnode2);
  //}
  root.SelectAction = TreeNodeSelectAction.Select;
  return root;
 }




Xml을 조작하기엔     XmlDocument 로 가지고 놀기 편하였다.


XmlDocument xDoc = new XmlDocument();
xDoc.Load : 읽어오기
xDoc.Save : 저장하기
XmlNodeList  xList  = xDoc.GetElementsByTagName("태그명");
xDoc["태그명"]


< XmlElement1   XmlAttribute1  XmlAttribute2 ... >
< XmlElement2   XmlAttribute1  XmlAttribute2 ... />
< XmlElement3   XmlAttribute1  XmlAttribute2 XmlAttribute3 ... />
</XmlElement1>

간단하게 위처럼 XmlElement로 접근이 쉽다.

간단한 설정 데이타나, 메세지 전달이 필요할때 변환이 쉽더라.


'# 2) .Net ( Vs 2005 ) > 기타' 카테고리의 다른 글

PWD 암호화 객체.  (0) 2009.05.08
인터페이스와델리게이트조합1  (2) 2009.05.08
DB로컬 연결시 문구  (0) 2009.05.02
큐브~  (0) 2009.05.02
DB Connection Factory  (0) 2009.05.01



SMS 입력받고 데이타 길이 체크하는 처리부분.

 public partial class Form1 : Form
    {
        bool char_ASCIICODE = false;

        public Form1()
        {
            InitializeComponent();
        }

        private void textBox1_TextChanged(object sender, EventArgs e)
        {           
            int length = Encoding.Default.GetBytes(this.textBox1.Text).Length;

            if (length > 80)
            {
                this.textBox1.Text = this.textBox1.Text.Substring(0, this.textBox1.TextLength - (char_ASCIICODE ? 1 : 2));
                char_ASCIICODE = false;
                this.textBox1.Select(this.textBox1.TextLength, 0);
                return;
            }
            length = Encoding.Default.GetBytes(this.textBox1.Text).Length;
            this.label1.Text = string.Format("{0}/80", length);
        }
       
        private void textBox1_KeyPress(object sender, KeyPressEventArgs e)
        {
            if (e.KeyChar < 256)
                char_ASCIICODE = true;
            else
                char_ASCIICODE = true;
        }   
}

그리 어려운 코드가 아니라 주석도 없다!

'# 2) .Net ( Vs 2005 ) > WinForm' 카테고리의 다른 글

폼간 데이타 전달  (0) 2009.05.02
그리드뷰 컨트롤  (0) 2009.05.02
Excel Export  (0) 2009.05.01
판넬 슬라이드 애니메이션  (0) 2009.05.01
데이타베이스 브라우져 ver3  (0) 2009.05.01