Showing posts from May, 2012

mshtml / interface / COM Generic Casting example

ever tried something like this:
and got all the elements where u have:

publicstaticbool IsTypeOf<T>(object o)
{   return (o is T);   }

privatevoid PrintAllElements<T>()
       HTMLDocument doc = webBrowser1.Document.DomDocument asHTMLDocument;
       foreach (IHTMLElement elem in doc.all)
             if (IsTypeOf<T>(elem))
             {    //do stuff}

i mean IsTypeOf always true?
thats cuz all the HTML classes inherit the nice IHTMLElement so any IHTMLElement is T where T is HTMLxxxxxElement(Class).
but the solution is so very simple - send the interface as T like IHTMLAnchorElement so this works great with the same code:

this OC goes to all interfaces based classes like most of the COM object we have in C#

How To Test JQUERY AJAX call example by RNAN

$("#UpdateKM").click(function (e) {    var upkm = document.getElementById("newKmtxt").value;    alert('myurl');    $.ajax(    {        url: 'myurl',        type: 'GET',        dataType: 'json'    }).done(function (result)    {        alert("done"); //or 1    }).fail(function (xhr, status,errorThrown)    {        alert(errorThrown); //or 2    }).    always(function (jqXHR, complete_textStatus)    {        alert('3');    }) });THANK U RNAN!!

C# LIST.FOREACH +lambda example

never found a really simple example, see this:
List<string> parts = newList<string>();
parts.ForEach(delegate (string p) {
     Console.WriteLine(p);    });
since in lambda () is delegate() so
List<DateTime> dates = newList<DateTime>(); // just to show that T doesnt matter
parts.ForEach((DateTime d) =>
PLUS u can do the remarkable list.Remove(d)! unlike foreach

C# WORD, and replace text, plus hebrew trick examlpe

the WordHandler class is the hard work of one of our ex-engineers.
pls remember that the number of parameters passed changes with the office versions
also u need to put the right Microsoft.Office.Interop.Word version, and its not according the office (word 14 is for office 10)
the trick is mine - the text backworded so a added in the word template val2 after val and it did the trick
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Word = Microsoft.Office.Interop.Word;
namespace WordFactory
static Word.Application oWord;
         static Word.Document oWordDoc;
         staticvoid Main(string[] args)
              WordHandler wh = newWordHandler();
              string pathA = @"F:\****.dot";
              string path = @"F:\****.dot";
              wh.CreateWord(path, out oWord, out oWordDoc);
              //the TRUTH == 201123USD01
              string acc = "201123USD01";
              string acc1 =…

Change Proxy C# example

ye i know there r millions exapmle but i wanna point out 2 thing:
string todaysProxy = "";
RegistryKey registry = Registry.CurrentUser.OpenSubKey
             ("Software\\Microsoft\\Windows\\CurrentVersion\\Internet Settings", true);
registry.SetValue("ProxyEnable", "00000001", RegistryValueKind.DWord);
registry.SetValue("ProxyEnable", 1);
registry.SetValue("ProxyServer", todaysProxy);
registry.SetValue("ProxyOverride", "192.168.0.*;127.0.0.*;localhost");

1 - ProxyEnable - either int 1 or define kind, unlike the batch
2 - O.C. IT WONT TAKE IMMIDIATE AFFECT but only on the new sessions, unless:

C# Read Excel File - EOProlbems!

sooo simple and genius!!
most basic print:
var excel = newExcelQueryFactory(@"F:\\MEMBER Book.xlsx");
var all = from c in excel.Worksheet()
select c;
foreach (var row in all)
foreach (var cell in row)
            Console.Write(cell.Value + "   ");

another thing i've been told of by Yon1973
use it with ADO

Update 2:
another reader for xls and other

MySQL IndexOf and Substring example

example to select the name only
SELECTINSTR('ariel@lti', '@');

SELECT Name, Email ,
INSTR(Email, '@') as indx,
SUBSTRING(Email, 1,  INSTR(Email, '@')-1)