<?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; Object Model</title>
	<atom:link href="http://www.fivenumber.com/category/moss-object-model/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>Most Common Custom WebParts Part 4 – Flash Media WebPart</title>
		<link>http://www.fivenumber.com/most-common-custom-webparts-part-4-%e2%80%93-flash-media-webpart/</link>
		<comments>http://www.fivenumber.com/most-common-custom-webparts-part-4-%e2%80%93-flash-media-webpart/#comments</comments>
		<pubDate>Sun, 28 Nov 2010 21:33:53 +0000</pubDate>
		<dc:creator>G Vijai Kumar</dc:creator>
				<category><![CDATA[MOSS - Object Model]]></category>
		<category><![CDATA[Sharepoint 2010]]></category>
		<category><![CDATA[SharePoint 2010 - Object Model]]></category>
		<category><![CDATA[Custom Webparts]]></category>
		<category><![CDATA[Sharepoint]]></category>

		<guid isPermaLink="false">http://www.fivenumber.com/?p=895</guid>
		<description><![CDATA[In my previous post you can view the most commonly used custom webparts, Tree View WebPart Shows Sites and Sub-Sites, Menu WebPart Shows Sites and Sub-Sites in Fly-Out Mode, Windows Media Player WebPart In this continuation series of most commonly used custom webparts, I come up with a simple Flash Player webpart which plays flash [...]]]></description>
			<content:encoded><![CDATA[<p>In my previous post you can view the most commonly used custom webparts, Tree View WebPart Shows Sites and Sub-Sites, Menu WebPart Shows Sites and Sub-Sites in Fly-Out Mode, Windows Media Player WebPart</p>
<p>In this continuation series of most commonly used custom webparts, I come up with a simple Flash Player webpart which plays flash files on Sharepoint sites, the webpart also supports to configure the properties as required.</p>
<p>Download the solution file <a title="Flash Media Player WebPart Solution" href="www.fivenumber.com/wp-content/uploads/2010/11/FlashWebPart.wsp" target="_blank">FlashWebPart.wsp</a></p>
<div id="attachment_896" class="wp-caption aligncenter" style="width: 310px"><a href="http://www.fivenumber.com/wp-content/uploads/2010/11/18.jpg" rel="lightbox[895]"><img class="size-medium wp-image-896" title="Flash Media Player WebPart" src="http://www.fivenumber.com/wp-content/uploads/2010/11/18-300x218.jpg" alt="Flash Media Player WebPart" width="300" height="218" /></a><p class="wp-caption-text">Flash Media Player WebPart</p></div>
<div id="attachment_897" class="wp-caption aligncenter" style="width: 200px"><a href="http://www.fivenumber.com/wp-content/uploads/2010/11/33.jpg" rel="lightbox[895]"><img class="size-medium wp-image-897" title="Flash Media Player WebPart Configuration" src="http://www.fivenumber.com/wp-content/uploads/2010/11/33-190x300.jpg" alt="Flash Media Player WebPart Configuration" width="190" height="300" /></a><p class="wp-caption-text">Flash Media Player WebPart Configuration</p></div>
<pre class="brush: csharp; title: ; notranslate">
using System;
using System.ComponentModel;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using Microsoft.SharePoint;
using Microsoft.SharePoint.WebControls;

namespace FlashWebPart.Flash
{
    [ToolboxItemAttribute(false)]
    public class Flash : WebPart
    {
        // Visual Studio might automatically update this path when you change the Visual Web Part project item.
        //private const string _ascxPath = @&quot;~/_CONTROLTEMPLATES/FlashWebPart/Flash/FlashWebPartUserControl.ascx&quot;;

        private string flashFilePath = &quot;http://www.adobe.com/content/dam/Adobe/en/devnet/flash/samples/time_1/1_timer.swf&quot;;
        private string flashWidth = &quot;320&quot;;
        private string flashHeight = &quot;240&quot;;
        private string bgColor = string.Empty;
        private bool loopPlayBack = true;

        [WebBrowsable(true),
        Personalizable(PersonalizationScope.User),
        WebDescription(&quot;Specifies the media file location&quot;),
        Category(&quot;Flash Media Properties&quot;),
        WebDisplayName(&quot;Media File Location&quot;)]
        public string FlashFilePath
        {
            get { return flashFilePath; }
            set { flashFilePath = value; }
        }

        [WebBrowsable(true),
        Personalizable(PersonalizationScope.User),
        WebDescription(&quot;Sets the width of the Media player&quot;),
        Category(&quot;Flash Media Properties&quot;),
        WebDisplayName(&quot;Width&quot;)]
        public string FlashWidth
        {
            get { return flashWidth; }
            set { flashWidth = value; }
        }

        [WebBrowsable(true),
        Personalizable(PersonalizationScope.User),
        WebDescription(&quot;Sets the height of the Media player&quot;),
        Category(&quot;Flash Media Properties&quot;),
        WebDisplayName(&quot;Height&quot;)]
        public string FlashHeight
        {
            get { return flashHeight; }
            set { flashHeight = value; }
        }

        [WebBrowsable(true),
        Personalizable(PersonalizationScope.User),
        WebDescription(&quot;Background Color: Specifies the back color&quot;),
        Category(&quot;Flash Media Properties&quot;),
        WebDisplayName(&quot;Background Color&quot;)]
        public string BGColor
        {
            get { return bgColor; }
            set { bgColor = value; }
        }

        [WebBrowsable(true),
        Personalizable(PersonalizationScope.User),
        WebDescription(&quot;Loop Play Back: (True/False) Repeats the video automatically&quot;),
        Category(&quot;Flash Media Properties&quot;),
        WebDisplayName(&quot;Loop Play Back&quot;)]
        public bool LoopPlayBack
        {
            get { return loopPlayBack; }
            set { loopPlayBack = value; }
        }

        //protected override void CreateChildControls()
        //{
        //    Control control = Page.LoadControl(_ascxPath);
        //    Controls.Add(control);
        //}

        protected override void Render(HtmlTextWriter writer)
        {
            SPSite site = null;
            SPWeb web = SPContext.Current.Web;
            if (!string.IsNullOrEmpty(FlashFilePath) &amp;&amp; !string.IsNullOrEmpty(FlashWidth) &amp;&amp; !string.IsNullOrEmpty(FlashHeight))
            {
                try
                {
                    SPSecurity.RunWithElevatedPrivileges(delegate()
                    {
                        site = new SPSite(web.Site.ID);

                        using (site)
                        {
                            #region Script
                            writer.Write(&quot;&lt;OBJECT classid='clsid:D27CDB6E-AE6D-11cf-96B8-444553540000' codebase='http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=6,0,0,0' width='&quot; + FlashWidth + &quot;' height='&quot; + FlashWidth + &quot;'&gt;&quot;);
                            writer.Write(&quot;&lt;param name='movie' value='&quot; + FlashFilePath + &quot;'&gt;&quot;);
                            writer.Write(&quot;&lt;param name='bgcolor' value='&quot; + BGColor + &quot;'&gt;&quot;);
                            writer.Write(&quot;&lt;param name='loop' value='&quot; + LoopPlayBack + &quot;'&gt;&quot;);
                            writer.Write(&quot;&lt;EMBED src='&quot; + FlashFilePath + &quot;' quality='high' bgcolor='#FFFFFF' width='&quot; + FlashWidth + &quot;' height='&quot; + FlashHeight + &quot;' loop='&quot; + LoopPlayBack + &quot;' type='application/x-shockwave-flash' pluginspage='http://www.macromedia.com/shockwave/download/index.cgi?P1_Prod_Version=ShockwaveFlash'&gt;&quot;);
                            writer.Write(&quot;&lt;/EMBED&gt;&quot;);
                            writer.Write(&quot;&lt;/OBJECT&gt;&quot;);
                            #endregion
                        }
                    });
                }
                catch (Exception ex)
                {
                    writer.Write(ex.Message);
                }
            }
            else
            {
                writer.Write(&quot;&lt;span class='ms-formvalidation'&gt;&quot;);
                writer.Write(&quot;Please configure the &lt;B&gt;Media WebPart&lt;/B&gt; properties in webpart properties section&quot;);
                writer.Write(&quot;&lt;/span&gt;&quot;);
            }
        }
    }
}
</pre>
]]></content:encoded>
			<wfw:commentRss>http://www.fivenumber.com/most-common-custom-webparts-part-4-%e2%80%93-flash-media-webpart/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Most Common Custom WebParts Part 3 – Windows OR YouTube Media Player WebPart</title>
		<link>http://www.fivenumber.com/most-common-custom-webparts-part-3-%e2%80%93-windows-media-player-webpart/</link>
		<comments>http://www.fivenumber.com/most-common-custom-webparts-part-3-%e2%80%93-windows-media-player-webpart/#comments</comments>
		<pubDate>Sun, 28 Nov 2010 10:35:09 +0000</pubDate>
		<dc:creator>G Vijai Kumar</dc:creator>
				<category><![CDATA[MOSS - Object Model]]></category>
		<category><![CDATA[SharePoint 2010 - Object Model]]></category>
		<category><![CDATA[Custom Webparts]]></category>
		<category><![CDATA[Sharepoint 2010]]></category>

		<guid isPermaLink="false">http://www.fivenumber.com/?p=887</guid>
		<description><![CDATA[In my previous post you can view the most commonly used custom webparts, Tree View WebPart Shows Sites and Sub-Sites and Menu WebPart Shows Sites and Sub-Sites in Fly-Out Mode Now I got one more chance to continue the series of most commonly used custom webparts, so once again I come up with a simple [...]]]></description>
			<content:encoded><![CDATA[<p>In my previous post you can view the most commonly used custom webparts, <a title="Tree View WebPart Shows Sites and Sub-Sites" href="http://www.fivenumber.com/most-common-custom-webparts-part1-tree-view-webpart-shows-sites-and-sub-sites/" target="_blank">Tree View WebPart Shows Sites and Sub-Sites</a> and <a title="Menu WebPart Shows Sites and Sub-Sites in Fly-Out Mode" href="http://www.fivenumber.com/most-common-custom-webparts-part-2-%E2%80%93-menu-webpart-shows-sites-and-sub-sites-in-fly-out-mode/" target="_blank">Menu WebPart Shows Sites and Sub-Sites in Fly-Out Mode</a></p>
<p>Now I got one more chance to continue the series of most commonly used custom webparts, so once again I come up with a simple Windows Or Youtube Media Player webpart which plays video on Sharepoint sites, the webpart also supports to configure the properties as required.</p>
<p>In the webpart properties section please enter the Windows media or Youtube link, the webpart automatically detects the media type and plays accordingly</p>
<p>Download the solution file <a title="Windows OR Youtube Media WebPart Solution" href="http://fivenumber.com/wp-content/uploads/2012/01/WindowsORYouTubeMediaWebPart.wsp" target="_blank">WindowsORYouTubeMediaWebPart.wsp</a></p>
<div id="attachment_941" class="wp-caption aligncenter" style="width: 269px"><a href="http://www.fivenumber.com/wp-content/uploads/2010/11/Windows-OR-YouTube-Player.png" rel="lightbox[887]"><img class="size-medium wp-image-941" title="Windows Or YouTube Player WebPart (Playing Windows media Video)" src="http://www.fivenumber.com/wp-content/uploads/2010/11/Windows-OR-YouTube-Player-259x300.png" alt="Windows Or YouTube Player WebPart (Playing Windows media Video)" width="259" height="300" /></a><p class="wp-caption-text">Windows Or YouTube Player WebPart (Playing Windows media Video)</p></div>
<div id="attachment_938" class="wp-caption aligncenter" style="width: 277px"><a href="http://www.fivenumber.com/wp-content/uploads/2010/11/Windows-OR-YouTube-Player-WebPart.png" rel="lightbox[887]"><img class="size-medium wp-image-938 " title="Windows Or YouTube Player WebPart (Playing Youtube Video)" src="http://www.fivenumber.com/wp-content/uploads/2010/11/Windows-OR-YouTube-Player-WebPart-267x300.png" alt="Windows Or YouTube Player WebPart (Playing Youtube Video)" width="267" height="300" /></a><p class="wp-caption-text">Windows Or YouTube Player WebPart (Playing Youtube Video)</p></div>
<pre></pre>
<div id="attachment_943" class="wp-caption aligncenter" style="width: 310px"><a href="http://www.fivenumber.com/wp-content/uploads/2010/11/Windows-OR-YouTube-Player-WebPart-Properties1.png" rel="lightbox[887]"><img class="size-medium wp-image-943" title="Windows Or YouTube Player WebPart Properties" src="http://www.fivenumber.com/wp-content/uploads/2010/11/Windows-OR-YouTube-Player-WebPart-Properties1-300x292.png" alt="Windows Or YouTube Player WebPart Properties" width="300" height="292" /></a><p class="wp-caption-text">Windows Or YouTube Player WebPart Properties</p></div>
<pre class="brush: csharp; title: ; notranslate">
using System;
using System.ComponentModel;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using Microsoft.SharePoint;
using Microsoft.SharePoint.WebControls;

namespace WindowsMediaWebPart.MediaWebPart
{
    [ToolboxItemAttribute(false)]
    public class WindowsMedia : WebPart
    {
        // Visual Studio might automatically update this path when you change the Visual Web Part project item.
        //private const string _ascxPath = @&quot;~/_CONTROLTEMPLATES/WindowsMediaWebPart/MediaWebPart/MediaWebPartUserControl.ascx&quot;;

        private string videoFilePath = string.Empty;
        private string videoWidth = &quot;320&quot;;
        private string videoHeight = &quot;240&quot;;
        private bool animationAtStart = true;
        private bool transparentAtStart = true;
        private bool autoStart = true;
        private bool showControls = true;
        private bool loopPlayBack = true;
        private string frameBorder = &quot;0&quot;;

        [WebBrowsable(true),
        Personalizable(PersonalizationScope.User),
        WebDescription(&quot;Specifies the media file location&quot;),
        Category(&quot;Media Properties&quot;),
        WebDisplayName(&quot;Media File Location&quot;)]
        public string VideoFilePath
        {
            get { return videoFilePath; }
            set { videoFilePath = value; }
        }

        [WebBrowsable(true),
        Personalizable(PersonalizationScope.User),
        WebDescription(&quot;Sets the width of the Media player&quot;),
        Category(&quot;Media Properties&quot;),
        WebDisplayName(&quot;Width&quot;)]
        public string VideoWidth
        {
            get { return videoWidth; }
            set { videoWidth = value; }
        }

        [WebBrowsable(true),
        Personalizable(PersonalizationScope.User),
        WebDescription(&quot;Sets the height of the Media player&quot;),
        Category(&quot;Media Properties&quot;),
        WebDisplayName(&quot;Height&quot;)]
        public string VideoHeight
        {
            get { return videoHeight; }
            set { videoHeight = value; }
        }

        [WebBrowsable(true),
        Personalizable(PersonalizationScope.User),
        WebDescription(&quot;Animation At Start: (True/False)&quot;),
        Category(&quot;Media Properties&quot;),
        WebDisplayName(&quot;Animation At Start&quot;)]
        public bool AnimationAtStart
        {
            get { return animationAtStart; }
            set { animationAtStart = value; }
        }

        [WebBrowsable(true),
        Personalizable(PersonalizationScope.User),
        WebDescription(&quot;Transparent At Start: (True/False)&quot;),
        Category(&quot;Media Properties&quot;),
        WebDisplayName(&quot;Transparent At  Start&quot;)]
        public bool TransparentAtStart
        {
            get { return transparentAtStart; }
            set { transparentAtStart = value; }
        }

        [WebBrowsable(true),
        Personalizable(PersonalizationScope.User),
        WebDescription(&quot;Auto Start: (True/False) Starts the video automatically&quot;),
        Category(&quot;Media Properties&quot;),
        WebDisplayName(&quot;Auto Start&quot;)]
        public bool AutoStart
        {
            get { return autoStart; }
            set { autoStart = value; }
        }

        [WebBrowsable(true),
        Personalizable(PersonalizationScope.User),
        WebDescription(&quot;Show Controls: (True/False) Displays media player controls&quot;),
        Category(&quot;Media Properties&quot;),
        WebDisplayName(&quot;Show Controls&quot;)]
        public bool ShowControls
        {
            get { return showControls; }
            set { showControls = value; }
        }

        [WebBrowsable(true),
        Personalizable(PersonalizationScope.User),
        WebDescription(&quot;Loop Play Back: (True/False) Repeats the video automatically&quot;),
        Category(&quot;Media Properties&quot;),
        WebDisplayName(&quot;Loop Play Back&quot;)]
        public bool LoopPlayBack
        {
            get { return loopPlayBack; }
            set { loopPlayBack = value; }
        }

        [WebBrowsable(true),
        Personalizable(PersonalizationScope.User),
        WebDescription(&quot;Sets the border of the media (applicable for youtube videos)&quot;),
        Category(&quot;Media Properties&quot;),
        WebDisplayName(&quot;Allow Full Screen&quot;)]
        public string FrameBorder
        {
            get { return frameBorder; }
            set { frameBorder = value; }
        }

        protected override void CreateChildControls()
        {
            //Control control = Page.LoadControl(_ascxPath);
            //Controls.Add(control);
            this.TitleUrl = VideoFilePath;
        }

        protected override void Render(HtmlTextWriter writer)
        {
            SPSite site = null;
            SPWeb web = SPContext.Current.Web;
            if (!string.IsNullOrEmpty(VideoFilePath) &amp;&amp; !string.IsNullOrEmpty(VideoWidth) &amp;&amp; !string.IsNullOrEmpty(VideoHeight))
            {
                try
                {
                    SPSecurity.RunWithElevatedPrivileges(delegate()
                    {
                        site = new SPSite(web.Site.ID);

                        using (site)
                        {
                            if ((videoFilePath.ToLower()).Contains(&quot;youtube.com/&quot;))
                            {
                                Uri youtubeUri = new Uri(videoFilePath);
                                string query = youtubeUri.Query;
                                string mediaID = HttpUtility.ParseQueryString(query).Get(&quot;v&quot;);
                                string source = &quot;http://www.youtube.com/embed/&quot; + mediaID;
                                writer.Write(&quot;&lt;iframe width='&quot; + VideoWidth + &quot;' height='&quot; + VideoHeight + &quot;' src='&quot; + source + &quot;' frameborder='&quot; + FrameBorder + &quot;' allowfullscreen&gt;&lt;/iframe&gt;&quot;);
                            }
                            else
                            {

                                writer.Write(&quot;&lt;OBJECT id='mediaPlayer' width='&quot; + VideoWidth + &quot;' height='&quot; + VideoHeight + &quot;' classid='CLSID:22d6f312-b0f6-11d0-94ab-0080c74c7e95' codebase='http://activex.microsoft.com/activex/controls/mplayer/en/nsmp2inf.cab#Version=5,1,52,701'standby='Loading Microsoft Windows Media Player components...' type='application/x-oleobject'&gt;&quot;);
                                writer.Write(&quot;&lt;param name='fileName' value='&quot; + VideoFilePath + &quot;'&gt;&quot;);
                                writer.Write(&quot;&lt;param name='animationatStart' value='&quot; + AnimationAtStart + &quot;'&gt;&quot;);
                                writer.Write(&quot;&lt;param name='transparentatStart' value='&quot; + TransparentAtStart + &quot;'&gt;&quot;);
                                writer.Write(&quot;&lt;param name='autoStart' value='&quot; + AutoStart + &quot;'&gt;&quot;);
                                writer.Write(&quot;&lt;param name='showControls' value='&quot; + ShowControls + &quot;'&gt;&quot;);
                                writer.Write(&quot;&lt;param name='loop' value='&quot; + LoopPlayBack + &quot;'&gt;&quot;);
                                writer.Write(&quot;&lt;EMBED type='application/x-mplayer2'pluginspage='http://microsoft.com/windows/mediaplayer/en/download/'id='windowsmediaPlayer' name='windowsmediaPlayer' displaysize='4' autosize='-1' bgcolor='darkblue' showcontrols='&quot; + ShowControls + &quot;' showtracker='-1' showdisplay='0' showstatusbar='-1' videoborder3d='-1' width='&quot; + VideoWidth + &quot;' height='&quot; + VideoHeight + &quot;' src='&quot; + VideoFilePath + &quot;' autostart='&quot; + AutoStart + &quot;' designtimesp='5311' loop='&quot; + LoopPlayBack + &quot;'&gt;&lt;/EMBED&gt;&quot;);
                                writer.Write(&quot;&lt;/OBJECT&gt;&quot;);

                            }
                        }
                    });
                }
                catch (Exception ex)
                {
                    writer.Write(ex.Message);
                }
            }
            else
            {
                writer.Write(&quot;&lt;span class='ms-formvalidation'&gt;&quot;);
                writer.Write(&quot;Please configure the &lt;B&gt;Media WebPart&lt;/B&gt; properties in webpart properties section&quot;);
                writer.Write(&quot;&lt;/span&gt;&quot;);
            }
        }
    }
}
</pre>
]]></content:encoded>
			<wfw:commentRss>http://www.fivenumber.com/most-common-custom-webparts-part-3-%e2%80%93-windows-media-player-webpart/feed/</wfw:commentRss>
		<slash:comments>5</slash:comments>
		</item>
		<item>
		<title>Most Common Custom WebParts Part 2 – Menu WebPart Shows Sites and Sub-Sites in Fly-Out Mode</title>
		<link>http://www.fivenumber.com/most-common-custom-webparts-part-2-%e2%80%93-menu-webpart-shows-sites-and-sub-sites-in-fly-out-mode/</link>
		<comments>http://www.fivenumber.com/most-common-custom-webparts-part-2-%e2%80%93-menu-webpart-shows-sites-and-sub-sites-in-fly-out-mode/#comments</comments>
		<pubDate>Fri, 29 Oct 2010 05:12:49 +0000</pubDate>
		<dc:creator>G Vijai Kumar</dc:creator>
				<category><![CDATA[MOSS - Object Model]]></category>
		<category><![CDATA[Sharepoint 2010]]></category>
		<category><![CDATA[SharePoint 2010 - Object Model]]></category>
		<category><![CDATA[Custom Webparts]]></category>
		<category><![CDATA[object model]]></category>
		<category><![CDATA[Sharepoint]]></category>

		<guid isPermaLink="false">http://www.fivenumber.com/?p=832</guid>
		<description><![CDATA[In my previous post can view the most common custom webparts part 1 From last post I want to continue the series of most commonly used custom webparts, so once again I come up with a simple and small custom menu webpart shows all the sites and sub-sites of a SharePoint site in fly-out style]]></description>
			<content:encoded><![CDATA[<p>In my previous post can view the <a title="Most common custom webparts part 1" href="http://www.fivenumber.com/most-common-custom-webparts-part1-tree-view-webpart-shows-sites-and-sub-sites/" target="_blank">most common custom webparts part 1</a></p>
<p>From last post I want to continue the series of most commonly used custom webparts, so once again I come up with a simple and small custom menu webpart shows all the sites and sub-sites of a SharePoint site in fly-out style</p>
<div id="attachment_833" class="wp-caption aligncenter" style="width: 310px"><a href="http://www.fivenumber.com/wp-content/uploads/2010/10/11.png" rel="lightbox[832]"><img class="size-medium wp-image-833" title="SharePoint Menu WebPart in fly-Out Style" src="http://www.fivenumber.com/wp-content/uploads/2010/10/11-300x225.png" alt="SharePoint Menu WebPart in fly-Out Style" width="300" height="225" /></a><p class="wp-caption-text">SharePoint Menu WebPart in fly-Out Style</p></div>
<pre class="brush: csharp; title: ; notranslate">
using System;
using System.ComponentModel;
using System.Web;
using System.Drawing;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using Microsoft.SharePoint;
using Microsoft.SharePoint.WebControls;

namespace CustomWebParts.VisualWebPart1
{
    [ToolboxItemAttribute(false)]
    public class VisualWebPart1 : WebPart
    {
        // Visual Studio might automatically update this path when you change the Visual Web Part project item.
       // private const string _ascxPath = @&quot;~/_CONTROLTEMPLATES/CustomWebParts/TreeView/TreeViewUserControl.ascx&quot;;

        System.Web.UI.WebControls.Menu menu = null;

        protected override void CreateChildControls()
        {
            //Control control = Page.LoadControl(_ascxPath);
            //Controls.Add(control);

            menu = new System.Web.UI.WebControls.Menu();
            SPSite site = SPContext.Current.Site;
            SPWeb web = SPContext.Current.Web;

            menu.StaticDisplayLevels = 1;
            menu.MaximumDynamicDisplayLevels = 200;
            menu.Orientation = System.Web.UI.WebControls.Orientation.Horizontal;
            menu.StaticEnableDefaultPopOutImage = false;
            menu.StaticPopOutImageUrl = &quot;/_layouts/images/menudark.gif&quot;;
            menu.SkipLinkText = &quot;&quot;;
            menu.DynamicHoverStyle.BackColor = System.Drawing.Color.FromName(&quot;#CBE3F0&quot;);
            menu.CssClass = &quot;ms-topNavContainer&quot;;

            menu.StaticMenuItemStyle.ItemSpacing = Unit.Pixel(0);
            menu.StaticSelectedStyle.CssClass = &quot;ms-topnavselected&quot;;
            menu.StaticHoverStyle.CssClass = &quot;ms-topNavHover&quot;;

            menu.DynamicMenuStyle.BackColor = System.Drawing.Color.FromName(&quot;#F2F3F4&quot;);
            menu.DynamicMenuStyle.BorderColor = System.Drawing.Color.FromName(&quot;#A7B4CE&quot;);
            menu.DynamicMenuStyle.BorderWidth = Unit.Pixel(1);

            menu.DynamicMenuItemStyle.CssClass = &quot;ms-topNavFlyOuts&quot;;
            menu.DynamicHoverStyle.CssClass = &quot;ms-topNavFlyOutsHover&quot;;
            menu.DynamicSelectedStyle.CssClass = &quot;ms-topNavFlyOutsSelected&quot;;

            MenuItemStyle stMenuStyle = menu.StaticMenuItemStyle;
            stMenuStyle.CssClass = &quot;ms-topnav&quot;;

            stMenuStyle.HorizontalPadding = 0;
            stMenuStyle.VerticalPadding = 0;
            stMenuStyle.ItemSpacing = Unit.Pixel(0);

            MenuItemStyle dyMenuStyle = menu.DynamicMenuItemStyle;
            dyMenuStyle.CssClass = &quot;ms-topNavFlyOuts&quot;;
            dyMenuStyle.HorizontalPadding = 0;
            dyMenuStyle.VerticalPadding = 0;

            System.Web.UI.WebControls.MenuItem mItem = new System.Web.UI.WebControls.MenuItem(web.Title);
            mItem.NavigateUrl = web.Site.Url;
            menu.Items.Add(mItem);

            GenerateMenu(menu, Context);
            menu.DataBind();
            this.Controls.Add(menu);
        }

        public static void GenerateMenu(System.Web.UI.WebControls.Menu menu, HttpContext context)
        {
            SPSite site = SPContext.Current.Site;
            SPWeb web = SPContext.Current.Web;

            foreach (SPWeb subsite in web.Webs)
            {
                System.Web.UI.WebControls.MenuItem mItem = new System.Web.UI.WebControls.MenuItem();
                mItem.NavigateUrl = subsite.Url;
                mItem.Text = subsite.Title;
                mItem.ToolTip = subsite.Title;
                menu.Items.Add(mItem);
                BuildMenu(subsite, mItem, context);
            }
        }

        private static void BuildMenu(SPWeb subweb, System.Web.UI.WebControls.MenuItem mItem, HttpContext context)
        {
            SPSite site = SPContext.Current.Site;
            SPWeb web = SPContext.Current.Web;

            foreach (SPWeb subsite in subweb.Webs)
            {
                System.Web.UI.WebControls.MenuItem mSubItem = new System.Web.UI.WebControls.MenuItem();
                mSubItem.NavigateUrl = subsite.Url;
                mSubItem.Text = subsite.Title;
                mSubItem.ToolTip = subsite.Title;
                mItem.ChildItems.Add(mSubItem);
            }
        }
    }
}
</pre>
]]></content:encoded>
			<wfw:commentRss>http://www.fivenumber.com/most-common-custom-webparts-part-2-%e2%80%93-menu-webpart-shows-sites-and-sub-sites-in-fly-out-mode/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Most Common Custom WebParts Part 1 &#8211; Tree View WebPart Shows Sites and Sub-Sites</title>
		<link>http://www.fivenumber.com/most-common-custom-webparts-part1-tree-view-webpart-shows-sites-and-sub-sites/</link>
		<comments>http://www.fivenumber.com/most-common-custom-webparts-part1-tree-view-webpart-shows-sites-and-sub-sites/#comments</comments>
		<pubDate>Fri, 29 Oct 2010 04:26:07 +0000</pubDate>
		<dc:creator>G Vijai Kumar</dc:creator>
				<category><![CDATA[MOSS - Object Model]]></category>
		<category><![CDATA[Sharepoint 2010]]></category>
		<category><![CDATA[SharePoint 2010 - Object Model]]></category>
		<category><![CDATA[Custom Webparts]]></category>
		<category><![CDATA[object model]]></category>
		<category><![CDATA[Sharepoint]]></category>

		<guid isPermaLink="false">http://www.fivenumber.com/?p=825</guid>
		<description><![CDATA[I desired to support most common custom webparts used by the SharePoint professional, so that these can be helpful for them. A custom tree view webpart shows all the sites and sub-sites of a SharePoint site Please use the below code and to get the exact look as show in the aboave image, the tree [...]]]></description>
			<content:encoded><![CDATA[<p>I desired to support most common custom webparts used by the SharePoint professional, so that these can be helpful for them.<br />
A custom tree view webpart shows all the sites and sub-sites of a SharePoint site</p>
<div id="attachment_826" class="wp-caption aligncenter" style="width: 310px"><a href="http://www.fivenumber.com/wp-content/uploads/2010/10/1.png" rel="lightbox[825]"><img class="size-medium wp-image-826" title="SharePoint Custom Tree View WebPart" src="http://www.fivenumber.com/wp-content/uploads/2010/10/1-300x243.png" alt="SharePoint Custom Tree View WebPart" width="300" height="243" /></a><p class="wp-caption-text">SharePoint Custom Tree View WebPart</p></div>
<p>Please use the below code and to get the exact look as show in the aboave image, the tree view webpart can expand/collapse</p>
<pre class="brush: csharp; title: ; notranslate">
using System;
using System.ComponentModel;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using Microsoft.SharePoint;
using Microsoft.SharePoint.WebControls;

namespace CustomWebParts.CustomTreeView
{
    [ToolboxItemAttribute(false)]
    public class CustomTreeView : WebPart
    {
        // Visual Studio might automatically update this path when you change the Visual Web Part project item.
        //private const string _ascxPath = @&quot;~/_CONTROLTEMPLATES/CustomWebParts/CustomTreeView/CustomTreeViewUserControl.ascx&quot;;

        TreeView myTree;
        LinkButton lnkBtnExpand;
        LinkButton lnkBtnCollapse;
        Label lblPipeDivider;
        Label lbl_ErrorMsg;
        private string errorMessage = string.Empty;
        private int level = 0;

        protected override void CreateChildControls()
        {
            //Control control = Page.LoadControl(_ascxPath);
            //Controls.Add(control);

            this.Controls.Clear();
            myTree = new TreeView();
            myTree.ExpandImageUrl = &quot;/_layouts/images/tvplus.gif&quot;;
            myTree.RootNodeStyle.ImageUrl = &quot;/_layouts/images/stsicon.gif&quot;;
            myTree.ParentNodeStyle.ImageUrl = &quot;/_layouts/images/stsicon.gif&quot;;
            myTree.LeafNodeStyle.ImageUrl = &quot;/_layouts/images/stsicon.gif&quot;;
            myTree.CollapseImageUrl = &quot;/_layouts/images/tvminus.gif&quot;;
            myTree.NoExpandImageUrl = &quot;/_layouts/images/stsicon.gif&quot;;            

            myTree.NodeWrap = true;
            myTree.ShowLines = true;
            myTree.ShowExpandCollapse = true;
            myTree.EnableClientScript = true;

            GenerateTreeView();
            myTree.CollapseAll();
            myTree.CssClass = &quot;ms-navitem a&quot;;
            this.Controls.Add(myTree);

            lnkBtnExpand = new LinkButton();
            lnkBtnExpand.Click += new EventHandler(expandAll_Click);
            lnkBtnExpand.Text = &quot;Expand all&quot;;
            lnkBtnExpand.CssClass = &quot;ms-navitem a&quot;;
            this.Controls.Add(lnkBtnExpand);

            lblPipeDivider = new Label();
            lblPipeDivider.Text = &quot;  |  &quot;;
            this.Controls.Add(lblPipeDivider);

            lnkBtnCollapse = new LinkButton();
            lnkBtnCollapse.Click += new EventHandler(collapseAll_Click);
            lnkBtnCollapse.Text = &quot;Collapse all&quot;;
            lnkBtnCollapse.CssClass = &quot;ms-navitem a&quot;;
            this.Controls.Add(lnkBtnCollapse);

            lbl_ErrorMsg = new Label();
            this.Controls.Add(lbl_ErrorMsg);

            base.CreateChildControls();
        }

        private void GenerateTreeView()
        {
            SPSite mySite = null;
            SPWeb myWeb = SPContext.Current.Web;
            SPSecurity.RunWithElevatedPrivileges(delegate()
            {
                try
                {
                    mySite = new SPSite(myWeb.Site.ID);
                    using (mySite)
                    {
                        level = 1;
                        foreach (SPWeb subWeb in myWeb.Webs)
                        {
                            TreeNode myTreeNode = new TreeNode(subWeb.Title);
                            myTreeNode.NavigateUrl = subWeb.Url;
                            ReadSubSites(subWeb, ref myTreeNode);
                            myTree.Nodes.Add(myTreeNode);
                        }

                    }
                }
                catch (Exception ex)
                {
                    errorMessage = ex.ToString();
                }
            });
        }

        private void ReadSubSites(SPWeb subWeb, ref TreeNode myTreeNode)
        {
            try
            {
                foreach (SPWeb myChildSubWeb in subWeb.Webs)
                {
                    TreeNode subnode = new TreeNode(myChildSubWeb.Title);
                    subnode.NavigateUrl = myChildSubWeb.Url;

                    myTreeNode.ChildNodes.Add(subnode);

                    if (myChildSubWeb.Webs.Count &gt; 0)
                    {
                        if (myTreeNode.ChildNodes.Count &gt; 0)
                        {
                            level = level + 1;
                            TreeNode myChildNode = myTreeNode.ChildNodes[myTreeNode.ChildNodes.Count - 1];
                            ReadSubSites(myChildSubWeb, ref myChildNode);
                            level = level - 1;
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                errorMessage = ex.ToString();
            }
        }

        void expandAll_Click(object sender, EventArgs e)
        {
            myTree.ExpandAll();
        }

        void collapseAll_Click(object sender, EventArgs e)
        {
            myTree.CollapseAll();
        }      

        protected override void RenderContents(HtmlTextWriter writer)
        {
            EnsureChildControls();
            lnkBtnExpand.RenderControl(writer);
            lblPipeDivider.RenderControl(writer);
            lnkBtnCollapse.RenderControl(writer);
            RenderChildren(writer);
        }
    }
}
</pre>
]]></content:encoded>
			<wfw:commentRss>http://www.fivenumber.com/most-common-custom-webparts-part1-tree-view-webpart-shows-sites-and-sub-sites/feed/</wfw:commentRss>
		<slash:comments>4</slash:comments>
		</item>
		<item>
		<title>Understanding SharePoint Property Bag Settings</title>
		<link>http://www.fivenumber.com/understanding-sharepoint-property-bag-settings/</link>
		<comments>http://www.fivenumber.com/understanding-sharepoint-property-bag-settings/#comments</comments>
		<pubDate>Mon, 30 Aug 2010 16:14:23 +0000</pubDate>
		<dc:creator>G Vijai Kumar</dc:creator>
				<category><![CDATA[MOSS - Object Model]]></category>
		<category><![CDATA[object model]]></category>
		<category><![CDATA[Sharepoint]]></category>
		<category><![CDATA[Sharepoint 2010]]></category>

		<guid isPermaLink="false">http://www.fivenumber.com/?p=802</guid>
		<description><![CDATA[Today my ex-coworker and friend ask me regarding SharePoint property bag, therefore I got an opportunity of posting this article on understanding SharePoint property bag settings. SharePoint property bag is a good place where we are able to accumulate key and value like a couple, It&#8217;s a hash table. There is no such user interface [...]]]></description>
			<content:encoded><![CDATA[<p>Today my ex-coworker and friend ask me regarding SharePoint property bag, therefore I got an opportunity of posting this article on understanding SharePoint property bag settings.</p>
<p>SharePoint property bag is a good place where we are able to accumulate key and value like a couple, It&#8217;s a hash table.</p>
<p>There is no such user interface to view/add/edit/delete the property bag key-value, but there is an option to perform the actions on property bag via SharePoint designer.</p>
<p>After you open a site in SharePoint Designer, go to <strong>Site </strong>menu click on Settings option, a <strong>Site Settings</strong> dialog box opens, click on <strong>Parameters </strong>tab where you can see the list of existing properties, from the same place you can even perform add/modify/remove actions.</p>
<div id="attachment_811" class="wp-caption aligncenter" style="width: 310px"><a href="http://www.fivenumber.com/wp-content/uploads/2010/08/1.jpg" rel="lightbox[802]"><img class="size-medium wp-image-811" title="View SharePoint property bag properties using SharePoint Designer" src="http://www.fivenumber.com/wp-content/uploads/2010/08/1-300x275.jpg" alt="View SharePoint property bag properties using SharePoint Designer" width="300" height="275" /></a><p class="wp-caption-text">View SharePoint property bag properties using SharePoint Designer</p></div>
<p>Subsequently, prior to start on deep into property bag, we will discuss going on additional area some where we can store up value other than SharePoint property bag.</p>
<p><strong>web.config</strong> file is too a place where we be able to accumulate the settings such as file location, URLs, etc.<br />
Example:</p>
<pre class="brush: xml; title: ; notranslate">
&lt;configuration&gt;
    &lt;appSettings&gt;
        &lt;add key=&quot;MyKey&quot; value=&quot;MyValue&quot; /&gt;
    &lt;/appSettings&gt;
&lt;/configuration&gt;
</pre>
<p>In view of the fact that we have single global web.config file meant for complete site. If we would like to accumulate additional settings correlated to several sites we have to make multiple entries in web.config file.</p>
<p>One more method of storing the settings by creating table in database, this approach is not recommend all the time in SharePoint.</p>
<p>Even we can store values in SharePoint list by creating two columns like Keys and Values using OOTB functionality and still can access the key-value pair using object model.</p>
<p>But, if you have several settings related to different sites with some unique permissions for individuals sites then we have to decide where the list is to be created.</p>
<p>On the way to over come this situation SharePoint provided property bag to store the properties in several levels like <strong>SPFarm</strong>, <strong>SPWebApplication</strong>, <strong>SPSite</strong>, <strong>SPWeb </strong>and <strong>SPList</strong>.</p>
<p>Storing key-value in <strong>SPFarm </strong>include more danger that require farm administrator privileges.</p>
<p>Below are few examples on <strong>SPFarm</strong>, <strong>SPWebApplication</strong>, <strong>SPSite</strong>, <strong>SPWeb </strong>add/view/edit/delete property bag values.</p>
<p><strong>Add property in SPFarm level</strong></p>
<pre class="brush: csharp; title: ; notranslate">
static void Main(string[] args)
        {
            SPFarm myFarm = SPFarm.Local;
            myFarm.Properties.Add(&quot;SPFarmKey&quot;, &quot;SPFarmValue&quot;);
            myFarm.Update();
            Console.WriteLine(&quot;Press any key to continue.....&quot;);
            Console.ReadLine();
        }
</pre>
<p><strong>View SPFarm property</strong></p>
<pre class="brush: csharp; title: ; notranslate">

static void Main(string[] args)
        {
            SSPFarm myFarm = SPFarm.Local;
            if (myFarm.Properties != null &amp;&amp; myFarm.Properties.Count &gt; 0)
            {
                if (myFarm.Properties.ContainsKey(&quot;SPFarmKey&quot;))
                {
                    Console.WriteLine(myWebApplication.Properties[&quot;SPFarmKey&quot;]);
                }
            }
            Console.WriteLine(&quot;Press any key to continue.....&quot;);
            Console.ReadLine();
        }
</pre>
<p><strong>Modify property in SPFarm level</strong></p>
<pre class="brush: csharp; title: ; notranslate">

static void Main(string[] args)
        {
            SPFarm myFarm = SPFarm.Local;
            myFarm.Properties[&quot;SPFarmKey&quot;] = &quot;NewSPFarmValue&quot;;
            myFarm.Update();
            Console.WriteLine(&quot;Press any key to continue.....&quot;);
            Console.ReadLine();
        }
</pre>
<p><strong>Delete property in SPFarm level</strong></p>
<pre class="brush: csharp; title: ; notranslate">

static void Main(string[] args)
        {
            SPFarm myFarm = SPFarm.Local;
            myFarm.Properties[&quot;SPFarmKey&quot;] = null;
            myFarm.Properties.Remove(&quot;SPFarmKey&quot;);
            myFarm.Update();
            Console.WriteLine(&quot;Press any key to continue.....&quot;);
            Console.ReadLine();
        }
</pre>
<p><strong>Add property in SPWebApplication level</strong></p>
<pre class="brush: csharp; title: ; notranslate">

static void Main(string[] args)
        {
            SPWebApplication myWebApplication = SPWebApplication.Lookup(new Uri(&quot;http://WebApplicationURL&quot;));
            myWebApplication.Properties.Add(&quot;SPWebAppKey&quot;, &quot;SPWebAppValue&quot;);
            myWebApplication.Update();
            Console.WriteLine(&quot;Press any key to continue.....&quot;);
            Console.ReadLine();
        }
</pre>
<p><strong>View SPWebApplication property</strong></p>
<pre class="brush: csharp; title: ; notranslate">

static void Main(string[] args)
        {
            SPWebApplication myWebApplication = SPWebApplication.Lookup(new Uri(&quot;http://WebApplicationURL&quot;));
            if (myWebApplication.Properties != null &amp;&amp; myWebApplication.Properties.Count &gt; 0)
            {
                if (myWebApplication.Properties.ContainsKey(&quot;SPWebAppKey&quot;))
                {
                    Console.WriteLine(myWebApplication.Properties[&quot;SPWebAppKey&quot;]);
                }
            }
            Console.WriteLine(&quot;Press any key to continue.....&quot;);
            Console.ReadLine();
        }
</pre>
<p><strong>Modify property in SPWebApplication level</strong></p>
<pre class="brush: csharp; title: ; notranslate">

static void Main(string[] args)
        {
            SPWebApplication myWebApplication = SPWebApplication.Lookup(new Uri(&quot;http://WebApplicationURL&quot;));
            myWebApplication.Properties[&quot;SPWebAppKey&quot;] = &quot;NewSPWebAppValue&quot;;
            myWebApplication.Update();
            Console.WriteLine(&quot;Press any key to continue.....&quot;);
            Console.ReadLine();
        }
</pre>
<p><strong>Delete property in SPWebApplication level</strong></p>
<pre class="brush: csharp; title: ; notranslate">

static void Main(string[] args)
        {
            SPWebApplication myWebApplication = SPWebApplication.Lookup(new Uri(&quot;http://WebApplicationURL&quot;));
            myWebApplication.Properties[&quot;WebAppKey&quot;] = null;
            myWebApplication.Properties.Remove(&quot;WebAppKey&quot;);
            myWebApplication.Update();
            Console.WriteLine(&quot;Press any key to continue.....&quot;);
            Console.ReadLine();
        }
</pre>
<p>There is no facility to store properties in <strong>SPSite </strong>object similar to <strong>SPWeb </strong>object, if you want to store the settings in site collection level we have to use <strong>SPSite.RootWeb</strong></p>
<p><strong>Add/retrieve SPSite property</strong></p>
<pre class="brush: csharp; title: ; notranslate">

static void Main(string[] args)
        {
            SPSite siteCollection = new SPSite(&quot;http://servername:port&quot;);
            SPWeb site = siteCollection.RootWeb;
            //Addning SPSite Property
            site.Properties.Add(&quot;SPSiteKey&quot;, &quot;SPSiteValue&quot;);
            site.Properties.Update();

            //Reading SPSite Property
            Console.WriteLine(site.Properties[&quot;SPSiteKey&quot;]);
            Console.WriteLine(&quot;Press any key to continue.....&quot;);
            Console.ReadLine();
        }
</pre>
<p><strong>Add/retrieve SPWeb property</strong></p>
<pre class="brush: csharp; title: ; notranslate">
static void Main(string[] args)
        {
            SPSite mySite = new SPSite(&quot;http://servername:port&quot;);
            SPWeb myWeb = mySite.OpenWeb(&quot;Your Web Name.....&quot;);
            //Adding SPWeb Property
            myWeb.Properties.Add(&quot;SPWebKey&quot;, &quot;SPWebValue&quot;);
            myWeb.Properties.Update();

            //Reading SPWeb Property
            Console.WriteLine(myWeb.Properties[&quot;SPWebKey&quot;]);
            Console.WriteLine(&quot;Press any key to continue.....&quot;);
            Console.ReadLine();
        }
</pre>
]]></content:encoded>
			<wfw:commentRss>http://www.fivenumber.com/understanding-sharepoint-property-bag-settings/feed/</wfw:commentRss>
		<slash:comments>8</slash:comments>
		</item>
		<item>
		<title>A quick look on Sharepoint object model programs &#8211; Part 3</title>
		<link>http://www.fivenumber.com/a-quick-look-on-sharepoint-object-model-programs-part-3/</link>
		<comments>http://www.fivenumber.com/a-quick-look-on-sharepoint-object-model-programs-part-3/#comments</comments>
		<pubDate>Sat, 28 Aug 2010 13:55:02 +0000</pubDate>
		<dc:creator>G Vijai Kumar</dc:creator>
				<category><![CDATA[MOSS - Object Model]]></category>
		<category><![CDATA[object model]]></category>
		<category><![CDATA[Sharepoint]]></category>

		<guid isPermaLink="false">http://www.fivenumber.com/?p=770</guid>
		<description><![CDATA[I have got the chance to post useful Sharepoint object model programs (part 3) with bare minimum lines of code and really handy even. Please follow the link for a quick look on Sharepoint object model programs Part 1 and Part 2 Creating a Folder in a Document Library: Add fields to list: Creating a [...]]]></description>
			<content:encoded><![CDATA[<p>I have got the chance to post useful Sharepoint object model programs (part 3) with bare minimum lines of code and really handy even.<br />
Please follow the link for a quick look on Sharepoint object model programs <a title="A quick look on Sharepoint object model programs - Part 1" href="http://www.fivenumber.com/a-quick-look-on-sharepoint-object-model-programs/" target="_blank">Part 1</a> and <a title="A quick look on Sharepoint object model programs - Part 2" href="http://www.fivenumber.com/a-quick-look-on-sharepoint-object-model-programs-part-2/" target="_blank">Part 2</a></p>
<p><strong>Creating a Folder in a Document Library:</strong></p>
<pre class="brush: csharp; title: ; notranslate">static void Main(string[] args)
        {
            try
            {
                SPSite mySite = new SPSite(&quot;http://servername:port&quot;);
                SPWeb myWeb = mySite.OpenWeb();
                SPList MyLibrary = myWeb.Lists[&quot;Your Document Library Name.....&quot;];
                SPFolder myFolder = MyLibrary.RootFolder;
                SPFolder myChildFolder = myFolder.SubFolders.Add(&quot;Your Folder Name.....&quot;);
                myFolder.Update();
            }
            catch(Exception ex)
            {
                Console.WriteLine(ex);
            }
            Console.WriteLine(&quot;Press any key to continue.....&quot;);
            Console.ReadLine();
        }
</pre>
<p><strong>Add fields to list:</strong></p>
<pre class="brush: csharp; title: ; notranslate">static void Main(string[] args)
        {
            try
            {
                SPSite mySite = new SPSite(&quot;http://servername:port&quot;);
                SPWeb myWeb = mySite.OpenWeb();
                SPList myList = myWeb.Lists[&quot;Your List Name.....&quot;];
                Guid listId = myList.ID;
                myList.Fields.Add(&quot;Employee ID&quot;, SPFieldType.Number, true);
                myList.Fields.Add(&quot;Employee Name&quot;, SPFieldType.Text, false);
                myList.Fields.Add(&quot;Designation&quot;, SPFieldType.Text, false);
                myList.Update();
            }
            catch(Exception ex)
            {
                Console.WriteLine(ex);
            }
            Console.WriteLine(&quot;Press any key to continue.....&quot;);
            Console.ReadLine();
        }
</pre>
<p><strong>Creating a new view in a list:</strong></p>
<pre class="brush: csharp; title: ; notranslate">static void Main(string[] args)
        {
            try
            {
                SPSite mySite = new SPSite(&quot;http://servername:port&quot;);
                SPWeb myWeb = mySite.OpenWeb();
                SPList mylist = myWeb.Lists[&quot;Your List Name.....&quot;];
                StringCollection myFields = new StringCollection();
                myFields.Add(&quot;Employee Name&quot;);
                myFields.Add(&quot;Designation&quot;);
                SPView myView= mylist.Views.Add(&quot;Your View Name.....&quot;, myFields, null, 100, false, false, SPViewCollection.SPViewType.Html, false);
            }
            catch(Exception ex)
            {
                Console.WriteLine(ex);
            }
            Console.WriteLine(&quot;Press any key to continue.....&quot;);
            Console.ReadLine();
        }
</pre>
<p><strong>Creating a new Content Type:</strong></p>
<pre class="brush: csharp; title: ; notranslate">static void Main(string[] args)
        {
            try
            {
                SPSite mySite = new SPSite(&quot;http://servername:port&quot;);
                SPWeb myWeb = mySite.OpenWeb();
                SPContentTypeCollection myContentTypeCollection = myWeb.ContentTypes;
                SPContentType myContentType= new SPContentType(myContentTypeCollection[SPBuiltInContentTypeId.Item], myContentTypeCollection, &quot;Content Type Name.....&quot;);
                myContentTypeCollection.Add(myContentType);
            }
            catch(Exception ex)
            {
                Console.WriteLine(ex);
            }
            Console.WriteLine(&quot;Press any key to continue.....&quot;);
            Console.ReadLine();
        }
</pre>
<p><strong>Adding the existing Site Columns to existing Content Type:</strong></p>
<pre class="brush: csharp; title: ; notranslate">static void Main(string[] args)
        {
            try
            {
                SPSite mySite = new SPSite(&quot;http://servername:port&quot;);
                SPWeb myWeb = mySite.OpenWeb();
                SPFieldCollection myFieldCollection = myWeb.Fields;
                SPContentType myContentType=myWeb.ContentTypes[&quot;Content Type Name&quot;];
                myContentType.FieldLinks.Add(new SPFieldLink(myFieldCollection[&quot;Employee Name&quot;]));
                myContentType.FieldLinks.Add(new SPFieldLink(myFieldCollection[&quot;Designation&quot;]));
                myContentType.Update();
            }
            catch(Exception ex)
            {
                Console.WriteLine(ex);
            }
            Console.WriteLine(&quot;Press any key to continue.....&quot;);
            Console.ReadLine();
        }
</pre>
<p><strong>Save site as template:</strong></p>
<pre class="brush: csharp; title: ; notranslate">static void Main(string[] args)
        {
            try
            {
                SPSite mySite = new SPSite(&quot;http://servername:port&quot;);
                SPWeb myWeb = mySite.OpenWeb();
                myWeb.SaveAsTemplate(&quot;FiveNumber.stp&quot;, &quot;FiveNumber&quot;, &quot;Its All About SharePoint&quot;, true);
            }
            catch(Exception ex)
            {
                Console.WriteLine(ex);
            }
            Console.WriteLine(&quot;Press any key to continue.....&quot;);
            Console.ReadLine();
        }
</pre>
<p><strong>Delete Recycle Bin Items:</strong></p>
<pre class="brush: csharp; title: ; notranslate">static void Main(string[] args)
        {
            SPSite mySite = new SPSite(&quot;http://servername:port&quot;);
            SPWeb myWeb = mySite.OpenWeb();
            SPRecycleBinItemCollection myRecycleBinCollection = mySite.RecycleBin;
            for (int i = 0; i &lt; myRecycleBinCollection.Count; i++)
            {
                myRecycleBinCollection[i].Delete();
                i--;
            }
            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-3/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>SharePoint Event Handlers &#8211; Asynchronous Vs Synchronous</title>
		<link>http://www.fivenumber.com/sharepoint-event-handlers-asynchronous-vs-synchronous/</link>
		<comments>http://www.fivenumber.com/sharepoint-event-handlers-asynchronous-vs-synchronous/#comments</comments>
		<pubDate>Sat, 21 Aug 2010 11:54:26 +0000</pubDate>
		<dc:creator>G Vijai Kumar</dc:creator>
				<category><![CDATA[MOSS - Object Model]]></category>
		<category><![CDATA[Sharepoint 2010 - General]]></category>
		<category><![CDATA[event handlers]]></category>
		<category><![CDATA[Sharepoint]]></category>
		<category><![CDATA[Sharepoint 2010]]></category>

		<guid isPermaLink="false">http://www.fivenumber.com/?p=746</guid>
		<description><![CDATA[There is a little puzzlement among Asynchronousand Synchronous events, however I believe after reading this article, there will be no place for confusion in your brain, the reason for that I go behind a childlike practice to memorize what is Asynchronous ? and what is Synchronous ? The same babyish method, I want to share [...]]]></description>
			<content:encoded><![CDATA[<p>There is a little puzzlement among <strong>Asynchronous</strong>and <strong>Synchronous </strong>events, however I believe after reading this article, there will be no place for confusion in your brain, the reason for that I go behind a childlike practice to memorize <em>what is Asynchronous ?</em> and <em>what is Synchronous ?</em></p>
<p>The same babyish method, I want to share with you.</p>
<p><strong>A</strong> for <strong>Apple</strong>, <strong>A </strong>for <strong>Asynchronous </strong>and <strong>A </strong>for <strong>After</strong> events, so all Asynchronous events occur <strong>after </strong>the event, which does not stop the code to execute. All Asynchronous events end with <strong>&#8216;ed&#8217;</strong> letters like SiteDelet<strong>ed</strong>, FieldAdd<strong>ed</strong>, ItemAdd<strong>ed</strong> etc.</p>
<p>Now, let’s talk on the subject of <strong>Synchronous </strong>events, all Synchronous events  occur <strong>before </strong>the event, which stop the code to execute. All Synchronous events end with <strong>&#8216;ing&#8217;</strong> letters like SiteDelet<strong>ing</strong>, FieldAdd<strong>ing</strong>, ItemAdd<strong>ing</strong> etc.</p>
<p><strong>SPWebEventReceiver Asynchronous Events</strong></p>
<table border="1" width="100%">
<tbody>
<tr>
<td>SiteDeleted</td>
<td>Occurs <strong>after </strong>an existing site collection deleted.</td>
</tr>
<tr>
<td>WebDeleted</td>
<td>Occurs <strong>after </strong>an existing web site is completely deleted.</td>
</tr>
<tr>
<td>WebMoved</td>
<td>Occurs <strong>after </strong>an existing web site has been moved.</td>
</tr>
</tbody>
</table>
<p><br/><br />
<strong>SPWebEventReceiver Synchronous Events</strong></p>
<table border="1" width="100%">
<tbody>
<tr>
<td>SiteDeleting</td>
<td>Occurs <strong>before </strong>an existing site collection is being deleted.</td>
</tr>
<tr>
<td>WebDeleting</td>
<td>Occurs <strong>before </strong>an existing web site is deleted.</td>
</tr>
<tr>
<td>WebMoving</td>
<td>Occurs <strong>before</strong> an existing web site has been renamed or moved</td>
</tr>
</tbody>
</table>
<p><br/><br />
<strong>SPListEventReceiver Asynchronous Methods</strong></p>
<table border="1" width="100%">
<tbody>
<tr>
<td>FieldAdded</td>
<td>Occurs <strong>after </strong>a field link is added.</td>
</tr>
<tr>
<td>FieldDeleted</td>
<td>Occurs <strong>after </strong>a field has been removed from the list.</td>
</tr>
<tr>
<td>FieldUpdated</td>
<td>Occurs <strong>after </strong>a field link has been updated</td>
</tr>
</tbody>
</table>
<p><br/><br />
<strong>SPListEventReceiver Synchronous Methods</strong></p>
<table border="1" width="100%">
<tbody>
<tr>
<td>FieldAdding</td>
<td>Occurs <strong>before </strong>a field link is added to a content type.</td>
</tr>
<tr>
<td>FieldDeleting</td>
<td>Occurs <strong>before </strong>a field is removed from the list.</td>
</tr>
<tr>
<td>FieldUpdating</td>
<td>Occurs <strong>before </strong>a field link is updated</td>
</tr>
</tbody>
</table>
<p><br/><br />
<strong>SPItemEventReceiver Asynchronous Methods</strong></p>
<table border="1" width="100%">
<tbody>
<tr>
<td>ItemAdded</td>
<td>Occurs <strong>after</strong> a new item has been added</td>
</tr>
<tr>
<td>ItemAttachmentAdded</td>
<td>Occurs <strong>after </strong>an attachment added to an item.</td>
</tr>
<tr>
<td>ItemAttachmentDeleted</td>
<td>Occurs <strong>after </strong>an attachment removed from an item.</td>
</tr>
<tr>
<td>ItemCheckedOut</td>
<td>Occurs <strong>after </strong>an item is checked out.</td>
</tr>
<tr>
<td>ItemDeleted</td>
<td>Occurs <strong>after </strong>an item is completely deleted.</td>
</tr>
<tr>
<td>ItemFileMoved</td>
<td>Occurs <strong>after </strong>a file is moved.</td>
</tr>
<tr>
<td>ItemUpdated</td>
<td>Occurs <strong>after </strong>an item is modified/edited.</td>
</tr>
</tbody>
</table>
<p><br/><br />
<strong>SPListItemEventReceiver Synchronous Methods</strong></p>
<table border="1" width="100%">
<tbody>
<tr>
<td>ItemAdding</td>
<td>Occurs <strong>before </strong>a new item is added.</td>
</tr>
<tr>
<td>ItemAttachmentAdding</td>
<td>Occurs <strong>before </strong>an attachment is added to an item.</td>
</tr>
<tr>
<td>ItemAttachmentDeleting</td>
<td>Occurs <strong>before </strong>an attachment when a user removed from an item.</td>
</tr>
<tr>
<td>ItemCheckingIn</td>
<td>Occurs <strong>before </strong>a file is checking-in.</td>
</tr>
<tr>
<td>ItemCheckingOut</td>
<td>Occurs <strong>before </strong>an item is checking-out.</td>
</tr>
<tr>
<td>ItemDeleting</td>
<td>Occurs <strong>before </strong>an item is completely deleted.</td>
</tr>
<tr>
<td>ItemFileMoving</td>
<td>Occurs <strong>before </strong>a file is moved.</td>
</tr>
<tr>
<td>ItemUncheckedOut</td>
<td>Occurs <strong>before </strong>an item is unchecked out.</td>
</tr>
<tr>
<td>ItemUncheckingOut</td>
<td><strong>Before </strong>event that occurs when an item is being unchecked out.</td>
</tr>
<tr>
<td>ItemUpdating</td>
<td>Occurs <strong>before </strong>an existing item is modified/edited.</td>
</tr>
</tbody>
</table>
<p><br/><br />
<strong>SharePoint Foundation 2010 New Events</strong></p>
<p>Microsoft added several new events to SharePoint Foundation 2010 on <strong>Site</strong>, <strong>List </strong>and <strong>Item </strong>level. These fresh events are intended to meet up the requirements and for better elasticity.</p>
<p><strong>SPWebEventReceiver</strong></p>
<table border="1" width="100%">
<tbody>
<tr>
<td>WebAdding</td>
<td><strong> </strong>Occurs <strong>before</strong> a new web site is created.</td>
</tr>
<tr>
<td>WebProvisioned</td>
<td>Occurs <strong>after </strong>the web is provisioned.</td>
</tr>
</tbody>
</table>
<p><br/><br />
<strong>WebAdding: </strong>event arises prior to a fresh web site is created, we can control the website to create or not to create by WebAdding event, then no SharePoint site is created and the provisioning process is not started.</p>
<p><strong>WebProvisioned: </strong>event arise after the web is totally provisioned and process has stopped up. WebProvisioned can be configured to control in any synchronous or asynchronous methods.</p>
<p>If user wants to add few webparts to the newly provisioned web we can use this event to meet up the necessity</p>
<p><strong>SPListEventReceiver</strong></p>
<table border="1" width="100%">
<tbody>
<tr>
<td>ListAdding</td>
<td>Occurs <strong>before</strong> a list is created.</td>
</tr>
<tr>
<td>ListAdded</td>
<td>Occurs <strong>after</strong> a list is created.</td>
</tr>
<tr>
<td>ListDeleting</td>
<td>Occurs <strong>before</strong> a list is deleted.</td>
</tr>
<tr>
<td>ListDeleted</td>
<td>Occurs <strong>after</strong> a list is deleted.</td>
</tr>
</tbody>
</table>
<p><br/><br />
Please follow <a title="Catalog of SharePoint Foundation Events" href="http://msdn.microsoft.com/en-us/library/ff407568.aspx" target="_blank">Catalog of SharePoint Foundation Events</a> for newly added event in SharePoint Foundation 2010</p>
]]></content:encoded>
			<wfw:commentRss>http://www.fivenumber.com/sharepoint-event-handlers-asynchronous-vs-synchronous/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>A quick look on WSS Out Of Box web services &#8211; Part 2</title>
		<link>http://www.fivenumber.com/a-quick-look-on-wss-out-of-box-web-services-part-2/</link>
		<comments>http://www.fivenumber.com/a-quick-look-on-wss-out-of-box-web-services-part-2/#comments</comments>
		<pubDate>Mon, 19 Apr 2010 09:31:08 +0000</pubDate>
		<dc:creator>G Vijai Kumar</dc:creator>
				<category><![CDATA[MOSS - Object Model]]></category>
		<category><![CDATA[Sharepoint]]></category>
		<category><![CDATA[Web Services]]></category>

		<guid isPermaLink="false">http://www.fivenumber.com/?p=708</guid>
		<description><![CDATA[In my previous post you can have a quick look on WSS Out Of Box web services – Part 1 In this post once again I want to update few WSS web service handy programs with minimum lines of code. Before executing the code first of all add web reference http://servername:port/_vti_bin/Webs.asmx In this example I [...]]]></description>
			<content:encoded><![CDATA[<p>In my previous post you can have <a title="A quick look on WSS out of box web services - Part 2" href="http://www.fivenumber.com/a-quick-look-on-wss-out-of-box-web-services/" target="_blank">a quick look on WSS Out Of Box web services – Part 1</a></p>
<p>In this post once again I want to update few WSS web service handy programs with minimum lines of code.</p>
<p>Before executing the code first of all add web reference  http://servername:port/_vti_bin/Webs.asmx<br />
In this example I have given the web reference folder name as myWebswebservice</p>
<p><strong>Show all subsites:</strong></p>
<pre class="brush: csharp; title: ; notranslate"> static void Main(string[] args)
        {
myWebswebservice.Webs allWebs = new myWebswebservice.Webs();
//credentials for password based authentication
//System.Net.NetworkCredential mycredentials = new System.Net.NetworkCredential(&quot;g.vijaikumar&quot;, &quot;mypassword&quot;, &quot;fivenumber&quot;);
//allWebs.Credentials = mycredentials;
//using system credentials of the application
allWebs.Credentials = System.Net.CredentialCache.DefaultCredentials;
try
{
string webTitle = null;
XmlNode myNode = allWebs.GetAllSubWebCollection();
XmlNodeList nodes = myNode.SelectNodes(&quot;*&quot;);
foreach (XmlNode node in nodes)
{
Console.WriteLine(webTitle + node.Attributes[&quot;Title&quot;].Value);
}
}
catch (Exception ex)
{
Console.WriteLine(ex.ToString());
}
Console.WriteLine(&quot;Press any key to continue.....&quot;);
Console.ReadLine();
}
</pre>
]]></content:encoded>
			<wfw:commentRss>http://www.fivenumber.com/a-quick-look-on-wss-out-of-box-web-services-part-2/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<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>Sharepoint list form generator</title>
		<link>http://www.fivenumber.com/sharepoint-list-form-generator/</link>
		<comments>http://www.fivenumber.com/sharepoint-list-form-generator/#comments</comments>
		<pubDate>Wed, 14 Oct 2009 15:49:38 +0000</pubDate>
		<dc:creator>G Vijai Kumar</dc:creator>
				<category><![CDATA[MOSS - Object Model]]></category>
		<category><![CDATA[Custom Webparts]]></category>
		<category><![CDATA[Sharepoint]]></category>
		<category><![CDATA[Tool Parts]]></category>

		<guid isPermaLink="false">http://www.fivenumber.com/?p=598</guid>
		<description><![CDATA[Today I am going to show you how to generate a list form dynamically as soon as you select the list name you can see the form generated for you with file upload field (attachment). I also know that there is  an excellent solution Sharepoint Form Generator developed by Alon Havivi, but still I want [...]]]></description>
			<content:encoded><![CDATA[<p>Today I am going to show you how to generate a list form dynamically as soon as you select the list name you can see the form generated for you with file upload field (attachment). I also know that there is  an excellent solution <a title="Sharepoint Form Generator" href="http://sfg.codeplex.com/" target="_blank">Sharepoint Form Generator</a> developed by <a title="Alon Havivi's SharePoint 2007 Blog" href="http://havivi.blogspot.com/2009/06/sharepoint-form-generator.html" target="_blank">Alon Havivi</a>, but still I want to share with you, so that for some one the code may be helpful as a whole or part of it</p>
<p>No problem whether your list contains 1 field or 100 fields, code will  generate all the &#8216;n&#8217; no.of fields with file upload field (attachment) contained in the list. It loops through all the input fields and creates at runtime.</p>
<p>All  you have to do is, open visual studio 2005/2008 create a new project using webpart template use the code from <a title="FormGeneratorWebPart1.cs" href="http://www.fivenumber.com/wp-content/uploads/2009/10/SharepointFormGenerator-WebPart1.txt" target="_blank">WebPart1.cs</a> and <a title="FormGeneratorToolPart.cs" href="http://www.fivenumber.com/wp-content/uploads/2009/10/SharepointFormGenerator-ToolPart.txt" target="_blank">FormGeneratorToolPart.cs</a> build the project, place the .dll file in GAC or site bin directory, add the necessary safe control tag in Web.config file, import the webpart in to gallery, and add the same on to your site, after adding the webpart in your site you have to select the list name from the webpart properties, so that you can see the generated form similar to the form as in NewForm.aspx</p>
<div id="attachment_599" class="wp-caption aligncenter" style="width: 153px"><a href="http://www.fivenumber.com/wp-content/uploads/2009/10/2.gif" rel="lightbox[598]"><img class="size-medium wp-image-599" title="Select the list name from the list of lists" src="http://www.fivenumber.com/wp-content/uploads/2009/10/2-143x300.gif" alt="Select the list name from the list of lists" width="143" height="300" /></a><p class="wp-caption-text">Select the list name from the list of lists</p></div>
<div id="attachment_600" class="wp-caption aligncenter" style="width: 310px"><a href="http://www.fivenumber.com/wp-content/uploads/2009/10/1.gif" rel="lightbox[598]"><img class="size-medium wp-image-600" title="List form generated" src="http://www.fivenumber.com/wp-content/uploads/2009/10/1-300x109.gif" alt="List form generated" width="300" height="109" /></a><p class="wp-caption-text">List form generated</p></div>
<p>Download the complete source code (<strong>Please Note</strong>: Code cannot be viewed properly on the web page, so please use the below links to view the code or for downloading)</p>
<p><a title="FormGeneratorWebPart1.cs" href="http://www.fivenumber.com/wp-content/uploads/2009/10/SharepointFormGenerator-WebPart1.txt" target="_blank">WebPart1.cs<br />
</a><a title="FormGeneratorToolPart.cs" href="http://www.fivenumber.com/wp-content/uploads/2009/10/SharepointFormGenerator-ToolPart.txt" target="_blank">FormGeneratorToolPart.cs</a></p>
<p><strong>WebPart1.cs</strong></p>
<pre name="code" class="c-sharp">
using System;
using System.Web;
using System.IO;
using System.Runtime.InteropServices;
using System.Web.UI;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Serialization;
using System.Web.UI.WebControls;

using Microsoft.SharePoint;
using Microsoft.SharePoint.WebControls;
using Microsoft.SharePoint.WebPartPages;

namespace FormGenerator
{
    [Guid("93612d52-737c-4e83-83c3-a228910e87a3")]
    public class FormGenerator : Microsoft.SharePoint.WebPartPages.WebPart
    {
        Table oFormTable;
        FileUpload oFormFileUpload;
        FieldLabel oFormLabelField;
        FormField oFormField;
        Button oFormButtonSubmit;
        Label oFormLabelMessage;

        SPList oFormList;

        private string _FormList = string.Empty;

        string qstitle = string.Empty;
        string qsmission = string.Empty;

        public string FormList
        {
            get { return _FormList; }
            set { _FormList = value; }
        }

        protected override void CreateChildControls()
        {
            base.CreateChildControls();

            oFormTable = new Table();
            oFormTable.CellPadding = 0;
            oFormTable.CellSpacing = 0;            

            oFormLabelMessage = new Label();
            oFormLabelMessage.ID = "lbl_message";
            oFormLabelMessage.CssClass = "ms-formvalidation";
            this.Controls.Add(oFormLabelMessage);

            //Generate Form
            GenerateFormList();
        }

        private void GenerateFormList()
        {
            SPWeb oWeb = Microsoft.SharePoint.WebControls.SPControl.GetContextWeb(Context);
            if (FormList != "")
            {
                try
                {
                    oFormList = oWeb.Lists[FormList];
                    foreach (SPField oField in oFormList.Fields)
                    {
                        if (oField.Type == SPFieldType.Attachments)
                        {
                            FieldLabel oLabelAttachmentField = new FieldLabel();
                            oLabelAttachmentField.ControlMode = SPControlMode.New;
                            oLabelAttachmentField.ListId = oFormList.ID;
                            oLabelAttachmentField.FieldName = oField.InternalName;

                            oFormFileUpload = new FileUpload();
                            oFormFileUpload.ID = "FileUpload";

                            AttachmentsField oAttachmentField = new AttachmentsField();
                            oAttachmentField.ControlMode = SPControlMode.New;
                            oAttachmentField.ListId = oFormList.ID;
                            oAttachmentField.FieldName = oField.InternalName;
                            oAttachmentField.Controls.Add(oFormFileUpload);
                            oAttachmentField.ID = "Control_" + oField.InternalName;

                            TableRow oRowAttachment = new TableRow();
                            oFormTable.Rows.Add(oRowAttachment);
                            TableCell oCellAttachmentLabel = new TableCell();
                            oRowAttachment.Cells.Add(oCellAttachmentLabel);

                            oCellAttachmentLabel.Controls.Add(oLabelAttachmentField);
                            oCellAttachmentLabel.CssClass = "ms-formlabel";
                            TableCell oCellAttachment = new TableCell();
                            oRowAttachment.Cells.Add(oCellAttachment);
                            oCellAttachment.Controls.Add(oAttachmentField);
                            oCellAttachment.CssClass = "ms-formbody";
                        }
                    }

                    // Loop through all the fields in the list
                    foreach (SPField oField in oFormList.Fields)
                    {
                        // Avoid Hidden, Read Only, Attachments field
                        if (!oField.Hidden &#038;&#038; !oField.ReadOnlyField &#038;&#038; oField.Type != SPFieldType.Attachments)
                        {
                            oFormLabelField = new FieldLabel();
                            oFormLabelField.ControlMode = SPControlMode.New;
                            oFormLabelField.ListId = oFormList.ID;
                            oFormLabelField.FieldName = oField.InternalName;

                            oFormField = new FormField();
                            oFormField.ControlMode = SPControlMode.New;
                            oFormField.ListId = oFormList.ID;
                            oFormField.FieldName = oField.InternalName;
                            oFormField.ID = "Control_" + oField.InternalName;

                            TableRow oRow = new TableRow();
                            oFormTable.Rows.Add(oRow);

                            TableCell oCellLabel = new TableCell();
                            oRow.Cells.Add(oCellLabel);
                            TableCell oCellControl = new TableCell();
                            oRow.Cells.Add(oCellControl);

                            oCellLabel.Controls.Add(oFormLabelField);
                            oCellControl.Controls.Add(oFormField);

                            oCellLabel.CssClass = "ms-formlabel";
                            oCellControl.CssClass = "ms-formbody";
                        }
                    }

                    //Create ASP.Net button
                    oFormButtonSubmit = new Button();
                    oFormButtonSubmit.ID = "btn_submit";
                    oFormButtonSubmit.Text = "OK";
                    oFormButtonSubmit.CssClass = "ms-ButtonHeightWidth";
                    oFormButtonSubmit.Click += new EventHandler(oFormButtonSubmit_Click);
                    this.Controls.Add(oFormButtonSubmit);

                    // Create the row for the Submit button
                    TableRow oRowButton = new TableRow();
                    oFormTable.Rows.Add(oRowButton);

                    // Create the cell for the Submit button
                    TableCell oCellButton = new TableCell();
                    oCellButton.ColumnSpan = 2;
                    oRowButton.Cells.Add(oCellButton);

                    Controls.Add(oFormTable);
                }
                catch (Exception ex)
                {
                    Page.Response.Write(ex.ToString());
                }
            }
            else
            {
                Page.Response.Write("Select valid <b>List</b> from webpart properties");
            }
        }

        void oFormButtonSubmit_Click(object sender, EventArgs e)
        {
            SPSite mySite = SPControl.GetContextSite(Context);
            SPWeb myWeb = SPControl.GetContextWeb(Context);
            SPList myList = myWeb.Lists[FormList];
            SPListItem myItem = myList.Items.Add();

            //Validating the controls
            foreach (SPField sField in myList.Fields)
            {
                if (sField.Required == true)
                {
                    string oControl = "Control_" + sField.InternalName.ToString();
                    Control oFieldControl = this.FindControl(oControl);
                    FormField sFormField = (FormField)oFieldControl;
                    if ((sFormField.Value) == null || (sFormField.Value.ToString()) == "")
                    {
                        oFormLabelMessage.Visible = true;
                        oFormLabelMessage.Text = "* indicates required fields";
                        return;
                    }
                }
            }
            foreach (SPField oField in myList.Fields)
            {
                string oFieldID = "Control_" + oField.InternalName;
                Control sFieldControl = this.FindControl(oFieldID);
                if (sFieldControl != null)
                {
                    if (oField.Type != SPFieldType.Attachments)
                    {
                        FormField sFormField = (FormField)sFieldControl;
                        myItem[oField.InternalName] = sFormField.Value;
                    }
                    else
                    {
                        AttachmentsField sAttachmentField = (AttachmentsField)sFieldControl;
                        FileUpload oFileControl = (FileUpload)sAttachmentField.FindControl("FileUpload");
                        if (oFileControl != null)
                        {
                            try
                            {
                                HttpPostedFile oPostedFile = oFileControl.PostedFile;
                                string oFileName = Path.GetFileName(oPostedFile.FileName);
                                if (oPostedFile.ContentLength > 0)
                                {
                                    Stream oInputStream = oPostedFile.InputStream;
                                    byte[] oBT = new byte[oPostedFile.InputStream.Length];
                                    oPostedFile.InputStream.Seek(0, SeekOrigin.Begin);
                                    oPostedFile.InputStream.Read(oBT, 0, oBT.Length);
                                    myItem.Attachments.Add(oFileName, oBT);
                                }
                            }
                            catch (Exception ex)
                            {
                                oFormLabelMessage.Visible = true;
                                oFormLabelMessage.Text = ex.ToString();
                            }
                        }
                    }
                }
                myWeb.AllowUnsafeUpdates = true;
                myItem.Update();
                myWeb.AllowUnsafeUpdates = false;
                oFormLabelMessage.Visible = true;
                oFormLabelMessage.Text = "Record updated";
            }
        }

        protected override void Render(HtmlTextWriter writer)
        {
            if (FormList != "")
            {
                writer.Write("<Table align='right'><Tr><Td>");
                oFormLabelMessage.RenderControl(writer);
                writer.Write("</Td></Tr></Table>");
                writer.Write("<br/>");
                writer.Write("<Table><Tr><Td>");
                oFormTable.RenderControl(writer);
                writer.Write("</Td></Tr>");
                writer.Write("<Tr><Td align='right'>");
                oFormButtonSubmit.RenderControl(writer);
                writer.Write("</Td></Tr></Table>");
            }
            else
            {
                oFormLabelMessage.RenderControl(writer);
            }
        }

        public override ToolPart[] GetToolParts()
        {
            ToolPart[] allToolParts = new ToolPart[3];
            WebPartToolPart standardToolParts = new WebPartToolPart();
            CustomPropertyToolPart customToolParts = new CustomPropertyToolPart();
            allToolParts[0] = standardToolParts;
            allToolParts[1] = customToolParts;
            allToolParts[2] = new FormGeneratorToolPart();
            return allToolParts;
        }
    }
}
</pre>
<p><strong>FormGeneratorToolPart.cs</strong></p>
<pre name="code" class="c-sharp">
using System;
using System.Collections.Generic;
using System.Text;
using System.Web.UI.WebControls;
using Microsoft.SharePoint;

namespace FormGenerator
{
    class FormGeneratorToolPart: Microsoft.SharePoint.WebPartPages.ToolPart
    {
        FormGenerator oFG;
        Panel oToolPartPanel;
        DropDownList oDDLListProvider;

        protected override void CreateChildControls()
        {
            base.CreateChildControls();

            oToolPartPanel = new Panel();
            Controls.Add(oToolPartPanel);

            oDDLListProvider = new DropDownList();
            oToolPartPanel.Controls.Add(oDDLListProvider);

            PopulateProviderList();
        }

        private void PopulateProviderList()
        {
            SPListCollection myListCol = SPContext.Current.Web.Lists;
            oDDLListProvider.AppendDataBoundItems = true;
            foreach (SPList myList in myListCol)
            {
                ListItem myListItem = new ListItem(myList.Title, myList.Title);
                oFG = (FormGenerator)this.ParentToolPane.SelectedWebPart;
                if (oFG.FormList == myList.Title)
                    myListItem.Selected = true;
                oDDLListProvider.Items.Add(myListItem);
            }
        }

        public override void ApplyChanges()
        {
            base.ApplyChanges();
            oFG.FormList = oDDLListProvider.SelectedValue;
        }

        public override void SyncChanges()
        {
            base.SyncChanges();
            oDDLListProvider.SelectedValue = oFG.FormList.ToString();
        }

        protected override void RenderToolPart(System.Web.UI.HtmlTextWriter output)
        {
            output.Write("<b>List Name Lookup:</b>");
            output.Write("<br/><br/>");
            oDDLListProvider.RenderControl(output);
            output.Write("<br/>
<div class='UserSectionTitle'>&nbsp;</div>

<br/>");
        }
    }
}
</pre>
]]></content:encoded>
			<wfw:commentRss>http://www.fivenumber.com/sharepoint-list-form-generator/feed/</wfw:commentRss>
		<slash:comments>21</slash:comments>
		</item>
	</channel>
</rss>

