Pages

Friday, September 18, 2009

Reading a word file Using c#

Reading a word file in c# is very simple we just need to add the reference of the COM component in our application. Click on Add >> Reference and Select the COM tab, under that tab please select the Microsoft object library 9.0 or higher. and after this use the following code to read any file...


Microsoft.Office.Interop.Word.ApplicationClass wordApp = new Microsoft.Office.Interop.Word.ApplicationClass();
object file = "D:\\Anil\\test\\testfile.doc"; // path for word file
object nullobj = System.Reflection.Missing.Value;
Microsoft.
Office.Interop.Word.Document doc = wordApp.Documents.Open(ref file, ref nullobj, ref nullobj,
ref nullobj, ref nullobj, ref nullobj, ref nullobj, ref nullobj, ref nullobj,
ref nullobj, ref nullobj, ref nullobj,ref nullobj, ref nullobj, ref nullobj, ref nullobj);
doc.
ActiveWindow.Selection.WholeStory();
doc.
ActiveWindow.Selection.Copy();
IDataObject data
= Clipboard.GetDataObject();
string allText = data.GetData(DataFormats.Text).ToString();
doc.
Close(ref nullobj, ref nullobj, ref nullobj);
wordApp.
Quit(ref nullobj, ref nullobj, ref nullobj);
Textbox1.
Text = allText);


Happy Coading!!!

Thanks
Anil Kumar Pandey
System Architect
Mumbai, Maharshtra

Thursday, September 17, 2009

Getting no of characters remaing for a text box..

Many times we set the maximum length of the text box so that a user can only enter that no of specified characters. if you want to so that how many no of character is remaing for that text box , then we can display this using this code..
Here with the use of Javascript we can achieve this task. please check this below code.

Code for ASP page

<head>
<script LANGUAGE="JavaScript">
function textCounter(field,cntfield,maxlimit)
{
if (field.value.length > maxlimit)
{
field.
value = field.value.substring(0, maxlimit);
}
else
{
cntfield.
value = maxlimit -
field.
value.length;
}
}
>
>

<body>
<asp:TextBox ID="txtFeatures" runat="server" TextMode="MultiLine"
Columns
="28" Rows="5" Wrap="true" />
<br />
<input readonly type="text" name="remLen1" id="remLen1" size="3"
maxlength
="3" value="90" />
>


and this code we need to attach with the text box in the cs file.

public void Page_Load()
{
if (!(Page.IsPostBack)) {
txtFeatures.
Attributes("name") = "txtFeatures";
txtFeatures.
Attributes("onKeyUp") = "textCounter(txtFeatures,remLen1,90);";
txtFeatures.
Attributes("onKeyDown") = "textCounter(txtFeatures,remLen1,90);";
txtFeatures.
Attributes("onKeyPress") = "textCounter(txtFeatures,remLen1,90);";
}
}



This is the complete code for the same.. try it..

Happy Coding!!!

Thanks
Anil Kumar Pandey
System Architect
Mumbai, Maharshtra

Monday, September 14, 2009

AN INTERESTING INTERVIEW

AN INTERESTING INTERVIEW........Banta Strikes Again!!!

AN INTERESTING INTERVIEW

Interviewer
:Let me check your word Power...
Banta :Ok Sir ....
Interviewer : Tell me the opposite of .....good.
Banta :hmmmm..... Bad
Interviewer
: Come
Banta
: Go.
Interviewer : Ugly.
Banta : Pichlli.
Interviewer : PICHLLIIIII?
Banta
: UGLYYYYYYYYY..
Interviewer : Shut Up.
Banta : Keep Talking.
Interviewer k now stop these all..
Bantak now carry on this all
Interviewer
:abe...chup ho ja..chup ho ja..chup ho jaaaa
Banta
:abe bolta rah..bolta rah..bolta rahhh
Interviewer
:Areeee yaaar
Banta
: areeee dushmannnnnn
Interviewer
: Get Out.
Banta : Come In.
Interviewer : Oh my God.
Banta : Oh my Devil.
Interviewer : U r Rejected.
Banta: I m selected...I M SELECTED???REALLY??BALLE BALLE




Thanks
Anil Kumar Pandey
System Architect
Mumbai, Maharshtra

Kontera