Wordcount for a file in c#

c# code snippet to search for a count of particular word from a textbased files.


StreamReader sr = new StreamReader(@"C:\yourfilename.txt"); // open the file
read string text = sr.ReadToEnd();
sr.Close();

string word = "search keyword" // word which we want to search
Regex r = new Regex(@"\b" + word + @"\b", RegexOptions.IgnoreCase);
MatchCollection mc = r.Matches(text);
int i = mc.Count.ToString();

WCF OperationContract function overloading

It is not possible to overload OperationContract

[ServiceContract]
public interface IOverload
{
[OperationContract]
int TestMethod(int arg1);
[OperationContract]
int TestMethod(int arg1,int arg2);
}


At run time, it will throw an exception as like

System.InvalidOperationException: Cannot have two operations in the same contract with the same name, You can change the name of one of the operations by changing the method name or by using the Name property of OperationContractAttribute.

we can set the operation contract name as below.

[ServiceContract]
public interface IOverload
{
[OperationContract(Name="Test1")]
int TestMethod(int arg1);

[OperationContract(Name="Test2")]
int TestMethod(int arg1,int arg2);
}

MsSQL string replace function for Text datatype

In MsSql, I tried to replace a string 'vm-1' to 'vm001' in all rows for a specific column of text datatype.

UPDATE [PatientImages]
SET [ImageLocation] = replace([ImageLocation],'nt3ks-vm1','nt3ksvm001')

But compiler slaps me and and said,
"Argument data type text is invalid for argument 1 of replace function".
I know the replace function works for character and binary types.
I tried again and again,then i found that it will work for char,varchar types and not for text datatype.
finally i replaced the content by type casted the value to varchar as below

UPDATE [PatientImages]
SET [ImageLocation] = replace(Cast(ImageLocation AS NVARCHAR(Max)),'nt3ks-vm1','nt3ksvm001')

i start to think why this text datatype is not supported in replace function.
then i come to know Text datatype is a deprecated datatype in sql2005, instead of that we have to use any one of NVarChar(Max), VarChar(Max) or VarBinary(Max)

User Presence Information in Sharepoint pages and webparts

A simple javascript function enable us to display the user presence information inside the web parts or in a share point page.

< img border="0" height="12" width="12" alt="" src="/_layouts/images/blank.gif" onload="IMNRC('yasar@yasar.in');" id="uid1" ShowOfflinePawn=1>

the user's email address is placed as a parameter to a JavaScript function IMNRC() actually adds the presence info of the user in the web page by getting the information from Windows messenger client applications


First post

Hi

after long time, i started blogging..
i thought to blog technical related stuffs.
lets see how much i can actively update.