First Create a Console application in Visual studio like this
file->new project->console application
now add sharepoint dell to this solution like this
right click on the references->search about sharepoint from the top right search bar->check it and click ok
now write the programm like this
using Microsoft.SharePoint;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace ConsoleApplication1
{
class Program
{
static void Main(string[] args)
{
//make changes based on your site url
string siteurl = "http://winserver2012:10007/sites/Procurement";
using (SPSite site = new SPSite(siteurl))
{
//all site users in your sharepoint site
//foreach (var users in site.RootWeb.SiteUsers)
//{
// Console.WriteLine(users);
//}
//createng list in sharepoint
SPWeb web = site.OpenWeb();
SPListCollection lists = web.Lists;
//createing generic list
lists.Add("My List", "My list Description", SPListTemplateType.GenericList);
SPList list = web.Lists["My List"];
// create Text type new column called "My Column"
list.Fields.Add("My Column", SPFieldType.Text, true);
// make new column visible in default view
SPView view = list.DefaultView;
view.ViewFields.Add("My Column");
view.Update();
}
Console.ReadKey();
}
}
}
file->new project->console application
now add sharepoint dell to this solution like this
right click on the references->search about sharepoint from the top right search bar->check it and click ok
now write the programm like this
using Microsoft.SharePoint;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace ConsoleApplication1
{
class Program
{
static void Main(string[] args)
{
//make changes based on your site url
string siteurl = "http://winserver2012:10007/sites/Procurement";
using (SPSite site = new SPSite(siteurl))
{
//all site users in your sharepoint site
//foreach (var users in site.RootWeb.SiteUsers)
//{
// Console.WriteLine(users);
//}
//createng list in sharepoint
SPWeb web = site.OpenWeb();
SPListCollection lists = web.Lists;
//createing generic list
lists.Add("My List", "My list Description", SPListTemplateType.GenericList);
SPList list = web.Lists["My List"];
// create Text type new column called "My Column"
list.Fields.Add("My Column", SPFieldType.Text, true);
// make new column visible in default view
SPView view = list.DefaultView;
view.ViewFields.Add("My Column");
view.Update();
}
Console.ReadKey();
}
}
}
here hi-lighted one should be already existing site collection
now check your sharepoint site collection(procurement)->settings(from top right settings icon)->site contents-> you will find the new site collection here ...
No comments:
Post a Comment