[Solved] How can i find all the times between two given dates and time? [closed]

Gee, sometimes its fun to overengineer things. There is an Aggregate function which turns a list into a scalar value – lets create one that goes the other way public static class Extensions { public static IEnumerable<T> Explode<T>(this T value, Func<T,T> next, Func<T,bool> limit) { var n = value; while(!limit(n)) { yield return n; n … Read more

[Solved] Split text file every 120,000 Lines?

Just another way using Enumerable.GroupBy and “integer division groups”: int batchSize = 120000; var fileGroups = File.ReadLines(path) .Select((line, index) => new { line, index }) .GroupBy(x => x.index / batchSize) .Select((group, index) => new { Path = Path.Combine(dir, string.Format(“FileName_{0}.txt”, index + 1)), Lines = group.Select(x => x.line) }); foreach (var file in fileGroups) File.WriteAllLines(file.Path, file.Lines); … Read more

[Solved] Re-casting c# variables with a different class

Couldn’t you refactor it so that you have a generic method that takes a WebResponse? public T Deserialize<T>(WebResponse response) where T: new() // ensure that any type of T used has a parameterless constructor { string r = “”; using (StreamReader sr = new StreamReader(res.GetResponseStream())) { r = sr.ReadToEnd(); } JavaScriptSerializer js = new JavaScriptSerializer(); … Read more

[Solved] Remove space left after console scrollbars in C#

Finally, after a lot of head-scratching, I think I’ve solved this issue. Firstly, I had to add some additional WinAPI methods: [DllImport(“kernel32.dll”, SetLastError = true)] private static extern IntPtr GetStdHandle(int nStdHandle); [DllImport(“kernel32.dll”, SetLastError = true)] private static extern bool GetConsoleScreenBufferInfoEx( IntPtr hConsoleOutput, ref ConsoleScreenBufferInfoEx ConsoleScreenBufferInfo); [DllImport(“kernel32.dll”, SetLastError = true)] private static extern bool SetConsoleScreenBufferInfoEx( IntPtr … Read more

[Solved] Trying to show a Windows Form using a DLL that is imported at the runtime in a console application

The problem is that Activator.CreateInstance does not return ExpandObject (dynamic). You should run test() by reflection, like this : foreach (Type type in DLL.GetExportedTypes()) { dynamic c = Activator.CreateInstance(type); MethodInfo methodInfo = type.GetMethod(“test”); methodInfo.Invoke(c , null); } 2 solved Trying to show a Windows Form using a DLL that is imported at the runtime in … Read more

[Solved] How can i make that the lines in richTextBox1 will start from the right to the left?

Refer to the documentation on SelectionAlignment property: http://msdn.microsoft.com/en-us/library/system.windows.forms.richtextbox.selectionalignment%28v=VS.100%29.aspx Use the above (in your scenario) like so: richTextBox1.SelectAll(); richTextBox1.SelectionAlignment = HorizontalAlignment.Right; solved How can i make that the lines in richTextBox1 will start from the right to the left?

[Solved] How to search a given word in word file by C# [closed]

If you are using the Aspose library as stated in your comment you can achieve this through a customised implementation of the IReplacingCallback interface. bool IsContain(string word, string filePath) { Document doc = new Document(filePath); OccurrencesCounter counter = new OccurrencesCounter(); doc.Range.Replace(new Regex(word), counter, false); return counter.Occurrences > 0; } private class OccurrencesCounter : IReplacingCallback { … Read more