public static SmtpServerAddressCollection Load() { String filename = EnsureUserFile(); FileInfo thefile=new FileInfo(filename); if (!thefile.Exists) { throw new ApplicationException(String.Format("Can't open {0}", filename)); } TextReader reader = null; SmtpServerAddressCollection coll=new SmtpServerAddressCollection(); try { reader=new StreamReader(filename); XmlSerializer serializer = coll.GetXmlSerializer(); coll=(SmtpServerAddressCollection) serializer.Deserialize(reader); } finally { if (reader!=null) { reader.Close(); } } return coll; }
private bool SaveSmtpServersToFile() { DataTable dt=(DataTable) dataGrid1.DataSource; SmtpServerAddressCollection coll=new SmtpServerAddressCollection(); try { foreach (DataRow row in dt.Rows) { int port=25; if (!row.IsNull("port")) { port=Convert.ToInt32(row["port"]); } coll.Add(new SmtpServerAddress((String) row["hostname"], port)); } coll.Save(); return true; } catch (Exception ex) { ShowErrorDialog(ex.Message); return false; } }
private void LoadSmtpServers() { //_smtpservers=new SmtpServerAddressCollection(); //_smtpservers.Load(GetSmtpServerConfigFile()); _smtpservers=SmtpServerAddressCollection.Load(); }