c# Programming Glossary: here's
Elevating process privilege programatically? http://stackoverflow.com/questions/133379/elevating-process-privilege-programatically using InstallUtil.exe but invoked through Process.Start. Here's the code ProcessStartInfo startInfo new ProcessStartInfo m_strInstallUtil..
Create Excel (.XLS and .XLSX) file from C# [closed] http://stackoverflow.com/questions/151005/create-excel-xls-and-xlsx-file-from-c-sharp con.Close Add the table to the data set ds.Tables.Add dt Here's the easy part. Create the Excel worksheet from the data set..
TransactionScope automatically escalating to MSDTC on some machines? http://stackoverflow.com/questions/1690892/transactionscope-automatically-escalating-to-msdtc-on-some-machines questions 506733 but unfortunately it doesn't. Here's a sample bit of code that will cause the trouble on the machines.. We've really dug in and tried to figure this out. Here's some info on the machines that it works on Dev 1 Windows 7 x64..
How to convert a column number (eg. 127) into an excel column (eg. AA) http://stackoverflow.com/questions/181596/how-to-convert-a-column-number-eg-127-into-an-excel-column-eg-aa etc. c# excel excel 2007 share improve this question Here's how I do it private string GetExcelColumnName int columnNumber..
Encrypt/Decrypt string in .NET http://stackoverflow.com/questions/202011/encrypt-decrypt-string-in-net http stackoverflow.com a 10366194 188474 Original Answer Here's a working example derived from the RijndaelManaged Class documentation..
When to Use Static Classes in C# http://stackoverflow.com/questions/241339/when-to-use-static-classes-in-c-sharp to Use Static Classes in C# Here's what MSDN has to say under When to Use Static Classes static..
High Quality Image Scaling C# http://stackoverflow.com/questions/249587/high-quality-image-scaling-c-sharp manipulation image scaling share improve this question Here's a nicely commented Image Manipulation helper class that you..
How to convert UNIX timestamp to DateTime and vice versa? http://stackoverflow.com/questions/249760/how-to-convert-unix-timestamp-to-datetime-and-vice-versa c# unix datetime timestamp share improve this question Here's what you need public static DateTime UnixTimeStampToDateTime..
How do I build a JSON object to send to an AJAX WebService? http://stackoverflow.com/questions/2737525/how-do-i-build-a-json-object-to-send-to-an-ajax-webservice miserably I realized there's probably a better way. Here's what the code for the web service method and relevant classes.. text didn't conform to requirements of the web service. Here's a valid JSON request based on the code in the WebMethod ' request..
Convert hex string to byte array [duplicate] http://stackoverflow.com/questions/321370/convert-hex-string-to-byte-array for this c# encoding hex share improve this question Here's a nice fun LINQ example. public static byte StringToByteArray..
How to Deserialize XML document http://stackoverflow.com/questions/364253/how-to-deserialize-xml-document xml deserialization share improve this question Here's a working version. I changed the XmlElementAttribute labels..
Best practices for exception management in Java or C# http://stackoverflow.com/questions/409563/best-practices-for-exception-management-in-java-or-c-sharp the task was successful not why it is wasn't successful. Here's some sample code in JAVA of a typical method public boolean..
C# - The foreach identifier and closures http://stackoverflow.com/questions/512166/c-sharp-the-foreach-identifier-and-closures in each closure scope so there is no risk of this issue. Here's a simple proof of the problem static void Main int data 0 1..
Convert generic List/Enumerable to DataTable? http://stackoverflow.com/questions/564366/convert-generic-list-enumerable-to-datatable generics datatable poco share improve this question Here's a nice 2013 update using FastMember from NuGet IEnumerable SomeType..
Retrieving Property name from lambda expression http://stackoverflow.com/questions/671968/retrieving-property-name-from-lambda-expression thing to make a type safe OnPropertyChanged method. Here's a method that'll return the PropertyInfo object for the expression...
Is it possible to dynamically compile and execute C# code fragments? http://stackoverflow.com/questions/826398/is-it-possible-to-dynamically-compile-and-execute-c-sharp-code-fragments constructing bits of code or even whole classes. Here's a nice short example take from LukeH's blog which uses some..
What does the [Flags] Enum Attribute mean in C#? http://stackoverflow.com/questions/8447/what-does-the-flags-enum-attribute-mean-in-c 2 Blue 3. This will render it useless for use as flags. Here's an example of a correct declaration Flags public enum MyColors..
C# Login to Website via program http://stackoverflow.com/questions/930807/c-sharp-login-to-website-via-program resp req.GetResponse cookieHeader resp.Headers Set cookie Here's an example of what you should see in the Set cookie header for..
ExecuteReader requires an open and available Connection. The connection's current state is Connecting http://stackoverflow.com/questions/9705637/executereader-requires-an-open-and-available-connection-the-connections-curren commented to trash it. That's only a problem source. Edit Here's a possible implementation of your retrievePromotion method public..
A generic error occurred in GDI+, JPEG Image to MemoryStream http://stackoverflow.com/questions/1053052/a-generic-error-occurred-in-gdi-jpeg-image-to-memorystream
Performance difference for control structures 'for' and 'foreach' in C# http://stackoverflow.com/questions/1124753/performance-difference-for-control-structures-for-and-foreach-in-c-sharp List T with foreach produces the same code as the for loop here's evidence that it doesn't static void IterateOverList List object..
How can I generate random 8 character, alphanumeric strings in C#? http://stackoverflow.com/questions/1344221/how-can-i-generate-random-8-character-alphanumeric-strings-in-c improve this question I heard LINQ is the new black so here's my attempt using LINQ var chars ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789..
XDocument or XMLDocument http://stackoverflow.com/questions/1542073/xdocument-or-xmldocument etc. There are various blog posts about this technique here's one I found with a quick search . share improve this answer..
C# cleanest way to write retry logic? http://stackoverflow.com/questions/1563191/c-sharp-cleanest-way-to-write-retry-logic a general exception handling mechanism. Having said that here's a lambda based retry wrapper that you can use with any method...
switch / pattern matching idea http://stackoverflow.com/questions/156467/switch-pattern-matching-idea or on the possibilities of richer C# language support... here's hoping p . c# switch statement share improve this question..
TransactionScope automatically escalating to MSDTC on some machines? http://stackoverflow.com/questions/1690892/transactionscope-automatically-escalating-to-msdtc-on-some-machines more of a mess useful and just for more clarity's sake here's how you can get SQL2005 to escalate to DTC with a single SqlConnection..
What NoSQL solutions are out there for .NET? [closed] http://stackoverflow.com/questions/1777103/what-nosql-solutions-are-out-there-for-net redis.io clients It's even more terse in dynamic languages here's how easy it is to create a non blocking web server hosting named..
Does using “new” on a strict allocate it on the heap or stack? http://stackoverflow.com/questions/203695/does-using-new-on-a-strict-allocate-it-on-the-heap-or-stack It makes sense for the CLI to think of it differently as there's no real code to call and certainly no type specific code. It.. slightly different again. To show all these differences here's a short test program. It doesn't show the difference between..
Getting key of value of a generic Dictionary? http://stackoverflow.com/questions/255341/getting-key-of-value-of-a-generic-dictionary single 2 c# .net share improve this question Okay here's the multiple bidirectional version using System using System.Collections.Generic..
Performance Tests of Serializations used by WCF Bindings http://stackoverflow.com/questions/3790728/performance-tests-of-serializations-used-by-wcf-bindings binding share improve this question OK I'll bite... here's some raw serializer metrics emph you may need to consider base..
When should I dispose of a data context http://stackoverflow.com/questions/389822/when-should-i-dispose-of-a-data-context from the LINQ to SQL team about this a while ago and here's the reply There are a few reasons we implemented IDisposable..
Dynamic LINQ OrderBy on IEnumerable<T> http://stackoverflow.com/questions/41244/dynamic-linq-orderby-on-ienumerablet dynamic queries MemberExpression doesn't support it . But here's a way to do it with LINQ to Objects. Note that the choice of..
How do the major C# DI/IoC frameworks compare? http://stackoverflow.com/questions/4581791/how-do-the-major-c-sharp-di-ioc-frameworks-compare to this question takes up hundreds of pages of my book here's a quick comparison chart that I'm still working on share improve..
Convert generic List/Enumerable to DataTable? http://stackoverflow.com/questions/564366/convert-generic-list-enumerable-to-datatable for the object type T . edit re performance query here's a test rig with results Vanilla 27179 Hyper 6997 I suspect that..
How to check if a number is a power of 2 http://stackoverflow.com/questions/600293/how-to-check-if-a-number-is-a-power-of-2 c# algorithm math share improve this question There's a simple trick for this problem bool IsPowerOfTwo ulong x return.. of two. If you want to take into account that edge case here's how bool IsPowerOfTwo ulong x return x 0 x x 1 0 Explanation..
How to associate a file extension to the current executable in C# http://stackoverflow.com/questions/69761/how-to-associate-a-file-extension-to-the-current-executable-in-c-sharp 1 to represent the path to the file selected. For instance here's a sample registry file to create an association between .txt..
Deep cloning objects in C# http://stackoverflow.com/questions/78536/deep-cloning-objects-in-c-sharp ICloneable interface described here so I won't regurgitate here's a nice deep clone object copier I found on The Code Project..
Using C#, how does one figure out what process locked a file? http://stackoverflow.com/questions/860656/using-c-how-does-one-figure-out-what-process-locked-a-file this question Please excuse the massive code dump but here's a little class to do it. It works on Windows 7 and Windows Server..
C# Login to Website via program http://stackoverflow.com/questions/930807/c-sharp-login-to-website-via-program Using WebRequest and code I adapted from Scott Hanselman here's how you'd POST form data to your login form string formUrl http..
|