SirSmart 0 Denunciar post Postado Junho 29, 2009 Galera estou precisando gravar os dados da minha classe em um xml. Mas o arquivo não é gravado em lugar algum e tb não dá erro ... Eis o código: classGravar.Nome = txtNome.Text.Trim(); classGravar.Email = txtEmail.Text.Trim(); classGravar.Tel = txtTelefone.Text.Trim(); classGravar.Pais = cmbPais.SelectedItem.ToString(); classGravar.Estado = cmbEstado.SelectedItem.ToString(); classGravar.Municipio = cmbMunicipio.SelectedItem.ToString(); classGravar.Orgao = txtOrgao.Text.Trim(); classGravar.Cargo = txtCargo.Text.Trim(); //Grava Dados em um xml System.Xml.Serialization.XmlSerializer writer = new System.Xml.Serialization.XmlSerializer(classGravar.GetType()); System.IO.StreamWriter file = new System.IO.StreamWriter("\\Temp/TesteMonitour.xml"); writer.Serialize(file, classGravar); file.Close();Como posso resolver esse problema... Obrigado Compartilhar este post Link para o post Compartilhar em outros sites
quintelab 91 Denunciar post Postado Junho 29, 2009 Alguma coisa tem que acontecer. Ele trava em alguma parte do código? De uma olhada nesta pasta temp. Abraços... Compartilhar este post Link para o post Compartilhar em outros sites
brunofilhorj 0 Denunciar post Postado Junho 29, 2009 Cara, rodei aqui e foi. você tem q se atentar a existência do diretório de do arquivo. segue o codigo um pouco modificado para testes. public class Info { public string Nome { get; set; } public string Email { get; set; } public string Cargo { get; set; } } protected void Page_Load(object sender, EventArgs e) { Info p = new Info(); p.Nome = "Bruno"; p.Email = "bruno@meuemail.com"; p.Cargo = "POGramador"; if (!Directory.Exists("\\Temp")) Directory.CreateDirectory("\\Temp"); //Grava Dados em um xml System.Xml.Serialization.XmlSerializer writer = new System.Xml.Serialization.XmlSerializer(p.GetType()); System.IO.StreamWriter file = new System.IO.StreamWriter("\\Temp/Teste.xml", true); writer.Serialize(file, p); file.Close(); file.Dispose(); } O true no final cria o arquivo se nao existir. System.IO.StreamWriter file = new System.IO.StreamWriter("\\Temp/Teste.xml", true); Compartilhar este post Link para o post Compartilhar em outros sites