/// <summary> /// </summary> public static bool ExecuteQueryDict(string dbConnStr, string sql, out Dictionary <string, string> dict, out string msg) { dict = new Dictionary <string, string>(); msg = ""; try { using (var conn = new SqlConnection(dbConnStr)) { conn.Open(); using (var cmd = new SqlCommand(sql, conn)) { using (var rdr = cmd.ExecuteReader()) { while (rdr.Read()) { dict.Add(GenUtil.SafeTrim(rdr[0]), GenUtil.SafeTrim(rdr[1])); } } } } } catch (Exception ex) { dict = new Dictionary <string, string>(); msg = ex.ToString(); } return(msg == ""); }
/// <summary> /// </summary> public static bool ExecuteQueryObj(string dbConnStr, string sql, out string obj, out string msg) { obj = ""; msg = ""; try { using (var conn = new SqlConnection(dbConnStr)) { conn.Open(); using (var cmd = new SqlCommand(sql, conn)) { using (var rdr = cmd.ExecuteReader()) { while (rdr.Read()) { obj = GenUtil.SafeTrim(rdr[0]); break; } } } } } catch (Exception ex) { obj = ""; msg = ex.ToString(); } return(msg == ""); }
/// <summary> /// </summary> public static bool CheckInSPFile(SpConnectionManager spConnection, Guid listId, string fileServerRelUrl, string comment, CheckinType checkinType, out string msg) { msg = ""; try { using (var ctx = spConnection.GetContext()) { var file = ctx.Web.GetFileByServerRelativeUrl(fileServerRelUrl); ctx.Load(file, f => f.Name, f => f.ListItemAllFields, f => f.ServerRelativeUrl); ctx.ExecuteQuery(); file.CheckIn(GenUtil.SafeTrim(comment), checkinType); ctx.ExecuteQuery(); } } catch (Exception ex) { msg = SHOW_FULL_ERRORS ? ex.ToString() : ex.Message; } return(msg == ""); }
/// <summary> /// </summary> public static List <string> ConvertStringToList(string str) { var lst = new List <string>(); // normalize delimiters, shoul be ";" str = GenUtil.SafeTrim(str).Replace(",", ";"); return(ConvertStringToList(str, ";")); }
/// <summary> /// </summary> public static List <string> ConvertStringToList(string str, string delimiter) { var lst = new List <string>(); str = GenUtil.SafeTrim(str); if (str.Contains(delimiter)) { lst.AddRange(str.Split(new string[] { delimiter }, StringSplitOptions.None)); } else { lst.Add(str); } return(lst.Where(x => x.Trim().Length > 0).Select(x => x.Trim()).Distinct().ToList()); }
/// <summary> /// </summary> public static bool GetRegStuff(out string alldata, out string msg) { alldata = ""; msg = ""; try { var key = Registry.CurrentUser.OpenSubKey("Software"); var appKey = key.OpenSubKey(REG_KEY_APP_NAME); if (appKey != null) { alldata = GenUtil.SafeTrim(appKey.GetValue(REG_KEY_VALUE)); } } catch (Exception ex) { msg = "Registry read error: " + ex.Message; } return(msg == ""); }
/// <summary> /// </summary> public static bool SaveRegStuff(string alldata, out string msg) { msg = ""; try { var key = Registry.CurrentUser.OpenSubKey("Software", true); var appKey = key.OpenSubKey(REG_KEY_APP_NAME, true); if (appKey == null) { appKey = key.CreateSubKey(REG_KEY_APP_NAME); } appKey.SetValue(REG_KEY_VALUE, GenUtil.SafeTrim(alldata)); } catch (Exception ex) { msg = "Registry save error: " + ex.Message; } return(msg == ""); }
/// <summary> /// Only use this for comparisons, never for normalizing data to save in MMD (this is done automatically). /// </summary> //public static string MmdNormalizeForComparison(object o) //{ // // SharePoint internally removes multiple spaces, and replaces & and " with unicode equivalents. // return Term.NormalizeName(MmdRemoveIllegalChars(SafeTrim(o))); //} /// <summary> /// Not used. /// </summary> public static string MmdDenormalize(object o) { return(GenUtil.SafeTrim(o) .Replace(Convert.ToChar(char.ConvertFromUtf32(65286)), '&') .Replace(Convert.ToChar(char.ConvertFromUtf32(65282)), '"')); }
/// <summary> /// </summary> public static string MakeSafe(object o) { return(GenUtil.SafeTrim(o).Replace("'", "''")); }