Surendra Sharma

Surendra Sharma

Search This Blog

Friday, June 4, 2010

Show the Web site Icon in the Adress bar


<
head id="Head2"
runat="server">


   
<title>Untitled Page</title>


   
<link
href="t.png"
rel="shotcut icon"
/>

</head>

Create word document from Template & pass data from .NET


using

Microsoft.Office.Core;

using Word;




private

void ParseWord()


{


 


    Word.ApplicationClass
myWordApp = new Word.ApplicationClass();


    Word.Document myWordDoc
= new Word.Document();


 


   
object missing = System.Reflection.Missing.Value; // our
'void' value


   
object filename =
@"E:\My Files\WordTest\Master5.dot"
; // our
word template


   
object destination =
@"E:\My Files\WordTest\ABC4.doc"
; 
// our target filename


   
object notTrue = false;  // our
boolean false

 

 


   
string myText =
"Hello World!!"
;


   
// the sample text we want as replacement

 


    myWordApp.Visible =
false;  //
tell word not to show itself

 


    myWordDoc =
myWordApp.Documents.Add( // load the template into a
document workspace


                         
ref filename,  // and
reference it through our myWordDoc


                         
ref missing,


                         
ref missing,


                         
ref missing);


 


   
// count how many fields we have to update


   
foreach (Field myField
in
myWordDoc.Fields)


    {


       
myField.Select();


       
string str = myField.Code.Text;


       
myWordApp.Selection.TypeText(DateTime.Now.ToString());


    }


 


   
//


   
// now the last touch.. save and close


   
//


    myWordDoc.SaveAs(


            
ref destination,


            
ref missing,


            
ref missing,


            
ref missing,


            
ref missing,


            
ref missing,


            
ref missing,


            
ref missing,


            
ref missing,


            
ref missing,


             ref missing,


            
ref missing,


            
ref missing,


            
ref missing,


            
ref missing,


            
ref missing);


 


   
// quit word


   
myWordApp.Application.Quit(


            
ref notTrue,


            
ref missing,


            
ref missing);

}

Set Server Side Label Control Text from Javascript

document.getElementById('<%=lblDateSelect.ClientID%>').innerText = 'Please select From Date' ;

Thursday, May 13, 2010

How to set text to a Password TextBox in ASP.NET

txtPassword.Attributes["value"] = "Password123";

Get the difference of month between two dates


private
static int monthDifference(DateTime startDate, DateTime endDate)

{       int monthsApart =
12 * (startDate.Year - endDate.Year) + startDate.Month - endDate.Month;
      return Math.Abs(monthsApart);



}

To solve apostrophe problem in where condition of SQL Statement


If ur query contain single apostrophe like this

SELECT * FROM Products WHERE ProductName = 'King's Jalepenos'

Then replace ur single apostrophe with two apostrophe like

SELECT * FROM Products WHERE ProductName ='King''s Jalepenos'



Better do it in C# coding as follows


string

str = "King''s Jalepenos";

str= str.Replace("'","''");

WinCV.exe - viewing the contents of any DOT NET namespace

WinCV.exe is a tool for viewing the contents of any DOT NET namespace. It is resides in C:\Program Files\Microsoft Visual Studio .NET 2003\SDK\v1.1\Bin