الجمعة، 21 أكتوبر 2011

Writing a Simple SharePoint Console App Step By Step



Example #1   ( to display the title of root web site )

Note
-          Create Console Application and choose framework 3.5

// You Need to Add Microsoft.SharePoint Dll from references.

using Microsoft.SharePoint; 
namespace ConsoleApplication6
{
    class Program
    {
        static void Main(string[] args)
        {
            string siteUrl = "http://win-rtt4l2rllsg/sites/test/";
            using (SPSite  sp=new SPSite(siteUrl))
            {
                Console.WriteLine(sp.RootWeb.Title);
            }
        }
    }
}

If you try to run you will relieve the following exception because by default VS 2010 run under 32 bit so we need to change the properties of Application to 64 bit.



To change to 64 bit




Example #2   ( to display all list in root site )

using System;
using Microsoft.SharePoint;

namespace ConsoleApplication6
{
    class Program
    {
        static void Main(string[] args)
    {
            string siteUrl = "http://win-rtt4l2rllsg/sites/test/";
            using (SPSite  sp=new SPSite(siteUrl))
            {
                foreach (SPList list in sp.RootWeb.Lists)
                {
                    Console.WriteLine(list.Title);
                }
            }
        }
    }
}
Result

0 التعليقات: