Microsoft.Win32.RegistryKey key; key = Microsoft.Win32.Registry.CurrentUser.CreateSubKey("SocialEmailerPro"); key.SetValue("Key", "IsabellaIsTheNewKey"); key.GetValue("Key"); key.Close();
DotNetThreads
Wednesday 26 February 2014
Create a Key in Registry
Thursday 31 October 2013
Download Text File in asp.net
StringWriter oStringWriter = new StringWriter(); Response.ContentType = "text/plain"; Response.AddHeader("Content-Disposition", "attachment; filename=YourFileName.txt"); Response.Clear(); using (StreamWriter writer = new StreamWriter(Response.OutputStream, Encoding.UTF8)) { writer.Write("This is the content"); } Response.End();
Wednesday 30 October 2013
Convert DataTable/DataSet to Json string
public string GetJson(DataSet ds) { System.Web.Script.Serialization.JavaScriptSerializer serializer = new System.Web.Script.Serialization.JavaScriptSerializer(); List<object> rowss = new List<object>(); List<Dictionary<string, object>> rows = new List<Dictionary<string, object>>(); Dictionary<string, object> row = null; foreach (DataTable dt in ds.Tables) { rows = new List<Dictionary<string, object>>(); foreach (DataRow dr in dt.Rows) { row = new Dictionary<string, object>(); foreach (DataColumn col in dt.Columns) { row.Add(col.ColumnName.Trim(), dr[col]); } rows.Add(row); } rowss.Add(rows); } return serializer.Serialize(rowss); }
public string GetJson(DataTable dt)
{ System.Web.Script.Serialization.JavaScriptSerializer serializer = new System.Web.Script.Serialization.JavaScriptSerializer(); List<Dictionary<string, object>> rows = new List<Dictionary<string, object>>(); Dictionary<string, object> row = null; foreach (DataRow dr in dt.Rows) { row = new Dictionary<string, object>(); foreach (DataColumn col in dt.Columns) { row.Add(col.ColumnName.Trim(), dr[col]); } rows.Add(row); } return serializer.Serialize(rows); }
Wednesday 9 October 2013
Compile asp.net website from Visual studio command prompt
Open Visual studio command prompt
Enter
Aspnet_compiler -v / -p _fromFullPath _toFullpath
example:
Aspnet_compiler -v / -p d:\mywebsite d:\mywebsiteCompiled
Enter
Aspnet_compiler -v / -p _fromFullPath _toFullpath
example:
Aspnet_compiler -v / -p d:\mywebsite d:\mywebsiteCompiled
Save Image from Web Browser Control C#
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Runtime.InteropServices; using System.Drawing; using System.Windows.Forms; using System.Threading; class HTMLImageCap { [StructLayout(LayoutKind.Sequential)] private struct RECT { public int left; public int top; public int right; public int bottom; } //use win32 api private class Gdi32 { [DllImport("gdi32.dll")] public static extern bool BitBlt(IntPtr hObject, int nXDest, int nYDest, int nWidth, int nHeight, IntPtr hObjectSource, int nXSrc, int nYSrc, int dwRop); [DllImport("gdi32.dll")] public static extern IntPtr CreateCompatibleBitmap(IntPtr hDC, int nWidth, int nHeight); [DllImport("gdi32.dll")] public static extern IntPtr CreateCompatibleDC(IntPtr hDC); [DllImport("gdi32.dll")] public static extern bool DeleteDC(IntPtr hDC); [DllImport("gdi32.dll")] public static extern bool DeleteObject(IntPtr hObject); [DllImport("gdi32.dll")] public static extern IntPtr SelectObject(IntPtr hDC, IntPtr hObject); } private static class User32 { [DllImport("user32.dll")] public static extern IntPtr GetDesktopWindow(); [DllImport("user32.dll")] public static extern IntPtr GetWindowDC(IntPtr hWnd); [DllImport("user32.dll")] public static extern IntPtr GetWindowRect(IntPtr hWnd, ref RECT rect); [DllImport("user32.dll")] public static extern IntPtr ReleaseDC(IntPtr hWnd, IntPtr hDC); } //define constants private const int SRCCOPY = 13369376; private const int LOOPTIMES = 40; private const int SLEEPTIME = 100; private static int getXoffset(HtmlElement he) { //get element pos int xPos = he.OffsetRectangle.Left; //get the parents pos HtmlElement tempEl = he.OffsetParent; while (tempEl != null) { xPos += tempEl.OffsetRectangle.Left; tempEl = tempEl.OffsetParent; } return xPos; } private static int getYoffset(HtmlElement he) { //get element pos int yPos = he.OffsetRectangle.Top; //get the parents pos HtmlElement tempEl = he.OffsetParent; while (tempEl != null) { yPos += tempEl.OffsetRectangle.Top; tempEl = tempEl.OffsetParent; } return yPos; } private static Image captureWindow(IntPtr handle, int x, int y, int width, int height) { IntPtr hdcSrc = User32.GetWindowDC(handle); RECT windowRect = new RECT(); User32.GetWindowRect(handle, ref windowRect); IntPtr hdcDest = Gdi32.CreateCompatibleDC(hdcSrc); IntPtr hBitmap = Gdi32.CreateCompatibleBitmap(hdcSrc, width, height); IntPtr hOld = Gdi32.SelectObject(hdcDest, hBitmap); Gdi32.BitBlt(hdcDest, 0, 0, width, height, hdcSrc, x, y, SRCCOPY); Gdi32.SelectObject(hdcDest, hOld); Gdi32.DeleteDC(hdcDest); User32.ReleaseDC(handle, hdcSrc); Image img = Image.FromHbitmap(hBitmap); Gdi32.DeleteObject(hBitmap); return img; } public static Image getImage(WebBrowser wb, HtmlElement he) { //get original scroll position int docY = wb.Document.GetElementsByTagName("HTML")[0].ScrollTop; int docX = wb.Document.GetElementsByTagName("HTML")[0].ScrollLeft; //scroll to view element wb.Document.Window.ScrollTo(getXoffset(he), getYoffset(he)); int heY = getYoffset(he) - wb.Document.GetElementsByTagName("HTML")[0].ScrollTop; int heX = getXoffset(he) - wb.Document.GetElementsByTagName("HTML")[0].ScrollLeft; int heWidth = he.OffsetRectangle.Width; int heHeight = he.OffsetRectangle.Height; Image img = captureWindow(wb.Handle, heX, heY, heWidth, heHeight); //scroll back tooriginal position wb.Document.Window.ScrollTo(docX, docY); return img; } }
Put this class in your project and use like this
string Url = "https://accounts.google.com/SignUp";
webBrowser1.Navigate(Url); //Wait for few secs HtmlElement sliderWrap = webBrowser1.Document.GetElementById("recaptcha_image"); Image i = HTMLImageCap.getImage(webBrowser1, sliderWrap); i.Save(Application.StartupPath + "\\text.jpg");
Subscribe to:
Posts (Atom)