How to create file at runtime?

0

In my application, I need to convert a string that contains XML to RTF . The way I found to accomplish such a task is with the following code, which uses files instead of strings. So I would need to create a XLT , XSLT , RTF format file during . How can I do this?

string string_xlm = "conteúdo qualquer";
string string_xslt = "conteúdo qualquer";

//criar arquivo doc_xml com conteúdo da string_xlm
//criar arquivo doc_xslt com conteúdo da string_xslt
//criar arquivo doc_rtf vazio

/*----------------------------------------------------*/
XslCompiledTransform xml2rtf = new XslCompiledTransform();
xml2rtf.Load(doc_xslt);
xml2rtf.Transform(doc_xml, doc_rtf);
/*----------------------------------------------------*/

string string_rtf = System.IO.File.ReadAllText(doc_rtf);
    
asked by anonymous 09.05.2018 / 15:06

1 answer

1

I do not know if this will solve your problem, but focusing only on the writing of the file:

Method 1:

System.IO.File.WriteAllText("C:\arquivo.extensao", "conteudo", Encoding.Default);

Method 2:

string rtf = "(conteúdo rtf)";

using (TextWriter tw = new StreamWriter("C:\doc_rtf.rtf",false,Encoding.Default))
{
    tw.Write(rtf);
    tw.Close();
}

For an Xml file, you can still use XmlDocument , but it also works as above.

    
09.05.2018 / 15:14