Set System Time Zone from .NET

There’s another way to do this, which admittedly is a bit of a hack, but works quite well in practice: public void SetSystemTimeZone(string timeZoneId) { var process = Process.Start(new ProcessStartInfo { FileName = “tzutil.exe”, Arguments = “/s \”” + timeZoneId + “\””, UseShellExecute = false, CreateNoWindow = true }); if (process != null) { process.WaitForExit(); … Read more

WinWord.exe won’t quit after calling Word.Documents.Add – Word .NET Interop

(All of my advice is adapted from this answer about Excel interop.) There are a few important things here: 1) Never use 2 dots on the same line. Also consider an indexer as a dot Good Word.Documents d = wordApp.Documents; Word.Document aDoc = d.Open(/*…*/); BAD Word.Document aDoc = wordApp.Documents.Open(/*…*/); 2) Release all of your pointers. … Read more

How do I import from Excel to a DataSet using Microsoft.Office.Interop.Excel?

What about using Excel Data Reader (previously hosted here) an open source project on codeplex? Its works really well for me to export data from excel sheets. The sample code given on the link specified: FileStream stream = File.Open(filePath, FileMode.Open, FileAccess.Read); //1. Reading from a binary Excel file (’97-2003 format; *.xls) IExcelDataReader excelReader = ExcelReaderFactory.CreateBinaryReader(stream); … Read more

Can I overlay a WPF window on top of another?

I’ve worked around this problem by using a Popup rather than a transparent Window Update I ended up with a subclassed Popup which I call AirspacePopup. What AirspacePopup does Follow its PlacementTarget. Is not always-on-top, but placed relative to the Window in which it is being placed. This solution comes from Chris Cavanagh’s Blog. Is … Read more

How to create class methods that conform to a protocol shared between Swift and Objective-C?

In Objective-C, we were always passing around pointers, and pointers could always be nil. Lots of Objective-C programmers made use of the fact that sending a message to nil did nothing and returned 0/nil/NO. Swift handles nil entirely differently. Objects either exist (never nil), or it is unknown whether or not they exist (which is … Read more

Use a .jar java library API in C#?

You can do it using IVKM.Net. IVKM.NET includes an application called ikvmc. Here’s the documentation for this tool: http://www.ikvm.net/userguide/ikvmc.html To use it compile your java code into a Jar. Then run the ikvmc program: ikvmc myCode.jar If your jar contains a main() function, it will be converted into an exe that can be run on … Read more

No definition found for GetActiveObject from System.Runtime.InteropServices.Marshal C#

We need to pull the GetActiveObject(String ProgID) function from the source code GitHub.Microsoft Create your own class, for example – Marshal2 And use as before Marshal2.GetActiveObject(progID); Source code public static class Marshal2 { internal const String OLEAUT32 = “oleaut32.dll”; internal const String OLE32 = “ole32.dll”; [System.Security.SecurityCritical] // auto-generated_required public static Object GetActiveObject(String progID) { Object … Read more

How do I read text from the Windows clipboard in Python?

You can use the module called win32clipboard, which is part of pywin32. Here is an example that first sets the clipboard data then gets it: import win32clipboard # set clipboard data win32clipboard.OpenClipboard() win32clipboard.EmptyClipboard() win32clipboard.SetClipboardText(‘testing 123’) win32clipboard.CloseClipboard() # get clipboard data win32clipboard.OpenClipboard() data = win32clipboard.GetClipboardData() win32clipboard.CloseClipboard() print data An important reminder from the documentation: When the … Read more