4
I have the following situation, I need to provide an XML file to be viewable in the browser, without the user needing to download the file, I do this by saving the file in a directory and then I send the directory of this file and the browser opens as the example below:
public string getXml(int entradaId)
{
try
{
var entrada = ctx.Entradas.Find(entradaId);
string xml = entrada.Xml;
var uploadPath = Server.MapPath("~/Content/Uploads");
string caminhoArquivo = Path.Combine(@uploadPath, entrada.ChaveNota + "-nfe.xml");
StreamWriter sw = new StreamWriter(caminhoArquivo);
sw.Write(xml);
sw.Flush();
sw.Close();
return "/Content/Uploads/" + entrada.ChaveNota + "-nfe.xml";
}
catch (Exception)
{
return "Xml Sem Entrada";
throw;
}
}
This works, but I believe it is not the right one. Because I end up not deleting the file and this will fill the folder with a while.
I need some way to return this XML for the Browser to open as a file and make the view available as an example.
But without me having to save the physical file.
entrada.Xml
is a string?– Jéf Bueno
@jbueno yes, It would be an XML saved in Sqlserver that returns me as a string.
– Edenilson Bila
Ready then =D
– Jéf Bueno