Use this below extension method to clone the obejcts
public static T Clone<T>(T source) { var serialized = JsonConvert.SerializeObject(source); return JsonConvert.DeserializeObject<T>(serialized); }
public static T Clone<T>(T source) { var serialized = JsonConvert.SerializeObject(source); return JsonConvert.DeserializeObject<T>(serialized); }
CustomAutoClosingMessageBox.Show("Text", "Caption", 1000);
public class CustomAutoClosingMessageBox { System.Threading.Timer _timeoutTimer; string _caption; DialogResult _result; DialogResult _timerResult; AutoClosingMessageBox(string text, string caption, int timeout, MessageBoxButtons buttons = MessageBoxButtons.OK, DialogResult timerResult = DialogResult.None) { _caption = caption; _timeoutTimer = new System.Threading.Timer(OnTimerElapsed, null, timeout, System.Threading.Timeout.Infinite); _timerResult = timerResult; using(_timeoutTimer) _result = MessageBox.Show(text, caption, buttons); } public static DialogResult Show(string text, string caption, int timeout, MessageBoxButtons buttons = MessageBoxButtons.OK, DialogResult timerResult = DialogResult.None) { return new AutoClosingMessageBox(text, caption, timeout, buttons, timerResult)._result; } void OnTimerElapsed(object state) { IntPtr mbWnd = FindWindow("#32770", _caption); // lpClassName is #32770 for MessageBox if(mbWnd != IntPtr.Zero) SendMessage(mbWnd, WM_CLOSE, IntPtr.Zero, IntPtr.Zero); _timeoutTimer.Dispose(); _result = _timerResult; } const int WM_CLOSE = 0x0010; [System.Runtime.InteropServices.DllImport("user32.dll", SetLastError = true)] static extern IntPtr FindWindow(string lpClassName, string lpWindowName); [System.Runtime.InteropServices.DllImport("user32.dll", CharSet = System.Runtime.InteropServices.CharSet.Auto)] static extern IntPtr SendMessage(IntPtr hWnd, UInt32 Msg, IntPtr wParam, IntPtr lParam); }
var result = Task.Run(async() => { return await yourAsyncMethod(); }).Result;
public void gotoWebSite(string mySiteUrl) { System.Diagnostics.Process.Start(mySiteUrl); }
<asp:DataList ID="dlItems" runat="server" OnItemCommand="dlItems_ItemCommand">
protected void dlItems_ItemCommand(object source, DataListCommandEventArgs e) { if (e.CommandName == "Update") { TextBox txtname = e.Item.FindControl("txtName") as TextBox; lblName.Text = txtname.Text; } }
var expandoObject = new ExpandoObject(); var myObject = expandoObject as IDictionary<String, object>; myObject ["youtPropertyName"] = "yourvalue";
Uri filename = new Uri(filePath); string server = filename.AbsoluteUri.Replace(filename.AbsolutePath, ""); string serverrelative = filename.AbsolutePath; Microsoft.SharePoint.Client.FileInformation file = Microsoft.SharePoint.Client.File.OpenBinaryDirect(this.ClientContext, serverrelative); return file.Stream;
Uri filename = new Uri(filePath); string server = filename.AbsoluteUri.Replace(filename.AbsolutePath, ""); string serverrelative = filename.AbsolutePath; Microsoft.SharePoint.Client.File file = this.ClientContext.Web.GetFileByServerRelativeUrl(serverrelative); this.ClientContext.Load(file); ClientResult<Stream> streamResult = file.OpenBinaryStream(); this.ClientContext.ExecuteQuery(); return streamResult.Value;