NIMA_1981
پنج شنبه 03 شهریور 1390, 01:24 صبح
سلام دوستان
من یک مثال ساده از روی یک کتاب برای ساخت xml نوشتم برنامه اجرا میشه اما هیچ فابلی ساخته نمیشه میشه راهنمایی کنید
این کد کلاس برنامه هست
using System.IO;
using System.Xml.Serialization;
namespace naeimxml
{
public class SerializableData
{
//Save-serialize the object to dick ...
public void Save(String filename) {
//make a temporary filename...
String tempFilename;
tempFilename =filename +".tmp";
//does the file exist?
FileInfo tempFileInfo= new FileInfo (tempFilename);
if (tempFileInfo.Exists)
tempFileInfo.Delete();
//open the file...
FileStream stream=new FileStream (tempFilename ,FileMode.Create,FileAccess.Write );
// save the object
Save(stream);
//close the file...
stream .Close();
//remove the existing data file and rename the temp file...
tempFileInfo.CopyTo (filename,true);
tempFileInfo.Delete();
}
public void Save(Stream stream)
{
//create a serializer...
XmlSerializer serializer = new XmlSerializer(this.GetType());
//save the file...
serializer.Serialize(stream, this);
}
}
}
من یک مثال ساده از روی یک کتاب برای ساخت xml نوشتم برنامه اجرا میشه اما هیچ فابلی ساخته نمیشه میشه راهنمایی کنید
این کد کلاس برنامه هست
using System.IO;
using System.Xml.Serialization;
namespace naeimxml
{
public class SerializableData
{
//Save-serialize the object to dick ...
public void Save(String filename) {
//make a temporary filename...
String tempFilename;
tempFilename =filename +".tmp";
//does the file exist?
FileInfo tempFileInfo= new FileInfo (tempFilename);
if (tempFileInfo.Exists)
tempFileInfo.Delete();
//open the file...
FileStream stream=new FileStream (tempFilename ,FileMode.Create,FileAccess.Write );
// save the object
Save(stream);
//close the file...
stream .Close();
//remove the existing data file and rename the temp file...
tempFileInfo.CopyTo (filename,true);
tempFileInfo.Delete();
}
public void Save(Stream stream)
{
//create a serializer...
XmlSerializer serializer = new XmlSerializer(this.GetType());
//save the file...
serializer.Serialize(stream, this);
}
}
}