How to create file at runtime?

Asked

Viewed 29 times

0

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

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);

1 answer

0


I don’t know if this will solve your problem, but focusing only on writing 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 the XmlDocument, but also works the way above.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.