10 Eylül 2008 Çarşamba

Dosya yazıp-okuma

1. using System;
2. using System.Collections.Generic;
3. using System.Text;
4. using System.IO;
5. using System.Web.UI.WebControls;
6. using System.Xml;
7.
8. namespace SoruCevap
9. {
10. public class DocumentManager
11. {
12. public static bool WriteObjectToFile(string Path, string oObject,FileMode oMode)
13. {
14. try
15. {
16. using (FileStream fs = new FileStream(Path, oMode))
17. {
18. using (StreamWriter writer = new StreamWriter(fs,Encoding.Unicode))
19. {
20. writer.Write(oObject);
21. writer.Close();
22. }
23. }
24. }
25. catch (Exception)
26. {
27. return false;
28. }
29. return true;
30. }
31. public static bool WriteObjectToFile(string Path, string oObject)
32. {
33. return WriteObjectToFile(Path, oObject, FileMode.Create);
34. }
35.
36. public static string ReadObjectFromFile(string Path)
37. {
38. try
39. {
40. using (FileStream fs = new FileStream(Path, FileMode.Open))
41. {
42. using (StreamReader reader = new StreamReader(fs, Encoding.Unicode))
43. {
44. return reader.ReadToEnd();
45. }
46. }
47. }
48. catch (Exception)
49. {
50.
51. return null;
52. }
53. }
54. }
55. }

Hiç yorum yok: