Tuesday, August 4, 2009

Redirect webpage to another webpage/ website

meta HTTP-EQUIV="REFRESH" content="0; url=http://www.DesTinationURL.com"

Monday, July 6, 2009

SQL Query returning duplicate records in a database

Use GroupBy, Having clause

SELECT Emp_Name, Emp_ID FROM Emp_Db GROUP BY Emp_Name, Emp_ID HAVING COUNT (*) > 1

Monday, June 29, 2009

C# Read text from .doc to c# application

Read text from word file (.doc)

Add referance to MicroSoft Word 11.0 object library

Word.ApplicationClass wordApp = new Word.ApplicationClass();
string filePath = "c:\\tempfile.doc";
object file = filePath;
object nullobj = System.Reflection.Missing.Value;
object nosave = Word.WdSaveOptions.wdDoNotSaveChanges;
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);
string m_Content = doc.Content.Text;
doc.Close(ref nosave, ref nullobj, ref nullobj);
wordApp.Quit(ref nosave, ref nullobj, ref nullobj);

richTextBox.Text = m_Content;

Saturday, June 27, 2009

Compare tables with same data

SQL Query Compare data in two tables having same data

(SELECT * FROM @Table1 EXCEPT SELECT * FROM @Table2) UNION (SELECT * FROM @Table2 EXCEPT SELECT * FROM @Table1)

Will return unque records, if the query returned no records, the data in both table are same.

Thursday, June 25, 2009

c# .net - Delete files from local drive

try
{
Microsoft.VisualBasic.FileIO.FileSystem.DeleteFile("new2");
}
catch
{
// file does not exist
}

Wednesday, June 24, 2009

C# .net – write text into a file

// create stream writer
StreamWriter writer = new StreamWriter("new");
try
{
writer1 = new StreamWriter("C:\\Program Files\\pdf995\\res\\PDF995.ini");
}
catch
{
file does not exist write to another file
}

Tuesday, June 23, 2009

c# Word automation - simplest way to create word doc in windows application

WordAuto word = new WordAuto();
ArrayList array = new ArrayList();

array.Insert(0,Name.Text);
array.Insert(1,Age.Text);
array.Insert(2,Designation.Text);

word.CreateFile(array);