/// <summary> /// Send an html email from the default from address. /// StripTags is run on html to get an alternative plain text version. /// If ok, return null /// </summary> /// <param name="to"></param> /// <param name="subject"></param> /// <param name="htmlBody"></param> /// <param name="attachments">files will full path, sep by ;</param> public static string SimpleSendHtmlEmail(string to, string subject, string htmlBody, string attachments) { string result = null; if (!String.IsNullOrEmpty(to)) { var envelope = new SendEMail(); string rawbody = htmlBody; string body = ""; if (!rawbody.Contains("<style")) { string styles = "<style type='text/css'>"; styles += "p, ol li{margin:0;padding:0;font-family:Arial, Helvetica, sans-serif;font-size:12px;color:#333333;}"; styles += "h2, h3, h4, h5, h6 {margin:0;padding:0;font-family:Arial, Helvetica, sans-serif;color:#1e3444;}"; styles += "h2 {font-size:14px;}"; styles += "h3 {font-size:13px;}"; styles += "h4 {font-size:12px;}"; styles += "h5 {font-size:15px;}"; styles += "h6 {font-size:11px;color:#666;}"; styles += "a {color:#0097d0;text-decoration:none;}"; styles += "table td {font-family:Arial, Helvetica, sans-serif;font-size:12px;color:#333333;}"; styles += "</style>"; body = styles; } // fix relative links from tinyMCE - may be able to remove this later if (Util.ServerIs() == "LVE" || Util.ServerIs() == "STG") { // you must use assign to a new variable when using replace. else use Regex.Replace(string, searchText, replaceText) body += rawbody.Replace("../../..", Web.BaseUrl); } else { // it's DEV //to = Util.GetNamedSetting("EmailToAddress"); // MN 20110511 this overrides all emails sent from DEV server, which can be annoying - uncomment this temporarily if desired body += rawbody.Replace("../../../../", Web.BaseUrl); } if (!envelope.SendEmail(subject, body, Fmt.StripTags(body), "html", to, to, EmailFromAddress, EmailFromName, attachments)) { result = envelope.errorResult; } } else { throw new Exception("Send mail failed. Email 'to' address blank"); } return(result); }
private string WriteHit(int id, int searchAreaID, int hitNum, double score) { //' display a single item in the search results list DataBlock rsArea, rsHit; string sql, result = ""; string filename, txt; string title, intro, area; DateTime datepub = VB.DateNull; //' if source="file" then //' filename = id //' set fs = server.createobject("scripting.filesystemobject") //' set stream = fs.OpenTextFile(server.mappath(fiVB.lename)) //' txt = stream.ReadAll //' stream.close //' //' title = id //' abstract = VB.left(StripTags(txt),250) //' CustomWriteFileHit fiVB.lename, title, abstract, score //' else // ' source will be a table name // ' find in areas database // 'set rs = db.execute("select * from SearchArea where Table='" & source & "'") rsArea = db.execute("select * from SearchArea where searchAreaID=" + searchAreaID); if (rsArea.GetValue("Tablename") == "file" || VB.IsNull(rsArea.GetValue("Tablename"))) { //set fs = server.createobject("scripting.filesystemobject") id = 1; filename = rsArea.GetValue("Page"); area = rsArea.GetValue("AreaTitle"); title = rsArea.GetValue("PageTitle"); FileSystem stream = FileSystem.OpenTextFile(HttpContext.Current.Server.MapPath(filename)); txt = stream.ReadAll(); txt = Fmt.StripTags(txt); stream.close(); intro = VB.left(txt, 250); //' strip out any breaks if (intro != "") { intro = intro.Replace(VB.crlf, " "); } result += CustomWriteHit(id, title, VB.DateNull, intro, area, filename, hitNum, score, null); } else { sql = GetHitSql(rsArea, id); rsHit = db.execute(sql); if (rsHit.eof() && rsHit.bof()) { //' ID not found //' this is possible but very unlikely //' it could happen if an administrator deletes an article while a user is searching //' just skip it, no need for an error message } else { //'id = rsHit(0) int fieldcount; fieldcount = rsHit.NumberOfColumns; //.Columns.VB.length;//.fields.count title = rsHit.GetValue(1); datepub = rsHit.GetValueDate(2); intro = rsHit.GetValue(3) + ""; if (intro == "" && fieldcount > 4) { intro = rsHit.GetValue(4) + ""; } if (intro == "" && fieldcount > 5) { intro = rsHit.GetValue(5) + ""; } area = rsArea.GetValue("AreaTitle"); pageLink = rsArea.GetValue("Page") + ""; if (pageLink != "") { if (VB.instr(pageLink, "?") != 0) { pageLink = pageLink + id; } else { string reqName = rsArea.GetValue("IDRequestField"); if (reqName == "") { reqName = rsArea.GetValue("IDField"); } pageLink = pageLink + "?" + reqName + "=" + id; } } result += CustomWriteHit(id, title, datepub, intro, area, pageLink, hitNum, score, rsHit); } rsHit.close(); //set rsHit = nothing } rsArea.close(); //set rsArea = nothing return(result); }
public string SearchHTMLFiles(string[] keywords, string originalKeywords) { //dim fs, file, folder, ext, txt, hitstr string hitstr = ""; // Create a reference to the current directory. DirectoryInfo di = new DirectoryInfo(Environment.CurrentDirectory); // Create an array representing the files in the current directory. FileInfo[] fi = di.GetFiles(); Console.WriteLine("The following files exist in the current directory:"); // Print out the names of the files in the current directory. foreach (FileInfo file in fi) { Console.WriteLine(file.Name); //set fs = server.createobject("scripting.filesystemobject"); //set folder = fs.GetFolder(server.mappath(".")); //' current directory //for each file in folder.files string ext = VB.lcase(file.Extension); if (ext == "html" || ext == "htm" || ext == "asp") { //set stream = file.OpenAsTextStream //txt = stream.ReadAll //stream.close string loadPath = HttpContext.Current.Server.MapPath(file.Name); // Open the stream and read it back. FileStream fs = File.Open( loadPath, FileMode.Open, FileAccess.Read, FileShare.Read); StringBuilder sb = new StringBuilder(); if (fs != null) { byte[] b = new byte[1024]; UTF8Encoding temp = new UTF8Encoding(true); while (fs.Read(b, 0, b.Length) > 0) { //fileSource += temp.GetString(b); sb.Append(temp.GetString(b)); } fs.Close(); } string txt = sb.ToString(); if (VB.instr(txt, "CheckUserLogin") == 0) { //' not a members-only page string table = "file"; string id = file.Name; string title = file.Name; string fulltext = Fmt.StripTags(txt); DateTime itemDate = VB.DateNull; double score = CalculateScore(title, fulltext, itemDate, keywords, originalKeywords); string scorestr = VB.right("00" + score, 3) + ":" + id + ":" + table; //' leading zeros to allow alphabetical sort //' append to results string if (score > 0) { hitstr = hitstr + scorestr + " "; } } } } //next return(hitstr); }
private string BuildFileHitString(int searchAreaID, string filename, string title, string[] keywords, string originalKeywords, int sortPosition) { //' returns hit string for a given file search area string hitstr, scorestr; //DataBlock rs; double score; int id; //, fieldNum, maxFieldNum; hitstr = ""; //set fs = server.createobject("scripting.filesystemobject") //set stream = fs.OpenTextFile(server.mappath(fiVB.lename)) //txt = stream.ReadAll //stream.close string loadPath = HttpContext.Current.Server.MapPath(filename); FileStream fs = null; try { // Open the stream and read it back. fs = File.Open( loadPath, FileMode.Open, FileAccess.Read, FileShare.ReadWrite); }catch (Exception) { Logging.eout("Search: Failed to open file [" + loadPath + "] "); } StringBuilder sb = new StringBuilder(); if (fs != null) { byte[] b = new byte[1024]; UTF8Encoding temp = new UTF8Encoding(true); while (fs.Read(b, 0, b.Length) > 0) { //fileSource += temp.GetString(b); sb.Append(temp.GetString(b)); } fs.Close(); } string txt = sb.ToString(); if (VB.instr(txt, "CheckUserLogin") == 0) //then { //' not a members-only page id = 1; string fulltext = Fmt.StripTags(txt); DateTime itemDate = VB.DateNull; score = CalculateScore(title, fulltext, itemDate, keywords, originalKeywords); if (score > 0) { score = score + sortPosition; } scorestr = VB.right("00" + score, 3) + ":" + id + ":" + searchAreaID; // ' leading zeros to allow alphabetical sort //' append to results string if (score > 0) // then { hitstr = hitstr + scorestr + " "; } } return(hitstr); }