Friday, October 12, 2012

Drag And Drop Functionality for ListBox

This code implements drag and drop functionality to listbox

        private void listBox1_DragEnter(object sender, DragEventArgs e)
        {
            if (e.Data.GetDataPresent(DataFormats.FileDrop))
            e.Effects = DragDropEffects.Copy;
        }

        private void listBox1_Drop(object sender, DragEventArgs e)
        {
            string[] files = (string[])e.Data.GetData(DataFormats.FileDrop);
            foreach (string file in files)
            {
                listBox1.Items.Add(file);
            }
        }

Insert a HTML Tag into webpage in c#

This code will insert a specified tag into the webpage programatically.
public static void GenerateJsTag(this TemplateControl page, string jsCode)
{
 var jsLink = new HtmlGenericControl {TagName = "script", InnerHtml = jsCode }; jsLink.Attributes.Add("type", "text/javascript");
 page.Controls.Add(jsLink);
}

Insert Bulk Records From Text File


This SQL command bulk inserts records from a flat file like .txt and .csv into  the SQL Table
BULK INSERT Table1
FROM 'C:\TextFile.txt'
WITH(FIELDTERMINATOR =',' , ROWTERMINATOR = '\n')