<?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>Object Model Archives - Blog IT</title>
	<atom:link href="https://blogit.create.pt/category/development/object-model/feed/" rel="self" type="application/rss+xml" />
	<link>https://blogit.create.pt/category/development/object-model/</link>
	<description>Create IT blogger community</description>
	<lastBuildDate>Thu, 10 Jan 2019 14:18:02 +0000</lastBuildDate>
	<language>en-US</language>
	<sy:updatePeriod>
	hourly	</sy:updatePeriod>
	<sy:updateFrequency>
	1	</sy:updateFrequency>
	<generator>https://wordpress.org/?v=6.9.1</generator>
	<item>
		<title>SharePoint Associating a Workflow to a list</title>
		<link>https://blogit.create.pt/marcosilva/2007/12/10/sharepoint-associating-a-workflow-to-a-list/</link>
					<comments>https://blogit.create.pt/marcosilva/2007/12/10/sharepoint-associating-a-workflow-to-a-list/#respond</comments>
		
		<dc:creator><![CDATA[Marco Silva]]></dc:creator>
		<pubDate>Mon, 10 Dec 2007 05:07:00 +0000</pubDate>
				<category><![CDATA[Object Model]]></category>
		<category><![CDATA[Development]]></category>
		<category><![CDATA[SharePoint]]></category>
		<guid isPermaLink="false">http://blogcreate.azurewebsites.net/marcosilva/?p=191</guid>

					<description><![CDATA[<p>Continuing from my last post, one thing that you also may want to do when programmatically creating a list is associating a workflow with a given configuration (e.g. Approval workflow when a new item is created in a document library).In the SharePoint interface we can do this association very easily but if you want to [&#8230;]</p>
<p>The post <a href="https://blogit.create.pt/marcosilva/2007/12/10/sharepoint-associating-a-workflow-to-a-list/">SharePoint Associating a Workflow to a list</a> appeared first on <a href="https://blogit.create.pt">Blog IT</a>.</p>
]]></description>
										<content:encoded><![CDATA[<p>Continuing from my last post, one thing that you also may want to do when programmatically creating a list is associating a workflow with a given configuration (e.g. Approval workflow when a new item is created in a document library).<br />In the SharePoint interface we can do this association very easily but if you want to do it using the object model there are a few steps that you should have into consideration.</p>
<p>First what we need to create is a <font face="courier new,courier">SPWorkflowAssociation </font>more specifically <font face="courier new,courier">SPWorkflowAssociation.CreateListAssociation</font>. For this we need to give information like:</p>
<ul>
<li><font face="courier new,courier">Workflow template</font> &ndash; Template to use for the workflow (e.g. Approval);</li>
<li><font face="courier new,courier">Workflow Title </font>&ndash; Name of the workflow;</li>
<li><font face="courier new,courier">Workflow task list</font> &ndash; Name of the workflow task list (should be based on the Tasks list template);</li>
<li><font face="courier new,courier">Workflow history list </font>&ndash; Name of the workflow history list (should be based on the Workflow History list template).</li>
</ul>
<p>After creating the <font face="courier new,courier">SPWorkflowAssociation </font>we can set general workflow parameters that are nothing more than configurations available in all workflow templates:</p>
<ul>
<li><font face="courier new,courier">AllowManual </font>&ndash; Allow manual start of the workflow;</li>
<li><font face="courier new,courier">AutoStartCreate </font>&ndash; Auto start the workflow on item creation;</li>
<li><font face="courier new,courier">AutoStartChange </font>&ndash; Auto start the workflow on item change;</li>
<li><font face="courier new,courier">AssociationData </font>&ndash; Association data to be passed to the workflow instance.</li>
</ul>
<p>The key parameter here is the <font face="courier new,courier">AssociationData </font>that contains workflow template specific configurations to be passed to the corresponding workflow instances. For example referring to the out-of-box Approval workflow, its association data is something like this (in XML because the Approval workflow uses an InfoPath form for its configuration page):</p>
<p><font face="courier new,courier">&lt;my:myFields xml:lang=&quot;en-us&quot; xmlns:xsi=&quot;http://www.w3.org/2001/XMLSchema-instance&quot;<br />&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;xmlns:my=&quot;http://schemas.microsoft.com/office/infopath/2003/myXSD&quot;&gt;</p>
<p>&nbsp;&nbsp;&nbsp; &lt;my:Reviewers&gt;<br />&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &lt;my:Person&gt;<br />&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &lt;my:DisplayName&gt;Administrator&lt;/my:DisplayName&gt;<br />&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &lt;my:AccountId&gt;Administrator&lt;/my:AccountId&gt;<br />&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &lt;my:AccountType&gt;User&lt;/my:AccountType&gt;<br />&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &lt;/my:Person&gt;<br />&nbsp;&nbsp;&nbsp; &lt;/my:Reviewers&gt;</p>
<p>&nbsp;&nbsp;&nbsp; &lt;my:CC&gt;&lt;/my:CC&gt;<br />&nbsp;&nbsp;&nbsp; &lt;my:DueDate xsi:nil=&quot;true&quot;&gt;&lt;/my:DueDate&gt;<br />&nbsp;&nbsp;&nbsp; &lt;my:Description xsi:nil=&quot;true&quot;&gt;&lt;/my:Description&gt;<br />&nbsp;&nbsp;&nbsp; &lt;my:Title&gt;&lt;/my:Title&gt;<br />&nbsp;&nbsp;&nbsp; &lt;my:DefaultTaskType&gt;1&lt;/my:DefaultTaskType&gt;<br />&nbsp;&nbsp;&nbsp; &lt;my:CreateTasksInSerial&gt;true&lt;/my:CreateTasksInSerial&gt;<br />&nbsp;&nbsp;&nbsp; &lt;my:AllowDelegation&gt;false&lt;/my:AllowDelegation&gt;<br />&nbsp;&nbsp;&nbsp; &lt;my:AllowChangeRequests&gt;true&lt;/my:AllowChangeRequests&gt;<br />&nbsp;&nbsp;&nbsp; &lt;my:StopOnAnyReject xsi:nil=&quot;true&quot;&gt;&lt;/my:StopOnAnyReject&gt;<br />&nbsp;&nbsp;&nbsp; &lt;my:WantedTasks xsi:nil=&quot;true&quot;&gt;&lt;/my:WantedTasks&gt;<br />&nbsp;&nbsp;&nbsp; &lt;my:SetMetadataOnSuccess&gt;false&lt;/my:SetMetadataOnSuccess&gt;<br />&nbsp;&nbsp;&nbsp; &lt;my:MetadataSuccessField&gt;&lt;/my:MetadataSuccessField&gt;<br />&nbsp;&nbsp;&nbsp; &lt;my:MetadataSuccessValue&gt;&lt;/my:MetadataSuccessValue&gt;<br />&nbsp;&nbsp;&nbsp; &lt;my:ApproveWhenComplete&gt;false&lt;/my:ApproveWhenComplete&gt;<br />&nbsp;&nbsp;&nbsp; &lt;my:TimePerTaskVal xsi:nil=&quot;true&quot;&gt;&lt;/my:TimePerTaskVal&gt;<br />&nbsp;&nbsp;&nbsp; &lt;my:TimePerTaskType xsi:nil=&quot;true&quot;&gt;&lt;/my:TimePerTaskType&gt;<br />&nbsp;&nbsp;&nbsp; &lt;my:Voting&gt;false&lt;/my:Voting&gt;<br />&nbsp;&nbsp;&nbsp; &lt;my:MetadataTriggerField&gt;&lt;/my:MetadataTriggerField&gt;<br />&nbsp;&nbsp;&nbsp; &lt;my:MetadataTriggerValue&gt;&lt;/my:MetadataTriggerValue&gt;<br />&nbsp;&nbsp;&nbsp; &lt;my:InitLock&gt;true&lt;/my:InitLock&gt;<br />&nbsp;&nbsp;&nbsp; &lt;my:MetadataStop&gt;false&lt;/my:MetadataStop&gt;<br />&nbsp;&nbsp;&nbsp; &lt;my:ItemChangeStop&gt;false&lt;/my:ItemChangeStop&gt;<br />&nbsp;&nbsp;&nbsp; &lt;my:GroupTasks&gt;true&lt;/my:GroupTasks&gt;<br />&lt;/my:myFields&gt;&nbsp;</font></p>
<p>As you can see this association data contains the rest of the configuration parameters regarding the workflow template and in the case of the Approval workflow it contains something as important as the Approvers list (Reviewers).</p>
<p>With this you have all the information that is needed to correctly configure and associate an workflow to a list. Just don&rsquo;t forget in the end to do something like <font face="courier new,courier">SPList.AddWorkflowAssociation(SPWorkflowAssociation)</font>.</p>
<p>I leave you here an example method to accomplish what was described.</p>
<p><font face="courier new,courier">public SPWorkflowAssociation AddListWorkflowAssociation(SPWeb parentWeb, SPList parentList, String title, String workflowTemplateName, String workflowTaskListName, String workflowHistoryListName,Boolean workflowAllowManualStart, Boolean workflowAutoStartOnCreate, Boolean workflowAutoStartOnChange, String workflowAssociationData)<br />{<br />&nbsp;&nbsp;&nbsp; // Search for workflow template in site<br />&nbsp;&nbsp;&nbsp; foreach (SPWorkflowTemplate workflowTemplate in parentWeb.WorkflowTemplates)<br />&nbsp;&nbsp;&nbsp; {<br />&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; if (workflowTemplate.Name == workflowTemplateName)<br />&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; { // Found</p>
<p>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp; // Check is task and history lists already exist<br />&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp; SPList taskList;<br />&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp; SPList historyList;<br />&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp; try<br />&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp; {<br />&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp; &nbsp;&nbsp;&nbsp; taskList = parentWeb.Lists[workflowTaskListName];<br />&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp; }<br />&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp; catch (System.ArgumentException)<br />&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp; { // Does not exist in site. Add<br />&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; taskList = SPHelper.AddList(parentWeb, workflowTaskListName, &quot;Task list for workflow.&quot;, &quot;Tasks&quot;, false);<br />&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp; }</p>
<p>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp; try<br />&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp; {<br />&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp; &nbsp;&nbsp;&nbsp; historyList = parentWeb.Lists[workflowHistoryListName];<br />&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp; }<br />&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp; catch (System.ArgumentException)<br />&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp; { // Does not exist in site. Add<br />&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp; &nbsp; historyList = SPHelper.AddList(parentWeb, workflowHistoryListName, &quot;History list for workflow.&quot;, &quot;Workflow History&quot;, false);<br />&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp; }</p>
<p>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp; // Create workflow list association<br />&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp; SPWorkflowAssociation workflowAssociation = SPWorkflowAssociation.CreateListAssociation(workflowTemplate, title, taskList, historyList);</p>
<p>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp; // Set workflow parameters<br />&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp; workflowAssociation.AllowManual = workflowAllowManualStart;<br />&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp; workflowAssociation.AutoStartCreate = workflowAutoStartOnCreate;<br />&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp; workflowAssociation.AutoStartChange = workflowAutoStartOnChange;<br />&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp; workflowAssociation.AssociationData = workflowAssociationData;</p>
<p>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp; // Add workflow to list<br />&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp; workflowAssociation = parentList.AddWorkflowAssociation(workflowAssociation);<br />&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; workflowAssociation.Enabled = true;</p>
<p>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp; // Return workflow object<br />&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp; return workflowAssociation;<br />&nbsp;&nbsp;&nbsp; &nbsp;&nbsp; }<br />&nbsp;&nbsp;&nbsp; }</p>
<p>&nbsp;&nbsp;&nbsp; // Error if reach here<br />&nbsp;&nbsp;&nbsp; return null;</font></p>
<p><font face="courier new,courier">}</font><br />&nbsp;</p>
<p>The post <a href="https://blogit.create.pt/marcosilva/2007/12/10/sharepoint-associating-a-workflow-to-a-list/">SharePoint Associating a Workflow to a list</a> appeared first on <a href="https://blogit.create.pt">Blog IT</a>.</p>
]]></content:encoded>
					
					<wfw:commentRss>https://blogit.create.pt/marcosilva/2007/12/10/sharepoint-associating-a-workflow-to-a-list/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
			</item>
		<item>
		<title>SharePoint 2007 basics – Add a Folder</title>
		<link>https://blogit.create.pt/marcosilva/2007/11/01/sharepoint-2007-basics-add-a-folder/</link>
					<comments>https://blogit.create.pt/marcosilva/2007/11/01/sharepoint-2007-basics-add-a-folder/#respond</comments>
		
		<dc:creator><![CDATA[Marco Silva]]></dc:creator>
		<pubDate>Thu, 01 Nov 2007 09:40:00 +0000</pubDate>
				<category><![CDATA[Object Model]]></category>
		<category><![CDATA[Development]]></category>
		<category><![CDATA[SharePoint]]></category>
		<guid isPermaLink="false">http://blogcreate.azurewebsites.net/marcosilva/?p=211</guid>

					<description><![CDATA[<p>Folders can be added under a list or under another folder and the way of adding in each case is very similar. Below another example of sample functions.&#160;public SPFolder AddFolder(SPList parentList, String title){&#160;&#160;&#160; // Enable folder creation on the list&#160;&#160;&#160; parentList.EnableFolderCreation = true;&#160; &#160;&#160;&#160; // Add folder&#160;&#160;&#160; SPListItem listItem = parentList.Folders.Add(&#34;&#34;, SPFileSystemObjectType.Folder);&#160;&#160;&#160; listItem[&#34;Name&#34;] = title; [&#8230;]</p>
<p>The post <a href="https://blogit.create.pt/marcosilva/2007/11/01/sharepoint-2007-basics-add-a-folder/">SharePoint 2007 basics – Add a Folder</a> appeared first on <a href="https://blogit.create.pt">Blog IT</a>.</p>
]]></description>
										<content:encoded><![CDATA[<p><span lang="EN-US" style="font-size: 11pt;line-height: 115%;font-family: 'Calibri','sans-serif'">Folders can be added under a list or under another<br />
folder and the way of adding in each case is very similar. Below another<br />
example of sample functions.</span><br />&nbsp;<br /><font face="courier new,courier" size="1">public SPFolder AddFolder(SPList parentList, String title)<br />{<br />&nbsp;&nbsp;&nbsp; // Enable<br />
folder creation on the list<br />&nbsp;&nbsp;&nbsp; parentList.EnableFolderCreation<br />
= true;&nbsp;</font></p>
<p><font face="courier new,courier" size="1">&nbsp;&nbsp;&nbsp; // Add folder<br />&nbsp;&nbsp;&nbsp; SPListItem<br />
listItem = parentList.Folders.Add(&quot;&quot;, SPFileSystemObjectType.Folder);<br />&nbsp;&nbsp;&nbsp; listItem[&quot;Name&quot;]<br />
= title;</font></p>
<p><font face="courier new,courier" size="1">&nbsp;&nbsp; // Update<br /></font><font face="courier new,courier" size="1">&nbsp;&nbsp; listItem.Update();</font></p>
<p><font face="courier new,courier" size="1"></font></p>
<p><font face="courier new,courier" size="1"></font><font face="courier new,courier" size="1">&nbsp;&nbsp; // Return<br /></font><font face="courier new,courier" size="1">&nbsp;&nbsp; return<br />
listItem.Folder;<br />}</font></p>
<p><font face="courier new,courier" size="1">public SPFolder<br />
AddFolder(SPFolder folder, String title)<br />{<br />&nbsp;&nbsp;&nbsp; // Add<br />&nbsp;&nbsp;&nbsp; SPFolder<br />
newFolder = folder.SubFolders.Add(title);&nbsp;</font></p>
<p><font face="courier new,courier" size="1">&nbsp;&nbsp;&nbsp; // Return<br />&nbsp;&nbsp;&nbsp; return<br />
newFolder;<br />}</font></p>
<p><font face="courier new,courier" size="1">&nbsp;</font></p>
<p><font face="courier new,courier" size="1">&nbsp;</font></p>
<p>The post <a href="https://blogit.create.pt/marcosilva/2007/11/01/sharepoint-2007-basics-add-a-folder/">SharePoint 2007 basics – Add a Folder</a> appeared first on <a href="https://blogit.create.pt">Blog IT</a>.</p>
]]></content:encoded>
					
					<wfw:commentRss>https://blogit.create.pt/marcosilva/2007/11/01/sharepoint-2007-basics-add-a-folder/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
			</item>
		<item>
		<title>SharePoint 2007 basics – Add a List</title>
		<link>https://blogit.create.pt/marcosilva/2007/11/01/sharepoint-2007-basics-add-a-list/</link>
					<comments>https://blogit.create.pt/marcosilva/2007/11/01/sharepoint-2007-basics-add-a-list/#respond</comments>
		
		<dc:creator><![CDATA[Marco Silva]]></dc:creator>
		<pubDate>Thu, 01 Nov 2007 09:33:00 +0000</pubDate>
				<category><![CDATA[Object Model]]></category>
		<category><![CDATA[Development]]></category>
		<category><![CDATA[SharePoint]]></category>
		<guid isPermaLink="false">http://blogcreate.azurewebsites.net/marcosilva/?p=231</guid>

					<description><![CDATA[<p>Adding a list is done very much in the same way as a web. You just have to pay attention to were you should get your list template from, because depending if it is a native or a custom list template the place where to get it is different (SPWeb.ListTemplates vs SPSite.GetCustomListTemplates). Of course that [&#8230;]</p>
<p>The post <a href="https://blogit.create.pt/marcosilva/2007/11/01/sharepoint-2007-basics-add-a-list/">SharePoint 2007 basics – Add a List</a> appeared first on <a href="https://blogit.create.pt">Blog IT</a>.</p>
]]></description>
										<content:encoded><![CDATA[<p><span lang="EN-US" style="font-size: 11pt;line-height: 115%;font-family: 'Calibri','sans-serif'">Adding a list is done very much in the same way as<br />
a web. You just have to pay attention to were you should get your list template<br />
from, because depending if it is a native or a custom list template the place where<br />
to get it is different (</span><span lang="EN-US" style="font-size: 8pt;line-height: 115%;font-family: 'Courier New'">SPWeb.ListTemplates</span><span lang="EN-US" style="font-size: 11pt;line-height: 115%;font-family: 'Calibri','sans-serif'"> vs </span><span lang="EN-US" style="font-size: 8pt;line-height: 115%;font-family: 'Courier New'">SPSite.GetCustomListTemplates</span><span lang="EN-US" style="font-size: 11pt;line-height: 115%;font-family: 'Calibri','sans-serif'">). Of course that a list can only be added to a web.<br /></span></p>
<p><span lang="EN-US" style="font-size: 11pt;line-height: 115%;font-family: 'Calibri','sans-serif'">So a function to add a list could be like the one<br />
below.</span></p>
<p><font face="courier new,courier" size="1">public<br />
SPList AddList(SPWeb parentWeb, String title, String description, String<br />
listTemplate, Boolean onQuickLaunch)<br />{<br />&nbsp;&nbsp;&nbsp; // Get list template object<br />&nbsp;&nbsp;&nbsp; SPListTemplate listTemplateSP = null;&nbsp;</font></p>
<p><font face="courier new,courier" size="1">&nbsp;&nbsp;&nbsp; // Try out-of-box list templates first (Not be best way of doing this)<br />&nbsp;&nbsp;&nbsp; try<br />&nbsp;&nbsp;&nbsp; {<br />&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; listTemplateSP =<br />
parentWeb.ListTemplates[listTemplate];<br />&nbsp;&nbsp;&nbsp; }<br />&nbsp;&nbsp;&nbsp; catch (System.ArgumentException)<br />&nbsp;&nbsp;&nbsp; { // Try custom site templates<br />&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; SPListTemplateCollection customListTemplateCollection<br />
= parentWeb.Site.GetCustomListTemplates(parentWeb);<br />&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; listTemplateSP =<br />
customListTemplateCollection[listTemplate];<br />&nbsp;&nbsp;&nbsp; }&nbsp;</font></p>
<p><font face="courier new,courier" size="1">&nbsp;&nbsp;&nbsp; if (listTemplateSP == null)<br />&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; // Could not found<br />&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; throw new Exception(&quot;AddList: Could not found<br />
list template&quot;);&nbsp;</font></p>
<p><font face="courier new,courier" size="1">&nbsp;&nbsp;&nbsp; // Ok. Add list<br />&nbsp;&nbsp;&nbsp; Guid newListGuid = parentWeb.Lists.Add(title, description,<br />
listTemplateSP);&nbsp;</font></p>
<p><font face="courier new,courier" size="1">&nbsp;&nbsp;&nbsp; // Get new list<br />&nbsp;&nbsp;&nbsp; SPList newList = parentWeb.Lists[newListGuid];<br />&nbsp;&nbsp;&nbsp; newList.OnQuickLaunch = onQuickLaunch;&nbsp;</font></p>
<p><font face="courier new,courier" size="1">&nbsp;&nbsp;&nbsp; // Return<br />&nbsp;&nbsp;&nbsp; return newList;</font></p>
<p><font face="courier new,courier" size="1"></font><font face="courier new,courier" size="1">}</p>
<p></font></p>
<p>The post <a href="https://blogit.create.pt/marcosilva/2007/11/01/sharepoint-2007-basics-add-a-list/">SharePoint 2007 basics – Add a List</a> appeared first on <a href="https://blogit.create.pt">Blog IT</a>.</p>
]]></content:encoded>
					
					<wfw:commentRss>https://blogit.create.pt/marcosilva/2007/11/01/sharepoint-2007-basics-add-a-list/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
			</item>
		<item>
		<title>SharePoint 2007 basics &#8211; Add a Web</title>
		<link>https://blogit.create.pt/marcosilva/2007/11/01/sharepoint-2007-basics-add-a-web/</link>
					<comments>https://blogit.create.pt/marcosilva/2007/11/01/sharepoint-2007-basics-add-a-web/#respond</comments>
		
		<dc:creator><![CDATA[Marco Silva]]></dc:creator>
		<pubDate>Thu, 01 Nov 2007 08:25:00 +0000</pubDate>
				<category><![CDATA[Object Model]]></category>
		<category><![CDATA[Development]]></category>
		<category><![CDATA[SharePoint]]></category>
		<guid isPermaLink="false">http://blogcreate.azurewebsites.net/marcosilva/?p=251</guid>

					<description><![CDATA[<p>For my first SharePoint post I wanted to start by some of the basics related to working with the SharePoint Object Model. For sure there are other posts about this on the net, but I think that my blog should also reflect my SharePoint learning experience, and maybe by doing this I can show different [&#8230;]</p>
<p>The post <a href="https://blogit.create.pt/marcosilva/2007/11/01/sharepoint-2007-basics-add-a-web/">SharePoint 2007 basics &#8211; Add a Web</a> appeared first on <a href="https://blogit.create.pt">Blog IT</a>.</p>
]]></description>
										<content:encoded><![CDATA[<p><font face="arial,helvetica,sans-serif"><span lang="EN-US" style="font-size: 11pt;line-height: 115%;font-family: 'Calibri','sans-serif'">For my first SharePoint post I wanted to start by<br />
some of the basics related to working with the SharePoint Object Model. For<br />
sure there are other posts about this on the net, but I think that my blog<br />
should also reflect my SharePoint learning experience, and maybe by doing this<br />
I can show different ways accomplish similar things.</span></font></p>
<p><font face="arial,helvetica,sans-serif"><span lang="EN-US" style="font-size: 11pt;line-height: 115%;font-family: 'Calibri','sans-serif'">So let&rsquo;s begin. How do you programmatically add Web&rsquo;s,<br />
List&rsquo;s and Folder&rsquo;s to SharePoint?</span></font></p>
<p><font face="arial,helvetica,sans-serif"><strong><span lang="EN-US" style="font-size: 11pt;line-height: 115%;font-family: 'Calibri','sans-serif'">Add a<br />
Web</span></strong></font></p>
<p><font face="arial,helvetica,sans-serif"><span lang="EN-US" style="font-size: 11pt;line-height: 115%;font-family: 'Calibri','sans-serif'">To add a web I used the </span><span lang="EN-US" style="font-size: 8pt;line-height: 115%;font-family: 'Courier New'">SPWebs.Webs</span><span lang="EN-US" style="font-size: 11pt;line-height: 115%;font-family: 'Calibri','sans-serif'"><br />
property that returns a </span><span lang="EN-US" style="font-size: 8pt;line-height: 115%;font-family: 'Courier New'">SPWebCollection</span><span lang="EN-US" style="font-size: 11pt;line-height: 115%;font-family: Consolas"> </span><span lang="EN-US" style="font-size: 11pt;line-height: 115%;font-family: 'Calibri','sans-serif'">where<br />
you can </span><span lang="EN-US" style="font-size: 8pt;line-height: 115%;font-family: 'Courier New'">Add</span><span lang="EN-US" style="font-size: 11pt;line-height: 115%;font-family: 'Calibri','sans-serif'"> new<br />
Web&rsquo;s. Of course that this means that you should add a web under another web<br />
(the parent web).</span><span lang="EN-US" style="font-size: 11pt;line-height: 115%;font-family: 'Calibri','sans-serif'"></span></font></p>
<p><font face="arial,helvetica,sans-serif"><span lang="EN-US" style="font-size: 11pt;line-height: 115%;font-family: 'Calibri','sans-serif'">So to add a web you have to give parameters like<br />
the </span><span lang="EN-US" style="font-size: 8pt;line-height: 115%;font-family: 'Courier New'">title</span><span lang="EN-US" style="font-size: 11pt;line-height: 115%;font-family: 'Calibri','sans-serif'">, </span><span lang="EN-US" style="font-size: 8pt;line-height: 115%;font-family: 'Courier New'">description</span><span lang="EN-US" style="font-size: 11pt;line-height: 115%;font-family: 'Calibri','sans-serif'">, </span><span lang="EN-US" style="font-size: 8pt;line-height: 115%;font-family: 'Courier New'">relative</span><span lang="EN-US" style="font-size: 8pt;line-height: 115%;font-family: 'Calibri','sans-serif'"> </span><span lang="EN-US" style="font-size: 8pt;line-height: 115%;font-family: 'Courier New'">url</span><span lang="EN-US" style="font-size: 8pt;line-height: 115%;font-family: 'Calibri','sans-serif'"> </span><span lang="EN-US" style="font-size: 8pt;line-height: 115%;font-family: 'Courier New'">name</span><span lang="EN-US" style="font-size: 11pt;line-height: 115%;font-family: 'Calibri','sans-serif'">, </span><span lang="EN-US" style="font-size: 8pt;line-height: 115%;font-family: 'Courier New'">locale</span><span lang="EN-US" style="font-size: 8pt;line-height: 115%;font-family: 'Calibri','sans-serif'"> </span><span lang="EN-US" style="font-size: 8pt;line-height: 115%;font-family: 'Courier New'">id</span><span lang="EN-US" style="font-size: 11pt;line-height: 115%;font-family: 'Calibri','sans-serif'">, </span><span lang="EN-US" style="font-size: 8pt;line-height: 115%;font-family: 'Courier New'">template</span><span lang="EN-US" style="font-size: 11pt;line-height: 115%;font-family: 'Calibri','sans-serif'"> to be<br />
used, etc. See <a href="http://msdn2.microsoft.com/en-us/library/microsoft.sharepoint.spwebcollection.add.aspx">http://msdn2.microsoft.com/en-us/library/microsoft.sharepoint.spwebcollection.add.aspx</a><br />
.</span></font></p>
<p><font face="arial,helvetica,sans-serif"><span lang="EN-US" style="font-size: 11pt;line-height: 115%;font-family: 'Calibri','sans-serif'">With this other things that you have to think about<br />
are related with the </span><span lang="EN-US" style="font-size: 8pt;line-height: 115%;font-family: 'Courier New'">web permissions</span><span lang="EN-US" style="font-size: 11pt;line-height: 115%;font-family: 'Calibri','sans-serif'"> and </span><span lang="EN-US" style="font-size: 8pt;line-height: 115%;font-family: 'Courier New'">navigation<br />
nodes</span><span lang="EN-US" style="font-size: 11pt;line-height: 115%;font-family: 'Calibri','sans-serif'"><br />
(Quick Launch and Top Link Bar&rsquo;s).</span> <br /></font></p>
<p class="MsoNormalCxSpMiddle" style="line-height: normal"><font face="arial,helvetica,sans-serif"><span lang="EN-US" style="font-size: 11pt;line-height: 115%;font-family: 'Calibri','sans-serif'">I finish with a sample function that can be used as<br />
a starting point</span><span lang="EN-US" style="font-size: 8pt;font-family: 'Courier New'"></span></font><span lang="EN-US" style="font-size: 8pt;font-family: 'Courier New'"><font face="arial,helvetica,sans-serif">.</font><br /></span></p>
<p style="font-family: courier new,courier"><font size="1">public SPWeb AddWeb(SPWeb parentWeb, String title,<br />
String description, String relativeUrlName, UInt32 localeId, String template,<br />
Boolean useUniquePermissions, Boolean addToTopNavigationBar, Boolean<br />
addToSitesQuickLaunch)<br />{<br />&nbsp;&nbsp;&nbsp; // Create<br />&nbsp;&nbsp;&nbsp; SPWeb newWeb =<br />
parentWeb.Webs.Add(relativeUrlName, title, description, localeId, template,<br />
useUniquePermissions, false);&nbsp;</font></p>
<p style="font-family: courier new,courier"><font size="1">&nbsp;&nbsp;&nbsp; // Default uses parent navigation<br />&nbsp;&nbsp;&nbsp; newWeb.Navigation.UseShared = true;&nbsp;</font></p>
<p style="font-family: courier new,courier"><font size="1">&nbsp;&nbsp;&nbsp; // Test links to add<br />&nbsp;&nbsp;&nbsp; SPNavigationNode navigationNodeToAdd<br />
= new SPNavigationNode(title, relativeUrlName, false);<br />&nbsp;&nbsp;&nbsp; if (addToTopNavigationBar == true)<br />&nbsp;&nbsp;&nbsp; { // Add<br />&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; parentWeb.Navigation.TopNavigationBar.AddAsLast(navigationNodeToAdd);<br />&nbsp;&nbsp;&nbsp; }<br />&nbsp;&nbsp;&nbsp; if (addToSitesQuickLaunch == true)<br />&nbsp;&nbsp;&nbsp; { // Add to Quick launch sites<br />
section<br />&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; foreach (SPNavigationNode<br />
navigationNode in parentWeb.Navigation.QuickLaunch)<br />&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; { // Search sites<br />&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; if (navigationNode.Title ==<br />
&quot;Sites&quot;)<br />&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; { // Add here<br />&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; navigationNode.Children.AddAsLast(navigationNodeToAdd);<br />&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; // Stop<br />
searching<br />&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; break;<br />&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; }<br />&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; }<br />&nbsp;&nbsp;&nbsp; }<br />&nbsp;&nbsp;&nbsp; return newWeb; <br />}</font></p>
<p><font face="arial,helvetica,sans-serif"><span lang="EN-US" style="font-size: 11pt;line-height: 115%;font-family: 'Calibri','sans-serif'"><font face="arial,helvetica,sans-serif">By the way, the last part to add the navigation<br />
node to the Quick Launch Sites section is just an example that may not work if<br />
you are using sites in languages other than English</font>.</span></font></p>
<p>The post <a href="https://blogit.create.pt/marcosilva/2007/11/01/sharepoint-2007-basics-add-a-web/">SharePoint 2007 basics &#8211; Add a Web</a> appeared first on <a href="https://blogit.create.pt">Blog IT</a>.</p>
]]></content:encoded>
					
					<wfw:commentRss>https://blogit.create.pt/marcosilva/2007/11/01/sharepoint-2007-basics-add-a-web/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
			</item>
	</channel>
</rss>
