/*
Copyright (C) Hannon Hill Corporation, hannonhill.com, July 2006
This is a script from hannonhill.com. You will find this and many other
scripts at our website as part of our content management system.
Terms of use:
You are free to use this script as long as the copyright message is kept
intact. However, you may not redistribute, sell or repost it without
our permission. There are no warranties and you use it at your own risk.
*/
using System;
using System.Data;
using System.Configuration;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Xml;
using System.Collections;
using System.Web.Mail;
using System.IO;
public partial class _Default : System.Web.UI.Page
{
private string url = "";
protected void Page_Load(object sender, EventArgs e)
{
string configFileName = Request.Form.Get("_configPage");
string fullPathStart = Request.ServerVariables.Get("PATH_TRANSLATED");
string currentPath = fullPathStart.Substring(0, fullPathStart.LastIndexOf('\\') + 1);
main.Text += "\r\n";
// Opening the config file
XmlTextReader reader = new XmlTextReader(currentPath + configFileName);
// Declare variables
string message = "";
string xmlContentInt = "";
bool sendEmail = false;
bool excelFile = false;
bool cmsFile = false;
ArrayList emails = new ArrayList();
string formName = "";
string xmlContent = "";
string mainTag = "form_information";
bool errorOnPage = false;
// Declare configuration file variables
string fromAddress = "";
string emailHeading = "";
string xmlFileName = "";
string xmlPath = "";
string cascadeAddress = "";
string username = "";
string password = "";
string folder = "";
// Go through each post request and add the information to the message and to the content of the xml file
for (int i = 0; i < Request.Form.Count; i++)
{
string key = Request.Form.GetKey(i);
string keyCut = key.Substring(0, key.Length - 2);
string[] values = Request.Form.GetValues(i);
if ((!key.Equals("emails[]")) && ((key.Length < 12) || (!key.Substring(key.Length - 11, 11).Equals("_REQUIRED[]"))) && (!key.Equals("_result[]")) && (!key.Equals("_formName[]")) && (!key.Equals("_forwardPage")) && (!key.Equals("_configPage")))
{
if (values.Length > 1)
{
message += keyCut;
string lastLetter = key.Substring(key.Length - 1, 1);
if (lastLetter.Equals("s") || lastLetter.Equals("x"))
message += "es: ";
else
message += "s: ";
for (int j = 0; j < values.Length; j++)
{
message += values[j];
if (j < values.Length - 1)
message += ", ";
else
message += "\r\n";
xmlContentInt += "<" + keyCut + ">" + values[j] + "" + keyCut + ">\r\n";
}
}
else
{
message += keyCut + ": " + values[0] + "\r\n";
xmlContentInt += "<" + keyCut + ">" + values[0] + "" + keyCut + ">\r\n";
}
}
else if (key.Equals("_result[]"))
{
for (int j = 0; j < values.Length; j++)
if (values[j].Equals("Send Email(s)"))
sendEmail = true;
else if (values[j].Equals("Save to Excel File"))
excelFile = true;
else if (values[j].Equals("Save to CMS"))
cmsFile = true;
}
else if (key.Equals("emails[]"))
{
for (int j = 0; j < values.Length; j++)
emails.Add(values[j]);
}
else if (key.Equals("_formName[]"))
formName = values[0];
}
xmlContent = "<" + formName + ">\r\n" + xmlContentInt + "" + formName + ">\r\n";
// Read information from the configuration file
while (reader.Read())
{
switch (reader.NodeType)
{
case XmlNodeType.Element:
if (!reader.Name.Equals("system-data-structure"))
{
string value = reader.ReadString();
if (reader.Name.Equals("fromAddress"))
fromAddress = value;
else if (reader.Name.Equals("emailHeading"))
emailHeading = value;
else if (reader.Name.Equals("xmlFileName"))
xmlFileName = value;
else if (reader.Name.Equals("xmlPath"))
xmlPath = value;
else if (reader.Name.Equals("cascadeAddress"))
cascadeAddress = value;
else if (reader.Name.Equals("username"))
username = value;
else if (reader.Name.Equals("password"))
password = value;
else if (reader.Name.Equals("folder"))
folder = value;
}
break;
}
}
url = cascadeAddress + "/ws/services/AssetOperationService?wsdl";
// If the send email option was chosen, send the email
if (sendEmail)
{
string strFrom = fromAddress;
string strSubject = emailHeading;
string strTo = "";
for (int i = 0; i < emails.Count; i++)
strTo += emails[i] + ",";
try
{
System.Net.Mail.SmtpClient mailer = new System.Net.Mail.SmtpClient();
mailer.Host = "66.98.226.18";
mailer.Send(strFrom, strTo, strSubject, message);
}
catch
{
main.Text += "