[Solved] String terminator for converting Time Strings [duplicate]

parse the string into components; possibly by position, possibly with Parse, possibly with regex decide what rules you want for each output use it For example: static string SimplifyTime(string value) { var match = Regex.Match(value, “([0-9]{2})hr:([0-9]{2})min:([0-9]{2})sec”); if (!match.Success) return value; int val = int.Parse(match.Groups[1].Value, CultureInfo.InvariantCulture); if (val > 0) return val + “hr Ago”; val … Read more

[Solved] How to login external web site from asp.net web page? [closed]

Hopefully, most web sites will prevent this type of thing. It is considered a cross site request forgery. You can read more about it here and if you still want to do it, at least you will know what you are getting into. Be safe. http://en.wikipedia.org/wiki/Cross-site_request_forgery 1 solved How to login external web site from … Read more

[Solved] Execute two buttons with single click

You should add an event that will call the code once the document has completed loading. private void Form1_Load(object sender, EventArgs e) { webBrowser1.DocumentCompleted += webBrowser1_DocumentCompleted; } void webBrowser1_DocumentCompleted(object sender, WebBrowserDocumentCompletedEventArgs e) { button2_Click(sender, e); } 2 solved Execute two buttons with single click

[Solved] How to make a deep copy Dictionary template

You can use Generics with where TValue : ICloneable constraint: public static Dictionary<TKey, TValue> deepCopyDic<TKey, TValue>(Dictionary<TKey, TValue> src) where TValue : ICloneable { //Copies a dictionary with all of its elements //RETURN: // = Dictionary copy Dictionary<TKey, TValue> dic = new Dictionary<TKey, TValue>(); foreach (var item in src) { dic.Add(item.Key, (TValue)item.Value.Clone()); } return dic; } … Read more

[Solved] c# how to get mail name (uid) after send [closed]

You can read all of the email file names in the C:\Temp directory like so: – DirectoryInfo dirInfo = new DirectoryInfo(@”C:\Temp”); foreach (FileInfo fInfo in dirInfo.GetFiles(“*.eml*”)) { Console.WriteLine(fInfo.Name); } Console.Read(); You could potentially get the the newest created file in that directory which would give you the last email sent, though I’m not exactly sure … Read more

[Solved] Datatable group and pivot

Try this using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Data; namespace ConsoleApplication1 { class Program { static void Main(string[] args) { DataTable dt = new DataTable(); dt.Columns.Add(“unit”, typeof(string)); dt.Columns.Add(“value”, typeof(int)); dt.Columns.Add(“date”, typeof(DateTime)); dt.Rows.Add(new object[] { “A”,2, DateTime.Parse(“01-01-2000”)}); dt.Rows.Add(new object[] { “B”,3, DateTime.Parse(“01-01-2000”)}); dt.Rows.Add(new object[] { “A”,4, DateTime.Parse(“02-01-2000”)}); string[] uniqueUnits = dt.AsEnumerable().Select(x => x.Field<string>(“unit”)).Distinct().ToArray(); … Read more

[Solved] Checking if all textboxes in a panel a filled

Perhaps something like this: foreach(Panel pnl in Controls.OfType<Panel>()) { foreach(TextBox tb in pnl.Controls.OfType<TextBox>()) { if(string.IsNullOrEmpty(tb.Text.Trim())) { MessageBox.Show(“Text box can’t be empty”); } } } 0 solved Checking if all textboxes in a panel a filled

[Solved] Regular Expression for Employee ID with some restrictions [closed]

mlorbetske’s regex can be rewritten a bit to remove the use of conditional regex. I also remove the redundant 0-9 from the regex, since it has been covered by \d. ^[a-zA-Z\d](?:[a-zA-Z\d]|(?<![._/\\\-])[._/\\\-]){0,49}$ The portion (?:[a-zA-Z\d]|(?<![._/\\\-])[._/\\\-]) matches alphanumeric character, OR special character ., _, /, \, – if the character preceding it is not a special character … Read more

[Solved] How to prevent method from running in multiple instances [closed]

I would use Mutex to avoid multiple access to the same recourses. Here you have a brief piece of code to achieve this Mutex mutex; private void StartPolling() { mutex = new Mutex(true, “same_name_in_here”, out bool createdNew); if (!createdNew) { throw new Exception(“Polling running in other process”); } //now StartPolling can not be called from … Read more

[Solved] Delay in c# not thread.sleep [closed]

Yes, you can do the same thing in C#, but that is a very bad idea. This way of making a pause is called a busy loop, because it will make the main thread use as much CPU as possible. What you want to do instead is to set up a timer, and call a … Read more

[Solved] Create Hashset with a large number of elements (1M)

To build on @Enigmativity’s answer, here’s a proper benchmark using BenchmarkDotNet: public class Benchmark { private const int N = 1000000; [Benchmark] public HashSet<int> EnumerableRange() => new HashSet<int>(Enumerable.Range(1, N + 1)); [Benchmark] public HashSet<int> NoPreallocation() { var result = new HashSet<int>(); for (int n = 1; n < N + 1; n++) { result.Add(n); } … Read more

[Solved] Creating .NET runtime envoriment [closed]

Just to make sure we’re talking about the same thing, a runtime is the software necessary to run something written under a particular development framework or system. For example, a user needs the Java runtime installed in order to run software written in Java. Likewise, you need the .NET runtime installed in order to run … Read more