Srinivas M

Srinivas M

  • 1.3k
  • 435
  • 28.8k

How to resume StreamReader to start reading from continue.

Feb 21 2019 1:31 AM
Actually I have an application in that I'm reading Stream data using StreamReader line to line and Inserting into Data Base If any Case Internet Connection Closed or system shutdown then i want to resume Stramreader don't want to read from starting Position of the Stream.
  1. Stream stream = res.GetResponseStream();  
  2. using (StreamReader sr = new StreamReader(stream))  
  3. {  
  4. int i = 1;  
  5. int j = 0;  
  6. string ss = "";  
  7. List<string> strContent = new List<string>();  
  8. while (i > j)  
  9. {  
  10. StringBuilder sb = new StringBuilder();  
  11. while (!sr.EndOfStream)  
  12. {  
  13. string line = sr.ReadLine();  
  14. ss = ss + line;  
  15. i++;  
  16. if (line.Equals("</record>"))  
  17. {  
  18. if ((sr.EndOfStream))  
  19. {  
  20. }  
  21. else  
  22. {  
  23. ss = ss + "</records>";  
  24. }  
  25. var mySourceDoc = new XmlDocument();  
  26. //load the file from the stream  
  27. mySourceDoc.LoadXml(ss);  
  28. //XmlNode nd = mySourceDoc.DocumentElement.SelectSingleNode("//records");  
  29. XmlDocument xmlAPDP = new XmlDocument();  
  30. xmlAPDP.LoadXml(ss);  
  31. XmlNodeReader xmlReader = new XmlNodeReader(xmlAPDP);  
  32. DataSet dataSet = new DataSet();  
  33. dataSet.ReadXml(xmlReader);  
  34. string sds = WriteXML(dataSet);  
  35. ss = "";  
  36. ss = "<?xml version='1.0' encoding='utf-8'?><records xmlns:xsi='http://www.w3.org/2001/XMLSchema-instance' xsi:noNamespaceSchemaLocation ='premium-world-check.xsd'>";  
  37. j = i;  
  38. i = j + 1;  
  39. break;  
  40. }  
  41. }  
  42. if ((sr.EndOfStream))  
  43. {  
  44. break;  
  45. }  
  46. }  
  47. }  

Answers (2)