Santosh
Santosh

Reputation: 2505

XmlWriter trimming my string

I am trying to return an XML string as a CLOB from Oracle stored procedure to C# string.

Then I am write this string to a file using XmlWriter class.

My code looks like following:

string myString= ((Oracle.ManagedDataAccess.Types.OracleClob)(cmd.Parameters["paramName"].Value)).Value.ToString();
string fileName = DateTime.Now.ToString("yyyyMMddHHmmss");
var stream = new MemoryStream();
var writer = XmlWriter.Create(stream);
writer.WriteRaw(myString);
stream.Position = 0;
var fileStreamResult = File(stream, "application/octet-stream", "ABCD"+fileName+".xml");
return fileStreamResult;

When I checked my CLOB output it returns completely to myString.

When I check my end result, XML file is trimmed at the end.

My string will be huge for ex: Length of 3382563 and more.

Is there any setting for XmlWriter to write the complete string to file.

Thanks in advance.

Upvotes: 0

Views: 209

Answers (2)

SHKVal
SHKVal

Reputation: 13

Encountered the same problem. I guess XmlWriter doesn't have time to flush all it's content into stream. So you should manually call

xmlWriter.Flush();
xmlWriter.Close();

Then problem is gone.

Upvotes: 1

blaze_125
blaze_125

Reputation: 2317

Sounds like all you want to do is grab some string value out of your Database, and write that string value in a text file. The string being xml does not actually force you into using an XML specific class or method unless you want to do XML specific operations, which I do not see in your snippet. Therefore, I suggest you simply grab the string value and spit it out in a file in the easiest way.

string myString = " blah blah blah keep my spaces ";

using (StreamWriter sw = new StreamWriter(@"M:\StackOverflowQuestionsAndAnswers\XMLWriterTrimmingString_45380476\bin\Debug\outputfile.xml"))
{
    sw.Write(myString);
}

Upvotes: 1

Related Questions