C# Xml Serialization & Deserialization

In your deserialization code you’re creating a MemoryStream and XmlTextWriter but you’re not giving it the string to deserialize. using (MemoryStream memStream = new MemoryStream()) { using (XmlTextWriter textWriter = new XmlTextWriter(memStream, Encoding.Unicode)) { // Omitted } } You can pass the bytes to the memory stream and do away with the XmlTextWriter altogether. using … Read more

Drag-and-Drop multiple Attached File From Outlook to C# Window Form

I solve my problem Just add that code in any cs file. using System; using System.IO; using System.Collections.Generic; using System.Runtime.InteropServices; using System.Runtime.InteropServices.ComTypes; using System.Text; using System.Reflection; using System.Windows.Forms; namespace iwantedue.Windows.Forms { public class OutlookDataObject: System.Windows.Forms.IDataObject { #region NativeMethods private class NativeMethods { [DllImport(“kernel32.dll”)] static extern IntPtr GlobalLock(IntPtr hMem); [DllImport(“ole32.dll”, PreserveSig = false)] public static extern … Read more

Binding DynamicObject to a DataGrid with automatic column generation?

There is no uniform way to query dynamic properties, generally it’s expected that you know them ahead of time. With DynamicObject, implementers may override GetMemberNames and that generally gives you the properties, however it is really meant for debugging because there is no requirement that it provide all properties. Otherwise if it’s your own DynamicObject … Read more

How to add TemplateField programmatically

This might help to get started: protected void Page_Load(object sender, EventArgs e) { if (!IsPostBack) { var linkField = new TemplateField(); linkField.ItemTemplate = new LinkColumn(); GridView1.Columns.Add(linkField); } } class LinkColumn : ITemplate { public void InstantiateIn(System.Web.UI.Control container) { LinkButton link = new LinkButton(); link.ID = “linkmodel”; container.Controls.Add(link); } } But: Although you can dynamically add … Read more

sql geography to dbgeography?

Sorry for the late response – but saw this whilst searching for something else. Simply do the following: SqlGeography theGeography; int srid = 4326; // or alternative DbGeography newGeography = DbGeography.FromText(theGeography.ToString(), srid); To reverse it: DbGeography theGeography; SqlGeography newGeography = SqlGeography.Parse(theGeography.AsText()).MakeValid(); Hope that helps!

TPL TaskFactory.FromAsync vs Tasks with blocking methods

You absolutely want to use FromAsync when an API offers a BeginXXX/EndXXX version of a method. The difference is that, in the case of something like Stream or Socket or WebRequest, you’ll actually end up using async I/O underneath the covers (e.g. I/O Completion Ports on Windows) which is far more efficient than blocking multiple … Read more