------- Windows Phone 7手機開發、.Net培訓、期待與您交流! -------
這個是很早以前學的了,拿出來分享。
//寫txt檔案 string fileName = System.IO.Path.Combine(Application.StartupPath, @"D:\DBDownload\edit\黑馬.txt"); //以預設編碼將txt裡的內容讀取到緩衝區 System.IO.StreamWriter writer = new System.IO.StreamWriter(fileName, false, System.Text.Encoding.Default); //寫入 foreach (string name in this.txtName.AutoCompleteCustomSource) { writer.WriteLine(name); } //輸出 writer.Flush(); //關閉 writer.Close(); //讀取txt檔案 string fileName = Path.Combine(Application.StartupPath, @"D:\DBDownload\edit\黑馬.txt"); if (File.Exists(fileName)) { System.IO.StreamReader reader = new System.IO.StreamReader(fileName, System.Text.Encoding.Default); string name = reader.ReadLine(); while (name != null) { this.txtName.AutoCompleteCustomSource.Add(name); this.txtName.Items.Add(name); name = reader.ReadLine(); } reader.Close(); }
------- Windows Phone 7手機開發、.Net培訓、期待與您交流! -------