Category: Uncategorized

Programatically adding column to sharepoint list, code to add column to list

Create new console application in VS and add following code in program.cs file. also add refrence to Microsoft.Sharepoint.dll

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.SharePoint;
namespace AddColumntoList
{
    class Program
    {
        static void Main(string[] args)
        {
            do
            {
                try
                {
                    Console.WriteLine(“–Add Column to list–“);
                    Console.WriteLine(“Enter Site URL : “);
                    String str_siteurl = Console.ReadLine();
                    using (SPSite siteColl = new SPSite(str_siteurl))
                    {
                        Console.WriteLine(“Site Found”);
                        siteColl.AllowUnsafeUpdates = true;
                        using (SPWeb rootweb = siteColl.OpenWeb())
                        {
                            rootweb.AllowUnsafeUpdates = true;
                            //Console.WriteLine(“Site Found”);
                            Console.WriteLine(“Enter List Name: “);
                            string listName = Console.ReadLine();
                            SPList testList = rootweb.Lists[listName];
                            Console.WriteLine(“list Found”);
                            Console.WriteLine(“Enter Column Name: “);
                            String colName = Console.ReadLine();
                            Console.WriteLine(“Select Type Of Column:-“);
                            Console.WriteLine(“1. Single line Text”);
                            Console.WriteLine(“2. MultiLine Text”);
                            Console.WriteLine(“Enter Choice number:- “);

                            string typeChoice = Console.ReadLine();
                            switch (typeChoice)
                            {
                                case “1”:
                                    SPFieldText newcolumn = (SPFieldText)testList.Fields.CreateNewField(SPFieldType.Text.ToString(), colName);
                                    testList.Fields.Add(newcolumn);
                                    break;
                                case “2”:
                                    SPFieldMultiLineText newcolumnMul = (SPFieldMultiLineText)testList.Fields.CreateNewField(SPFieldType.Note.ToString(), colName);
                                    testList.Fields.Add(newcolumnMul);
                                    break;
                            }

                            //    newcolumn.Required = false;
                            //newcolumn.Description = “comma seperated value”;
                            //testList.Fields.Add(newcolumn);
                            testList.Update();
                            Console.WriteLine(“Column Created”);

                            Console.WriteLine(“Add Colum to Default View y/n??? :-“);
                            string defChoice = Console.ReadLine();
                            if (defChoice == “y” || defChoice == “Y”)
                            {
                                SPView defView = testList.DefaultView;
                                defView.ViewFields.Add(colName);
                                defView.Update();
                                Console.WriteLine(“Column added to default view”);
                            }
                            rootweb.AllowUnsafeUpdates = false;
                        }
                        siteColl.AllowUnsafeUpdates = false;
                    }
                }
                catch (Exception ex)
                {
                    Console.WriteLine(“ERROR : ” + ex.Message);
                    Console.WriteLine(“Press Enter to Continue and ESC to exit…”);
                }
            } while (Console.ReadKey(true).Key != ConsoleKey.Escape);
            Console.WriteLine(“Press Enter to Exit…”);
            Console.ReadLine();
        }
    }
}

javascript to move images on google

Very interesting…. magic of programming
Do try this once

1. Open Internet Explorer
2. Go to Google.com
3. Type “Flowers” or any other nice flower/animal word or anything which search pictures.
4. You will get a page which is having full of images
5. Then delete the URL from the address bar and paste the following script

javascript:R= 0; x1=.1; y1=.05; x2=.25; y2=.24; x3=1.6; y3=.24; x4=300; y4=200; x5=300; y5=200; DI= document.images; DIL=DI.length; function A(){for(i=0; i<DIL; i++){DIS=DI[ i ].style; DIS.position= 'absolute' ; DIS.left=Math. sin(R*x1+ i*x2+x3)* x4+x5; DIS.top=Math. cos(R*y1+ i*y2+y3)* y4+y5}R++ }setInterval( 'A()',5); void(0)

6. press enter
7. See the magic of programming