We are update document using openxml programatically. while we start to read file using below code, Exception throws at that time.
This exception only throws when file size is bigger.
using (WordprocessingDocument wdoc = WordprocessingDocument.Open(strPath, true))
using (WordprocessingDocument wordDoc = WordprocessingDocument.Open(m_fileName, true))
{
MainDocumentPart mainPart = wordDoc.MainDocumentPart;
foreach (CustomXmlPart customXmlPart in mainPart.CustomXmlParts)
{
bool exists = false;
using (XmlTextReader xReader = new XmlTextReader(customXmlPart.GetStream(FileMode.Open, FileAccess.Read)))
{
XmlDocument xmlDocument = new XmlDocument();
xReader.MoveToContent();
exists = xReader.NamespaceURI.Equals("urn:TTCProperties:namespace");
if (exists)
{
xmlDocument.Load(xReader);
XmlNodeList n = xmlDocument.GetElementsByTagName("Status");
if (n != null)
{
foreach (XmlNode curr in n)
{
Console.WriteLine(curr.InnerText);
curr.InnerText = "New String";
}
}
StreamReader sr = new StreamReader(customXmlPart.GetStream());
Stream stream = customXmlPart.GetStream();
stream.SetLength(0);
using (StreamWriter ts = new StreamWriter(stream))
ts.Write(xmlDocument.InnerXml);
wordDoc.MainDocumentPart.Document.Save(mainPart);
how can resolve this runtime Exception during file reading