<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>Sharepoint Server &#187; MOSS &#8211; Quick Look</title>
	<atom:link href="http://www.fivenumber.com/category/moss-quick-look/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.fivenumber.com</link>
	<description>It&#039;s all about SharePoint</description>
	<lastBuildDate>Tue, 03 Jan 2012 16:33:44 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.1</generator>
<image>
<link>http://www.fivenumber.com</link>
<url>http://www.fivenumber.com/wp-content/mbp-favicon/5.jpg</url>
<title>Sharepoint Server</title>
</image>
		<item>
		<title>A quick look on Sharepoint object model programs &#8211; Part 2</title>
		<link>http://www.fivenumber.com/a-quick-look-on-sharepoint-object-model-programs-part-2/</link>
		<comments>http://www.fivenumber.com/a-quick-look-on-sharepoint-object-model-programs-part-2/#comments</comments>
		<pubDate>Mon, 29 Mar 2010 12:04:03 +0000</pubDate>
		<dc:creator>G Vijai Kumar</dc:creator>
				<category><![CDATA[MOSS - Object Model]]></category>
		<category><![CDATA[MOSS - Quick Look]]></category>
		<category><![CDATA[Custom Webparts]]></category>
		<category><![CDATA[Sharepoint]]></category>
		<category><![CDATA[Webparts]]></category>

		<guid isPermaLink="false">http://www.fivenumber.com/?p=684</guid>
		<description><![CDATA[In my previous post you can have a quick look on Sharepoint object model programs &#8211; Part 1 Here, once again am going to post Sharepoint object model programs (part 2) with minimum lines of code and are really handy, which are actually most useful even. Show only BLOG sites: //STS#0 &#8211; Team Site //STS#1 [...]]]></description>
			<content:encoded><![CDATA[<p>In my previous post you can have <a title="A quick look on Sharepoint object model programs" href="http://www.fivenumber.com/a-quick-look-on-sharepoint-object-model-programs/" target="_blank">a quick look on Sharepoint object model programs &#8211; Part 1</a></p>
<p>Here, once again am going to post Sharepoint object model programs (part 2) with minimum lines of code and are really handy, which are actually most useful even.</p>
<p><strong>Show only BLOG sites:</strong></p>
<p>        //STS#0   &#8211;   Team Site<br />
        //STS#1   &#8211;   Blank Site<br />
        //STS#2   &#8211;   Document Workspace<br />
        //MPS#0   &#8211;   Basic Meeting Workspace<br />
        //MPS#1   &#8211;   Blank Meeting Workspace<br />
        //MPS#2   &#8211;   Decision Meeting Workspace<br />
        //MPS#3   &#8211;   Social Meeting Workspace<br />
        //MPS#4   &#8211;   Multipage Meeting Workspace<br />
        //WIKI#0  &#8211;   Wiki<br />
        //BLOG#0  &#8211;   Blog</p>
<pre class="brush: csharp; title: ; notranslate">static void Main(string[] args)
        {
            SPSite site = new SPSite(&quot;http://servername:port&quot;);
            foreach (SPWeb web in site.AllWebs)
            {
                string template = web.WebTemplate + &quot;#&quot; + web.Configuration;
                if (template.ToUpper() == &quot;BLOG#0&quot;)
                {
                    Console.WriteLine(web.Title);
                }
            }
            Console.WriteLine(&quot;Press any key to continue.....&quot;);
            Console.ReadLine();
        }
</pre>
<p><strong>Show services and status in Sharepoint server farm:</strong></p>
<pre class="brush: csharp; title: ; notranslate">static void Main(string[] args)
        {
            SPServiceCollection services = SPFarm.Local.Services;
            foreach (SPService service in services)
            {
                Console.WriteLine(&quot;Service Name: {0}&quot;, service.Name);
                Console.WriteLine(&quot;Service Status: {0}&quot;, service.Status);
                Console.WriteLine(&quot;-------------------------------------&quot;);
            }
            Console.WriteLine(&quot;Press any key to continue.....&quot;);
            Console.ReadLine();
        }
</pre>
<p><strong>Adding/Retrieving values to property bag:</strong></p>
<pre class="brush: csharp; title: ; notranslate">static void Main(string[] args)
        {
            using (SPSite siteCollection = new SPSite(&quot;http://servername:port&quot;))
            {
                using (SPWeb site = siteCollection.RootWeb)
                {
                    site.Properties.Add(&quot;TempKey&quot;, &quot;TempValue&quot;);//Adding value
                    site.Properties.Update();

                    Console.WriteLine(site.Properties[&quot;TempKey&quot;]);//Reading value
                }
            }
            Console.WriteLine(&quot;Press any key to continue.....&quot;);
            Console.ReadLine();
        }
</pre>
<p><strong>Read files in a folder:</strong></p>
<pre class="brush: csharp; title: ; notranslate">static void Main(string[] args)
        {
            SPSite site = new SPSite(&quot;http://servername:port&quot;);
            SPWeb web = site.OpenWeb();
            SPFolder folder = web.GetFolder(&quot;Shared Documents&quot;);
            SPFileCollection files = folder.Files;
            foreach (SPFile file in files)
            {
                Console.WriteLine(file.Name.ToString());
            }
            Console.WriteLine(&quot;Press any key to continue.....&quot;);
            Console.ReadLine();
        }
</pre>
<p><strong>Get content database for all site collections:</strong></p>
<pre class="brush: csharp; title: ; notranslate">
 static void Main(string[] args)
        {
                SPSite site = new SPSite(&quot;http://CentralAdminSiteURL&quot;);
                SPFarm farm = site.WebApplication.Farm;
                SPWebService service = farm.Services.GetValue&lt;SPWebService&gt;(&quot;&quot;);
                foreach (SPWebApplication webapp in service.WebApplications)
                {
                    foreach (SPSite mysite in webapp.Sites)
                    {
                        Console.WriteLine(mysite.Url+&quot; ----- &quot;+ mysite.ContentDatabase.Name);
                    }
                }
            Console.WriteLine(&quot;Press any key to continue.....&quot;);
            Console.ReadLine();
        }
</pre>
]]></content:encoded>
			<wfw:commentRss>http://www.fivenumber.com/a-quick-look-on-sharepoint-object-model-programs-part-2/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
		<item>
		<title>A quick look on Sharepoint object model programs</title>
		<link>http://www.fivenumber.com/a-quick-look-on-sharepoint-object-model-programs/</link>
		<comments>http://www.fivenumber.com/a-quick-look-on-sharepoint-object-model-programs/#comments</comments>
		<pubDate>Thu, 24 Sep 2009 13:11:16 +0000</pubDate>
		<dc:creator>G Vijai Kumar</dc:creator>
				<category><![CDATA[MOSS - Object Model]]></category>
		<category><![CDATA[MOSS - Quick Look]]></category>
		<category><![CDATA[Custom Webparts]]></category>
		<category><![CDATA[Sharepoint]]></category>
		<category><![CDATA[Webparts]]></category>

		<guid isPermaLink="false">http://www.fivenumber.com/?p=578</guid>
		<description><![CDATA[Here I am going to show you that the actions which we perform normally with UI, those also can be done programmatically, the same thing I am going to show in this post, this post is mainly targeted for beginners those who are new to Sharepoint object model, a quick watch on programs to create [...]]]></description>
			<content:encoded><![CDATA[<p>Here I am going to show you that the actions which we perform normally with UI, those also can be done programmatically, the same thing I am going to show in this post, this post is mainly targeted for beginners those who are new to Sharepoint object model, a quick watch on programs to create sub sites, lists, showing web apps etc.<br />
<strong>Creating Sub Site:</strong></p>
<pre name="code" class="c-sharp">
static void Main(string[] args)
{
SPSite mySite = new SPSite("http://servername:port");
SPWeb myWeb = mySite.OpenWeb();
SPWebCollection myWebCol = myWeb.Webs;
SPWeb mynewweb = myWebCol.Add("Web url", "Web Title", "Web Description", 1033, "STS#0", false, false);
Console.WriteLine("Press any key to continue.....");
Console.ReadLine();
}
</pre>
<p><strong>Creating List:</strong></p>
<pre name="code" class="c-sharp">
static void Main(string[] args)
{
SPSite mySite = new SPSite("http://servername:port");
SPWeb myWeb = mySite.OpenWeb();
myWeb.Lists.Add("My New List", "My new list description", myWeb.ListTemplates["Custom List"]);
SPList newList = myWeb.Lists["My New List"];
newList.OnQuickLaunch = true;
newList.Update();
Console.WriteLine("Press any key to continue.....");
Console.ReadLine();
}
</pre>
<p><strong>Show all top-level sites in a farm</strong></p>
<pre name="code" class="c-sharp">
static void Main()        
 {
 foreach (SPWebApplication myWebApp in SPWebService.ContentService.WebApplications)
 {
 foreach (SPSite mySiteCol in myWebApp.Sites)
 {
 try
 {
 Console.WriteLine(mySiteCol.Url);
 }
 catch (Exception e)
 {
 Console.WriteLine(e);
 }                   
 }
 }
 Console.WriteLine("Press any key to continue.....");
 Console.ReadLine();
 }
</pre>
<p><strong>Show all site collection in web application:</strong></p>
<pre name="code" class="c-sharp">
static void Main(string[] args)
{
SPSite mySite = new SPSite("http://servername:port");
SPWebApplication myWebApp = mySite.WebApplication;
SPSiteCollection mySiteCol = myWebApp.Sites;
foreach (SPSite SingleSite in mySiteCol)
{
Console.WriteLine(SingleSite.Url.ToString());
}
Console.WriteLine("Press any key to continue.....");
Console.ReadLine();
}
</pre>
<p><strong>Show all subsites in site collection:</strong></p>
<pre name="code" class="c-sharp">
static void Main(string[] args)
{
SPSite mySite = new SPSite("http://servername:port");
foreach (SPWeb myWeb in mySite.AllWebs)
{
Console.WriteLine(myWeb.Url.ToString());
}
Console.WriteLine("Press any key to continue.....");
Console.ReadLine();
}
</pre>
<p><strong>Show all Roles in a site:</strong></p>
<pre name="code" class="c-sharp">
static void Main(string[] args)
{
SPSite mySite = new SPSite("http://servername:port");
SPWeb myWeb = mySite.OpenWeb();
foreach (SPRoleDefinition myRoleDef in myWeb.RoleDefinitions)
{
Console.WriteLine(myRoleDef.Name);
}
Console.WriteLine("Press any key to continue.....");
Console.ReadLine();
}
</pre>
<p><strong>Show all Alerts in a site:</strong></p>
<pre name="code" class="c-sharp">
static void Main(string[] args)
{
SPSite mySite = new SPSite("http://servername:port");
SPWeb myWeb = mySite.OpenWeb();
foreach (SPAlert myAlerts in myWeb.Alerts)
{
Console.WriteLine(myAlerts.Title);
}
Console.WriteLine("Press any key to continue.....");
Console.ReadLine();
}
</pre>
<p><strong>Show all Lists in a site:</strong></p>
<pre name="code" class="c-sharp">
static void Main(string[] args)
{
SPSite mySite = new SPSite("http://servername:port");
SPWeb myWeb = mySite.OpenWeb();
foreach (SPList myList in myWeb.Lists)
{
Console.WriteLine(myList.Title.ToString());
}
Console.WriteLine("Press any key to continue.....");
Console.ReadLine();
}
</pre>
<p><strong>Show all List Templates in a site:</strong></p>
<pre name="code" class="c-sharp">
static void Main(string[] args)
{
SPSite mySite = new SPSite("http://servername:port");
SPWeb myWeb = mySite.OpenWeb();
foreach (SPListTemplate myListTemplate in myWeb.ListTemplates)
{
Console.WriteLine(myListTemplate.Name);
}
Console.WriteLine("Press any key to continue.....");
Console.ReadLine();
}
</pre>
<p><strong>Show all Fields in a List:</strong></p>
<pre name="code" class="c-sharp">
static void Main(string[] args)
{
SPSite mySite = new SPSite("http://servername:port");
SPWeb myWeb = mySite.OpenWeb();
SPList myList = myWeb.Lists["List Name"];
foreach (SPField myField in myList.Fields)
{
Console.WriteLine(myField.InternalName);
}
Console.WriteLine("Press any key to continue.....");
Console.ReadLine();
}
</pre>
<p><strong>Show all Items in a List column:</strong></p>
<pre name="code" class="c-sharp">
static void Main(string[] args)
{
SPSite mySite = new SPSite("http://servername:port");
SPWeb myWeb = mySite.OpenWeb();
SPList myList = myWeb.Lists["List Name"];
SPQuery myQuery = new SPQuery();
myQuery.Query = "";//Your Query
SPListItemCollection myItemCol = myList.GetItems(myQuery);
foreach (SPListItem myListItem in myItemCol)
{
Console.WriteLine(myListItem["Column Name"].ToString());
}
Console.WriteLine("Press any key to continue.....");
Console.ReadLine();
}
</pre>
<p><strong>Delete all Items from a list:</strong></p>
<pre name="code" class="c-sharp">
static void Main(string[] args)
{
SPSite mySite = new SPSite("http://servername:port");
SPWeb myWeb = mySite.OpenWeb();
SPList myList=myWeb.Lists["List Name"];
myWeb.AllowUnsafeUpdates = true;
int count = 1;
for (int i = 0; i < myList.ItemCount; i++)
{
SPListItem myListitem = myList.Items[0];
myListitem.Delete();
Console.WriteLine(count + " item(s) deleted");
count++;
}
myWeb.AllowUnsafeUpdates = false;
Console.WriteLine("Press any key to continue.....");
Console.ReadLine();
}
</pre>
<p><strong>Show all Groups in a site:</strong></p>
<pre name="code" class="c-sharp">
static void Main(string[] args)
{
SPSite mySite = new SPSite("http://servername:port");
SPWeb myWeb = mySite.OpenWeb();
foreach (SPGroup myGroup in myWeb.Groups)
{
Console.WriteLine(myGroup.Name);
}
Console.WriteLine("Press any key to continue.....");
Console.ReadLine();
}
</pre>
<p><strong>Show all Users in a group:</strong></p>
<pre name="code" class="c-sharp">
static void Main(string[] args)
{
SPSite mySite = new SPSite("http://servername:port");
SPWeb myWeb = mySite.OpenWeb();
SPGroup myGroup = myWeb.Groups["Group Name"];
foreach (SPUser myUser in myGroup.Users)
{
Console.WriteLine(myUser.Name);
}
Console.WriteLine("Press any key to continue.....");
Console.ReadLine();
}
</pre>
<p><strong>Show all Users in a group from UserCollection:</strong></p>
<pre name="code" class="c-sharp">
static void Main(string[] args)
        {
            SPSite mySite = new SPSite("http://servername:port");
            SPWeb myWeb = mySite.OpenWeb();
            SPUserCollection myUserCollection = myWeb.Groups["Group Name"].Users;
            foreach (SPUser myUser in myUserCollection)
            {
                Console.WriteLine(myUser.LoginName);
            }
            Console.WriteLine("Press any key to continue.....");
            Console.ReadLine();
        }
</pre>
]]></content:encoded>
			<wfw:commentRss>http://www.fivenumber.com/a-quick-look-on-sharepoint-object-model-programs/feed/</wfw:commentRss>
		<slash:comments>8</slash:comments>
		</item>
	</channel>
</rss>

