110,499
社区成员
发帖
与我相关
我的任务
分享
public static bool SerializeInput(Input input, string path)
{
try
{
XmlSerializer formatter = new XmlSerializer(typeof(Input));
Stream stream = new FileStream(path, FileMode.Create, FileAccess.ReadWrite, FileShare.None);
formatter.Serialize(stream, input);
stream.Close();
}
catch
{
return false;
}
return true;
}
public static Input DeserializeInput(string path)
{
XmlSerializer fomatter = new XmlSerializer(typeof(Input));
Stream stream = new FileStream(path, FileMode.Open, FileAccess.Read, FileShare.None);
stream.Seek(0, SeekOrigin.Begin);
Input input = (Input)fomatter.Deserialize(stream);
stream.Close();
return input;
}
public partial class Input
{
private string ed1 = string.Empty;
public string ExcelDir1
{
set
{
ed1 = value;
}
get
{
return ed1;
}
}
private string ed2 = string.Empty;
public string ExcelDir2
{
set { ed2 = value; }
get { return ed2; }
}
private string ed3 = string.Empty;
public string ExcelDir3
{
set { ed3 = value; }
get { return ed3; }
}
private string ed4 = string.Empty;
public string ExcelDir4
{
set
{
ed4 = value;
}
get
{
return ed4;
}
}
private string ed5 = string.Empty;
public string ExcelDir5
{
set { ed5 = value; }
get { return ed5; }
}
private string cd1 = string.Empty;
public string ConfigDir1
{
set
{
cd1 = value;
}
get
{
return cd1;
}
}
private string cd2 = string.Empty;
public string ConfigDir2
{
set { cd2 = value; }
get { return cd2; }
}
private string cd3 = string.Empty;
public string ConfigDir3
{
set { cd3 = value; }
get { return cd3; }
}
private string cd4 = string.Empty;
public string ConfigDir4
{
set
{
cd4 = value;
}
get
{
return cd4;
}
}
private string cd5 = string.Empty;
public string ConfigDir5
{
set { cd5 = value; }
get { return cd5; }
}
}
#region 创建保存保存信息的临时XML
/// <summary>
/// 创建保存保存信息的临时XML
/// </summary>
/// <param name="strSaveName"></param>
/// <param name="strSavePath"></param>
/// <param name="strNotSaveName"></param>
/// <param name="strNotSavePath"></param>
public void CreateXML(string strSaveName,string strSavePath,string strNotSaveName,string strNotSavePath)
{
string[] arrSaveName = strSaveName.Split('$');
string[] arrSavePath = strSavePath.Split('$');
string[] arrNotSaveName = null;
string[] arrNotSavePath = null;
int iSaveCount = strSaveName.Split('$').Length-1;
int iNotSaveCount = 0;
XmlDocument oXml = new XmlDocument();
XmlDeclaration oDeclare = oXml.CreateXmlDeclaration("1.0", "GB2312", null);
oXml.AppendChild(oDeclare);
//创建一个根节点(一级)
XmlElement oRoot = oXml.CreateElement("SaveInfo");
oXml.AppendChild(oRoot);
//创建保存图片信息节点
XmlNode oNodeSaveName = oXml.CreateElement("SaveName");
XmlNode oNodeSavePath = oXml.CreateElement("SavePath");
XmlNode oNotSaveName = oXml.CreateElement("NotSaveName");
XmlNode oNotSavePath = oXml.CreateElement("NotSavePath");
//创建已经保存信息
try
{
for(int i=0 ; i<iSaveCount ; i++)
{
XmlElement oElementName= oXml.CreateElement("Name"+i.ToString());
oElementName.SetAttribute("Name", "NameC"+i.ToString());
oElementName.SetAttribute("ID", "NamePC"+i.ToString());
oElementName.InnerText = "@"+arrSaveName[i];
oNodeSaveName.AppendChild(oElementName);
XmlElement oElementPath= oXml.CreateElement("Path"+i.ToString());
oElementPath.SetAttribute("Name", "PathC"+i.ToString());
oElementPath.SetAttribute("ID", "PathPC"+i.ToString());
oElementPath.InnerText = arrSavePath[i].Insert(arrSavePath[i].LastIndexOf("\\")+1,"@");
oNodeSavePath.AppendChild(oElementPath);
}
}
catch(Exception e)
{
string strError = e.Message;
}
oRoot.AppendChild(oNodeSaveName);
oRoot.AppendChild(oNodeSavePath);
if(strNotSaveName != string.Empty)
{
arrNotSaveName = strNotSaveName.Split('$');
arrNotSavePath = strNotSavePath.Split('$');
iNotSaveCount = arrNotSaveName.Length-1;
try
{
for(int i=0 ; i<iNotSaveCount ; i++)
{
XmlElement oElementNotName= oXml.CreateElement("NotName"+i.ToString());
oElementNotName.SetAttribute("Name", "NotNameC"+i.ToString());
oElementNotName.SetAttribute("ID", "NotNamePC"+i.ToString());
oElementNotName.InnerText = "@"+arrNotSaveName[i];
oNotSaveName.AppendChild(oElementNotName);
XmlElement oElementNotPath= oXml.CreateElement("NotPath"+i.ToString());
oElementNotPath.SetAttribute("Name", "NotPathC"+i.ToString());
oElementNotPath.SetAttribute("ID", "NotPathPC"+i.ToString());
oElementNotPath.InnerText = arrNotSavePath[i].Insert(arrNotSavePath[i].LastIndexOf("\\")+1,"@");
oNotSavePath.AppendChild(oElementNotPath);
}
oRoot.AppendChild(oNotSaveName);
oRoot.AppendChild(oNotSavePath);
}
catch(Exception e)
{
string str = e.Message;
}
}
try
{
string strXMLPath = HttpContext.Current.Server.MapPath("../Plsctp/")+"Temp.xml";
oXml.Save(strXMLPath);
Console.Write(oXml.OuterXml);
}
catch(Exception e)
{
string str = e.Message;
}
}
#endregion