2013-12-17 2 views
0

나는이 ASP 페이지를 가지고 있으며 모든 요청마다 1로 카운트 값을 추가하고 값을 표시하고 텍스트 스트림에 카운트 값을 유지하려는 경우 여기에 내 코드가 있지만 문제는 없습니다. 페이지ASP 페이지 요청 수

<script runat="server"> 

protected void Page_Load(object sender, EventArgs e) 
{ 
    System.IO.StreamWriter sw; 
    System.IO.StreamReader sr ; 
    int count=0; 
    if (!System.IO.File.Exists(@"filepath\ResponsCount.txt")) 
    { 
     sw = new System.IO.StreamWriter(@"filepath\ResponsCount.txt"); 
     sw.WriteLine("count.ToString()"); 
    } 

    else 
    { 
     sr = new System.IO.StreamReader(@"filepath\ResponsCount.txt"); 
     count = int.Parse(sr.ReadLine()); 
     count++; 
     sw = new System.IO.StreamWriter(@"filepath\ResponsCount.txt"); 
     sw.WriteLine(count.ToString()); 
    } 
    Label2.Text = count.ToString(); 
} 
</script> 
+0

스트림 작성기를 닫지 않는 것 같습니다. .... sw.Close();이어야합니다. –

답변

0

를로드 한 후 내 txt 파일 나는

sw.Close(); 

당신이 파일에 기록 때 당신이해야 할 일입니다 ... 당신은 StreamWriter를 폐쇄 표시되지 않습니다. 그러면 모든 내용이 기록중인 파일로 플러시되고 마지막으로 올바르게 닫힙니다.