1
Answer

xmltextwriter

Jacob Bahula

Jacob Bahula

17y
2.8k
1
Hi am trying to use xmltextwriter to create new file but tells me that "Empty path name is not legal."
here is my code

public void SaveXmlDocument(SaveType type)

{

string newFileName = this.fileName;

SaveFileDialog saveFileDialog1 = new SaveFileDialog();

saveFileDialog1.Filter = fileDlgFilter;

if ((type == SaveType.SaveAs) ||

Empty(newFileName))

{

if (!Empty(newFileName))

{

saveFileDialog1.InitialDirectory = Path.GetDirectoryName(newFileName);

saveFileDialog1.FileName = Path.GetFileName(newFileName);

}

else

{

saveFileDialog1.InitialDirectory = fileDlgInitDir;

saveFileDialog1.FileName = newDocName;

}

DialogResult res = saveFileDialog1.ShowDialog(frmOwner);

if (res != DialogResult.OK)

// return false;

newFileName = saveFileDialog1.FileName;

//fileDlgInitDir = new FileInfo(newFileName).DirectoryName;

}

XmlSerializer mySerializer = new XmlSerializer(typeof(DocManager));

// XmlTextWriter myWriter = textwri

FileStream myStream = new FileStream(newFileName,FileMode.Create, FileAccess.Write,FileShare.Read);

XmlTextWriter myWriter = new XmlTextWriter(myStream,Encoding.UTF8);

//myWriter = Formatting.Indented;

mySerializer.Serialize(myStream,type);

myStream.Close();

Answers (1)
Next Recommended Forum