private void button1_Click(object sender, System.EventArgs e)
{
saveFileDialog1.Filter = "xml 文件|*.xml";//设置打开对话框的文件过滤条件
saveFileDialog1.Title = "保存成 xml 文件";//设置打开对话框的标题
saveFileDialog1.FileName="";
saveFileDialog1.ShowDialog();//打开对话框
if(saveFileDialog1.FileName != "")//检测用户是否输入了保存文件名
{
mXmlDoc.Save(saveFileDialog1.FileName);//用私有对象mXmlDoc保存文件,mXmlDoc在前面声明过
MessageBox.Show("保存成功");
}
}
/// <summary>
/// 把加载的xml文件转换为Office文件
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void button2_Click(object sender, System.EventArgs e)
{
///从私有对象dox里选取me节点这里的一些对xml对象的操作详细说明可以参考msdn以获取更多信息
XmlNode node=doc.DocumentElement.SelectSingleNode("me") ;
XmlElement ele=(XmlElement)node;//获取一个xml元素
string pic=ele.GetAttribute ("aa");//获取ele元素的aa属性并报讯在一个临时字符串变量pic
byte[] bytes=Convert.FromBase64String (pic);//声明一个byte[]用来存放Base64解码转换过来的数据流
///从保存对话框里获取文件保存地址
saveFileDialog1.Filter = "Office Documents(*.doc, *.xls, *.ppt)|*.doc;*.xls;*.ppt";
saveFileDialog1.Title = "保存成 office 文件";
saveFileDialog1.FileName="";
saveFileDialog1.ShowDialog();
if(saveFileDialog1.FileName != "")
{
//创建文件流并保存
FileStream outfile=new System.IO .FileStream (saveFileDialog1.FileName,System.IO.FileMode.CreateNew);
outfile.Write(bytes,0,(int)bytes.Length );
MessageBox.Show("保存成功");
}
}
/// <summary>
/// 加载窗口时的一些初始化行为
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
public void Form1_Load(object sender, System.EventArgs e)
{
MessageBox.Show("欢迎使用蛙蛙牌文档转换器");
}
/// <summary>
/// 卸载窗体时把临时变量全部释放
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
public void Form1_Closed(object sender, System.EventArgs e)
{
mXmlDoc=null;
doc=null;
}
/// <summary>
/// 加载office文件并编码序列花为一个XmlDocument变量
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void button3_Click(object sender, System.EventArgs e)
{
string strFileName;
openFileDialog1.Filter = "Office Documents(*.doc, *.xls, *.ppt)|*.doc;*.xls;*.ppt" ;
openFileDialog1.FilterIndex = 1;
openFileDialog1.FileName = "";
openFileDialog1.ShowDialog();
strFileName = openFileDialog1.FileName;
if(strFileName.Length != 0)
{
System.IO.FileStream inFile=new FileStream(strFileName,System.IO.FileMode.Open,System.IO.FileAccess.Read);
byte[] binaryData=new byte [inFile.Length];
inFile.Read(binaryData, 0,(int)inFile.Length);
string mStr=Convert.ToBase64String(binaryData);
string hh=mStr;
mXmlDoc=new System.Xml.XmlDocument();
mStr=string.Format ("<wawa><me aa=\"{0}\"/></wawa>",mStr);
mXmlDoc.LoadXml( mStr);
MessageBox.Show("加载成功");
}
}
/// <summary>
/// 加载xml文件到私有对象dox
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void button4_Click(object sender, System.EventArgs e)
{
string strFileName;
openFileDialog1.Filter = "xml 文件|*.xml" ;
openFileDialog1.FilterIndex = 1;
openFileDialog1.FileName = "";
openFileDialog1.ShowDialog();
strFileName = openFileDialog1.FileName;
///If the user does not cancel, open the document.
if(strFileName.Length != 0)
{
doc=new XmlDocument();
doc.Load(strFileName);
MessageBox.Show("加载成功");
}
}
}
}
{
saveFileDialog1.Filter = "xml 文件|*.xml";//设置打开对话框的文件过滤条件
saveFileDialog1.Title = "保存成 xml 文件";//设置打开对话框的标题
saveFileDialog1.FileName="";
saveFileDialog1.ShowDialog();//打开对话框
if(saveFileDialog1.FileName != "")//检测用户是否输入了保存文件名
{
mXmlDoc.Save(saveFileDialog1.FileName);//用私有对象mXmlDoc保存文件,mXmlDoc在前面声明过
MessageBox.Show("保存成功");
}
}
/// <summary>
/// 把加载的xml文件转换为Office文件
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void button2_Click(object sender, System.EventArgs e)
{
///从私有对象dox里选取me节点这里的一些对xml对象的操作详细说明可以参考msdn以获取更多信息
XmlNode node=doc.DocumentElement.SelectSingleNode("me") ;
XmlElement ele=(XmlElement)node;//获取一个xml元素
string pic=ele.GetAttribute ("aa");//获取ele元素的aa属性并报讯在一个临时字符串变量pic
byte[] bytes=Convert.FromBase64String (pic);//声明一个byte[]用来存放Base64解码转换过来的数据流
///从保存对话框里获取文件保存地址
saveFileDialog1.Filter = "Office Documents(*.doc, *.xls, *.ppt)|*.doc;*.xls;*.ppt";
saveFileDialog1.Title = "保存成 office 文件";
saveFileDialog1.FileName="";
saveFileDialog1.ShowDialog();
if(saveFileDialog1.FileName != "")
{
//创建文件流并保存
FileStream outfile=new System.IO .FileStream (saveFileDialog1.FileName,System.IO.FileMode.CreateNew);
outfile.Write(bytes,0,(int)bytes.Length );
MessageBox.Show("保存成功");
}
}
/// <summary>
/// 加载窗口时的一些初始化行为
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
public void Form1_Load(object sender, System.EventArgs e)
{
MessageBox.Show("欢迎使用蛙蛙牌文档转换器");
}
/// <summary>
/// 卸载窗体时把临时变量全部释放
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
public void Form1_Closed(object sender, System.EventArgs e)
{
mXmlDoc=null;
doc=null;
}
/// <summary>
/// 加载office文件并编码序列花为一个XmlDocument变量
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void button3_Click(object sender, System.EventArgs e)
{
string strFileName;
openFileDialog1.Filter = "Office Documents(*.doc, *.xls, *.ppt)|*.doc;*.xls;*.ppt" ;
openFileDialog1.FilterIndex = 1;
openFileDialog1.FileName = "";
openFileDialog1.ShowDialog();
strFileName = openFileDialog1.FileName;
if(strFileName.Length != 0)
{
System.IO.FileStream inFile=new FileStream(strFileName,System.IO.FileMode.Open,System.IO.FileAccess.Read);
byte[] binaryData=new byte [inFile.Length];
inFile.Read(binaryData, 0,(int)inFile.Length);
string mStr=Convert.ToBase64String(binaryData);
string hh=mStr;
mXmlDoc=new System.Xml.XmlDocument();
mStr=string.Format ("<wawa><me aa=\"{0}\"/></wawa>",mStr);
mXmlDoc.LoadXml( mStr);
MessageBox.Show("加载成功");
}
}
/// <summary>
/// 加载xml文件到私有对象dox
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void button4_Click(object sender, System.EventArgs e)
{
string strFileName;
openFileDialog1.Filter = "xml 文件|*.xml" ;
openFileDialog1.FilterIndex = 1;
openFileDialog1.FileName = "";
openFileDialog1.ShowDialog();
strFileName = openFileDialog1.FileName;
///If the user does not cancel, open the document.
if(strFileName.Length != 0)
{
doc=new XmlDocument();
doc.Load(strFileName);
MessageBox.Show("加载成功");
}
}
}
}
再有就是反项操作了