Surendra Sharma

Surendra Sharma

Search This Blog

Friday, June 4, 2010

Regex for allowing only Alphabetics, numbers, apostrophe, spaces, dash for string having length 20

ValidationExpression="^[0-9a-zA-Z''\-'' '\s]{1,20}$"

To Display some ListItem in different colour in ListBox in ASP.NET

foreach (ListItem objTempItem in ListBox2.Items)

{

   //Code to change background colour of listitem

   //objTempItem.Attributes.Add("style", "background-color: RED");



  //Code to change text or foreground colour of listitem

  objTempItem.Attributes.Add("style","color:RED");

}

How to get Temporary Folder Path using .NET (C#)

How to get path of the current system's temporary folder using .NET (C#)
Temporary folders are useful to store simple logs during execution of the program. It is also used for storing the decompressed files before any operation. The folder location varies from OS to OS. The following C# snippet would help in retrieving the Temporary folder path

string sPath;

sPath =
Path.GetTempPath();

Console.WriteLine("Temporary Path := " + sPath );

Get filenames from all folders

Here is another way to get filenames from all folders, including subdirectories (notice the SearchOption.AllDirectories parametre):

// Process the list of files found in all directory.


string
[]
fileEntries = Directory.GetFiles(sourceDir,
"*", SearchOption.AllDirectories);


foreach

(string fileName in
fileEntries)


{

// do something with fileName


     
Console.WriteLine(fileName);


}


If you change the "*" to ex. "*.log" you will get all filenames that ends with ".log".

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' ;