In the past, xml needs to be exported as the fusionChats data source in a project. xml does not seem to have a function to create a new file, so a method is handwritten.
Code
Using System. Text;
Using System. IO;
Using System. Xml;
Namespace BIS. Service
{
Public class FileCommand
{
Public static readonly string DataPath = AppDomain. CurrentDomain. BaseDirectory + @ "Data \";
/// <Summary>
/// Write an object
/// </Summary>
/// <Param name = "FileName"> </param>
/// <Param name = "Content"> </param>
/// <Returns> </returns>
Public static bool CreateXML (string FileName, string Content)
{
Bool isSuccess = false;
// FileName + = ". xml ";
FileStream objFileStream = null;
StreamWriter objStreamWriter = null;
Try
{
// Determine whether the file already exists. If yes, overwrite the file.
If (File. Exists (DataPath + FileName ))
{
File. Delete (DataPath + FileName );
}
XmlDocument xml = new XmlDocument ();
ObjFileStream = new FileStream (DataPath + FileName, FileMode. Append, FileAccess. Write );
ObjStreamWriter = new StreamWriter (objFileStream, Encoding. Default );
ObjStreamWriter. WriteLine ("<? Xml version = \ "1.0 \" encoding = \ "UTF-8 \"?> ");
ObjStreamWriter. WriteLine (Content); // write the string to the file.
IsSuccess = true;
}
Catch (Exception e)
{
// Throw new Exception ("Export failed ");
}
Finally
{
If (objStreamWriter! = Null)
{
ObjStreamWriter. Flush ();
ObjStreamWriter. Close ();
}
}
Return isSuccess;
}
}
}