Reference site for Sitecore and Dot NET. Call at +91-9910045174 for any Sitecore corporate trainings and workshops.
Surendra Sharma
Search This Blog
Friday, June 4, 2010
Regex for allowing only Alphabetics, numbers, apostrophe, spaces, dash for string having length 20
To Display some ListItem in different colour in ListBox in ASP.NET
}
How to get Temporary Folder Path 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();
Get filenames from all folders
// 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;
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);
}