<?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>Welcome to ShanthaKumar&#039;s Blog, SharePoint and more... &#187; List</title>
	<atom:link href="http://www.ktskumar.com/blog/tag/list/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.ktskumar.com</link>
	<description>more Points to Share....</description>
	<lastBuildDate>Tue, 13 Dec 2011 17:36:09 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.2.1</generator>
		<item>
		<title>Catch the Unique Items from SharePoint List</title>
		<link>http://www.ktskumar.com/blog/2011/11/catch-the-unique-items-from-sharepoint-list/</link>
		<comments>http://www.ktskumar.com/blog/2011/11/catch-the-unique-items-from-sharepoint-list/#comments</comments>
		<pubDate>Wed, 30 Nov 2011 07:27:22 +0000</pubDate>
		<dc:creator>Shantha Kumar</dc:creator>
				<category><![CDATA[SharePoint]]></category>
		<category><![CDATA[SharePoint-2010]]></category>
		<category><![CDATA[List]]></category>
		<category><![CDATA[SharePoint 2010]]></category>
		<category><![CDATA[Unique]]></category>

		<guid isPermaLink="false">http://www.ktskumar.com/?p=528</guid>
		<description><![CDATA[I have lot of items from SharePoint List, but most of the items are duplicated. Here, I am going to give you a tips on getting unique rows from the List. For that, I googled for some time and then I found out there is no way to get the items based on CAML. So [...]]]></description>
			<content:encoded><![CDATA[<p>I have lot of items from SharePoint List, but most of the items are duplicated. Here, I am going to give you a tips on getting unique rows from the List. For that, I googled for some time and then I found out there is no way to get the items based on CAML.</p>
<p>So I tried to use LINQ to query the SharePoint Items. It works perfectly well for me. Here I provided my code to get the SharePoint Unique ListItems based on latest Items.</p>
<p>In the following example, I am first sorting the Items based on Modified field and then getting the unique item based on Title field by grouping.</p>
<p><code><strong><span style='color:#000066;'><br />
            using (SPSite site = new SPSite("http://localhost"))<br />
            {<br />
                using (SPWeb web = site.OpenWeb())<br />
                {<br />
                    SPList list = web.Lists.TryGetList("MyList");<br />
                    string Modi = "Modified";<br />
                    List<SPListItem> lstitems =<br />
                        (from l in list.Items.OfType&lt;SPListItem&gt;() orderby l[Modi] descending select l).ToList&lt;SPListItem&gt;();</span></strong></code></p>
<p><code><strong><span style='color:#000066;'>                    var listitemDistinct = lstitems.GroupBy(item1 => item1.Title, (key, group) => group.First()).ToList();</span></strong></code></p>
<p><code><strong><span style='color:#000066;'>                     foreach (SPListItem i in listitemDistinct)<br />
                    {<br />
                        Console.WriteLine("Title: " +i.Title +"Modified: " + i[Modi].ToString());<br />
                    }<br />
                }<br />
            }<br />
</span></strong></code></p>
<p>If the ListItems has the following items,</p>
<table>
<tr>
<td>ID</td>
<td>Title</td>
<td>Modified</td>
</tr>
<tr>
<td>1</td>
<td> Sample 1 </td>
<td> 11/16/2011</td>
</tr>
<tr>
<td>2</td>
<td> Sample 2 </td>
<td> 11/17/2011</td>
</tr>
<tr>
<td>3</td>
<td> Sample 1 </td>
<td> 11/18/2011</td>
</tr>
<tr>
<td>4</td>
<td> Sample 2 </td>
<td> 11/19/2011</td>
</tr>
</table>
<p>Result:<br />
Title: Sample 2 Modified: 11/19/2011<br />
Title: Sample 1 Modified: 11/18/2011</p>
]]></content:encoded>
			<wfw:commentRss>http://www.ktskumar.com/blog/2011/11/catch-the-unique-items-from-sharepoint-list/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Updating SharePoint ListItems</title>
		<link>http://www.ktskumar.com/blog/2011/03/updating-sharepoint-listitems/</link>
		<comments>http://www.ktskumar.com/blog/2011/03/updating-sharepoint-listitems/#comments</comments>
		<pubDate>Sun, 06 Mar 2011 03:08:23 +0000</pubDate>
		<dc:creator>Shantha Kumar</dc:creator>
				<category><![CDATA[SharePoint-2010]]></category>
		<category><![CDATA[List]]></category>
		<category><![CDATA[Server Object Model]]></category>
		<category><![CDATA[SharePoint]]></category>

		<guid isPermaLink="false">http://www.ktskumar.com/?p=423</guid>
		<description><![CDATA[There are two methods available to update the List Items on SPListItem Object. SPListItem.Update(); SPListItem.SystemUpdate(); SPListItem.Update() used to update all the values in SharePoint List Item including pre-defined hidden fields. If we modified the item, that will affects the Modified Date, Modified By, Version information fields. SPList olist = oweb.Lists.TryGetList(&#8220;ListName&#8221;); SPListItem olistitem = olist.Items[1]; olistitem.Title [...]]]></description>
			<content:encoded><![CDATA[<p>There are two methods available to update the List Items on SPListItem Object.<br />
<strong>SPListItem.Update();<br />
SPListItem.SystemUpdate()</strong>;</p>
<p><strong>SPListItem.Update()</strong> used to update all the values in SharePoint List Item including pre-defined hidden fields. If we modified the item, that will affects the Modified Date, Modified By, Version information fields.</p>
<p><em><span style="color: #008000;">SPList olist = oweb.Lists.TryGetList(&#8220;ListName&#8221;);<br />
SPListItem olistitem = olist.Items[1];<br />
olistitem.Title = &#8220;Sample List Item&#8221;<br />
olistitem.Update();<br />
olist.Update();</span></em></p>
<p><strong>SPListItem.SystemUpdate()</strong> method used to update the values of the listitem without modifying the Modified Date, Modified By and Version information fields.</p>
<p><span style="color: #008000;"><em>SPList olist = oweb.Lists.TryGetList(&#8220;ListName&#8221;);<br />
SPListItem olistitem = olist.Items[1];<br />
olistitem.Title = &#8220;Sample List Item&#8221;<br />
olistitem.SystemUpdate();<br />
olist.Update();</em></span></p>
]]></content:encoded>
			<wfw:commentRss>http://www.ktskumar.com/blog/2011/03/updating-sharepoint-listitems/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>SharePoint Daily Alerts &#8211; 3</title>
		<link>http://www.ktskumar.com/blog/2011/01/sharepoint-daily-alerts-3/</link>
		<comments>http://www.ktskumar.com/blog/2011/01/sharepoint-daily-alerts-3/#comments</comments>
		<pubDate>Mon, 03 Jan 2011 17:54:21 +0000</pubDate>
		<dc:creator>Shantha Kumar</dc:creator>
				<category><![CDATA[SharePoint Daily Alerts]]></category>
		<category><![CDATA[List]]></category>
		<category><![CDATA[Lookup]]></category>
		<category><![CDATA[Permissions]]></category>

		<guid isPermaLink="false">http://www.ktskumar.com/?p=377</guid>
		<description><![CDATA[If the user want to choose cascade or Restrict option for the lookup field, that user must have the ManageLists permission for the Lookup List. To View the list of Permissions, check the SPBasePermissions enumeration.]]></description>
			<content:encoded><![CDATA[<p>If the user want to choose <strong><em>cascade</em></strong> or <em><strong>Restrict</strong></em> option for the lookup field, that user must have the <strong>ManageLists</strong> permission for the Lookup List.<br />
To View the list of Permissions, check the <a href="http://msdn.microsoft.com/en-us/library/microsoft.sharepoint.spbasepermissions.aspx" target="_blank">SPBasePermissions</a> enumeration.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.ktskumar.com/blog/2011/01/sharepoint-daily-alerts-3/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>How to get InternalName in ListEdit Page</title>
		<link>http://www.ktskumar.com/blog/2009/09/how-to-get-internalname-in-listedit-page/</link>
		<comments>http://www.ktskumar.com/blog/2009/09/how-to-get-internalname-in-listedit-page/#comments</comments>
		<pubDate>Fri, 25 Sep 2009 01:09:08 +0000</pubDate>
		<dc:creator>Shantha Kumar</dc:creator>
				<category><![CDATA[SharePoint]]></category>
		<category><![CDATA[Coulmns]]></category>
		<category><![CDATA[Customize]]></category>
		<category><![CDATA[Field]]></category>
		<category><![CDATA[InternalName]]></category>
		<category><![CDATA[List]]></category>
		<category><![CDATA[listedit]]></category>
		<category><![CDATA[spField]]></category>

		<guid isPermaLink="false">http://ktskumar.com/blog/?p=242</guid>
		<description><![CDATA[In SharePoint the column or field has two names. One is DisplayName, used to view the field name publically in all pages and another is InternalName used internally to refer the Field. This Internal name will be used in CAML Queries, during retreiving inserting and updating the list item.We can&#8217;t see this Internal name in any pages [...]]]></description>
			<content:encoded><![CDATA[<p>In SharePoint the column or field has two names. One is DisplayName, used to view the field name publically in all pages and another is InternalName used internally to refer the Field. This Internal name will be used in CAML Queries, during retreiving inserting and updating the list item.We can&#8217;t see this Internal name in any pages normally, but we can do some work around for getting this internalnames, such as writing the code  &amp; look in to the url of the particular field.</p>
<p>Now i giving a simple tip on displaying the InternalName on ListEdit page itself, this will help us in knowing internal name quickly and consume the time when we work up on List and ListItems.</p>
<div style="margin:left:0px">
<ul>
<li>For that, we have to edit the ListEdit.aspx page, which is available under &lt;System Folder&gt;:Program FilesCommon FilesMicrosoft Sharedweb server extensions12TEMPLATELAYOUTS</li>
<li>Before going to edit that page, backup that file and open it. This is the screenshot, taken before editing the page,<br />
<a href="http://www.ktskumar.com/wp-content/uploads/2009/09/lstedit1.jpg" target=_blank"><img src="http://www.ktskumar.com/wp-content/uploads/2009/09/lstedit1.jpg" alt="Displaying ListEdit Page without Internal Names" /></a></li>
<li>In the ListEdit page, add the Column as InternalName under Columns section,To add the header for Internalname under Columns section, Search for the following line<br />
<em>for (Int32 iIndex = 0; iIndex &lt; spFields.Count; iIndex ++ )</em></li>
<li>At first we have to add the header column, for that before the above searched  line there is &lt;TR&gt; tag with three header &lt;TH&gt; tags, add the following &lt;TH&gt; within the &lt;TR&gt; tag,<strong>&lt;TH scope=&#8221;col&#8221;-vh2-nofilter width=25% id=&#8221;TH1&#8243;&gt;Internal Name&lt;/TH&gt;</strong>After adding the line, the code look like this,
<div class="codecss" style="font-size:11px;">&lt;TR&gt;<br />
&lt;TH scope=&#8221;col&#8221;-vh2-nofilter width=25% id=&#8221;1600&#8243;&gt;<br />
&lt;SharePoint:EncodedLiteral runat=&#8221;server&#8221; text=&#8221;&lt;%$Resources:wss,listedit_columnclicktoedit%&gt;&#8221; EncodeMethod=&#8217;HtmlEncode&#8217;/&gt;<br />
&lt;/TH&gt;<br />
&lt;TH scope=&#8221;col&#8221;-vh2-nofilter width=25% id=&#8221;1700&#8243;&gt;<br />
&lt;SharePoint:EncodedLiteral runat=&#8221;server&#8221; text=&#8221;&lt;%$Resources:wss,listedit_type%&gt;&#8221; EncodeMethod=&#8217;HtmlEncode&#8217;/&gt;<br />
&lt;/TH&gt;<br />
&lt;TH scope=&#8221;col&#8221;-vh2-nofilter colspan=2 id=&#8221;1800&#8243;&gt;<br />
&lt;% if (!spList.ContentTypesEnabled) { %&gt;<br />
&lt;SharePoint:EncodedLiteral runat=&#8221;server&#8221; text=&#8221;&lt;%$Resources:wss,listedit_required%&gt;&#8221; EncodeMethod=&#8217;HtmlEncode&#8217;/&gt;<br />
&lt;% } else { %&gt;<br />
&lt;SharePoint:EncodedLiteral runat=&#8221;server&#8221; text=&#8221;&lt;%$Resources:wss,listedit_used_in%&gt;&#8221; EncodeMethod=&#8217;HtmlEncode&#8217;/&gt;<br />
&lt;% } %&gt;<br />
&lt;/TH&gt;<br />
<strong>&lt;TH scope=&#8221;col&#8221;-vh2-nofilter width=25% id=&#8221;TH1&#8243;&gt;Internal Name&lt;/TH&gt;<br />
</strong>&lt;/TR&gt;<br />
for (Int32 iIndex = 0; iIndex &lt; spFields.Count; iIndex ++ )
</div>
</li>
<li>And then we have to add the InternalName for each field type, for that<br />
Search for the following if condition line,</p>
<p><em>if (spField.ReadOnlyField &amp;&amp; !bCountRelated)</em></p>
<p>The above line checks the current field is read only or not, by default the read only fields are User and Calculated Columns</li>
<li>If you look in to the page, you can able to see the switch case statement under the if condition. Switch case statement checks the each read-only field type and adding the row contents such as (Display name, field type and Require or not) columns based on the field type,so we have to add the following line (column) within each case statement,
<p><strong>&lt;TD-vb2&gt;&lt;%SPHttpUtility.UrlKeyValueEncode(spField.InternalName, Response.Output);%&gt;&lt;/TD&gt;</strong></p>
<p>In this page, spField.InternalName displays the Internal Name for the current field type.</p>
<p>The above TD tag content ensures that, the each field row has its own Internalname</li>
<li>The else condition refers to the non-read only fields, If we add this line <strong>&lt;TD-vb2&gt;&lt;%SPHttpUtility.UrlKeyValueEncode(spField.InternalName, Response.Output);%&gt;&lt;/TD&gt;</strong>, the internal Name will be appeared on all the non-read only field types.</li>
<p>After adding all the lines, the code for the if and else condition will be look like this,</p>
<div class="codecss" style="font-size:11px;">if (spField.ReadOnlyField &amp;&amp; !bCountRelated)<br />
{<br />
switch (spField.Type)<br />
{<br />
case SPFieldType.Calculated:<br />
rowClass = (rowClass == &#8220;&#8221;)? &#8220;ms-alternating&#8221; : &#8220;&#8221;;<br />
%&gt;<br />
&lt;TR&gt;<br />
&lt;TD-vb2&gt;<br />
&lt;A ID=&#8221;LinkEditField&lt;%= Convert.ToString(iIndex) %&gt;&#8221; HREF=&#8221;FldEdit.aspx?List=&lt;%SPHttpUtility.UrlKeyValueEncode(spList.ID.ToString(&#8220;B&#8221;).ToUpper(), Response.Output);%&gt;&amp;Field=&lt;%SPHttpUtility.UrlKeyValueEncode(spField.InternalName, Response.Output);%&gt;&#8221;&gt; &lt;%SPHttpUtility.HtmlEncode(spField.Title,Response.Output);%&gt;<br />
&lt;/A&gt;<br />
&lt;/TD&gt;<br />
&lt;TD-vb2&gt;<br />
&lt;SharePoint:EncodedLiteral runat=&#8221;server&#8221; text=&#8221;&lt;%$Resources:wss,listedit_calculated%&gt;&#8221; EncodeMethod=&#8217;HtmlEncode&#8217;/&gt;<br />
&lt;/TD&gt;<br />
&lt;TD colspan=2-vb2&gt;<br />
&lt;%SPHttpUtility.HtmlEncode(GetUsedIn(spField), Response.Output);%&gt;<br />
&lt;/TD&gt;<br />
<strong>&lt;TD-vb2&gt;<br />
&lt;%SPHttpUtility.UrlKeyValueEncode(spField.InternalName, Response.Output);%&gt;<br />
&lt;/TD&gt;</strong><br />
&lt;/TR&gt;<br />
&lt;%<br />
break;<br />
case SPFieldType.User:<br />
rowClass = (rowClass == &#8220;&#8221;)? &#8220;ms-alternating&#8221; : &#8220;&#8221;;<br />
%&gt;<br />
&lt;TR&gt;<br />
&lt;TD-vb2&gt;<br />
&lt;A ID=&#8221;LinkEditField&lt;%= Convert.ToString(iIndex) %&gt;&#8221; HREF=&#8221;FldEditEx.aspx?List=&lt;%SPHttpUtility.UrlKeyValueEncode(spList.ID.ToString(&#8220;B&#8221;).ToUpper(), Response.Output);%&gt;&amp;Field=&lt;%SPHttpUtility.UrlKeyValueEncode(spField.InternalName, Response.Output);%&gt;&#8221; &gt; &lt;%SPHttpUtility.HtmlEncode(spField.Title,Response.Output);%&gt;&lt;/A&gt;<br />
&lt;/TD&gt;<br />
&lt;TD-vb2&gt;&lt;%SPHttpUtility.HtmlEncode(spField.TypeDisplayName, Response.Output);%&gt;<br />
&lt;/TD&gt;<br />
&lt;TD colspan=2-vb2&gt;&lt;%SPHttpUtility.HtmlEncode(GetUsedIn(spField), Response.Output);%&gt;<br />
&lt;/TD&gt;<br />
<strong>&lt;TD-vb2&gt;<br />
&lt;%SPHttpUtility.UrlKeyValueEncode(spField.InternalName, Response.Output);%&gt;<br />
&lt;/TD&gt;<br />
</strong>&lt;/TR&gt;<br />
&lt;%<br />
break;<br />
default:<br />
if (spField.XPath != null &amp;&amp; !spField.Hidden)<br />
{<br />
%&gt;<br />
&lt;TR&gt;<br />
&lt;TD-vb2&gt;<br />
&lt;%SPHttpUtility.HtmlEncode(spField.Title,Response.Output);%&gt;<br />
&lt;/TD&gt;<br />
&lt;TD-vb2&gt;&lt;%SPHttpUtility.HtmlEncode(spField.TypeDisplayName, Response.Output);%&gt;&lt;/TD&gt;<br />
&lt;TD colspan=2-vb2&gt;<br />
&lt;% if ( !spList.ContentTypesEnabled &amp;&amp; spField.Required == true ) { %&gt; &lt;IMG SRC=&#8221;/_layouts/images/check.gif&#8221; alt=&#8221;Checked&#8221;&gt; &lt;% ; } %&gt;<br />
&lt;%SPHttpUtility.HtmlEncode(GetUsedIn(spField), Response.Output);%&gt;<br />
&lt;/TD&gt;<br />
<strong>&lt;TD-vb2&gt;<br />
&lt;%SPHttpUtility.UrlKeyValueEncode(spField.InternalName, Response.Output);%&gt;<br />
&lt;/TD&gt;<br />
</strong>&lt;/TR&gt;<br />
&lt;%<br />
}<br />
break;<br />
}<br />
}<br />
else<br />
{<br />
rowClass = (rowClass == &#8220;&#8221;)? &#8220;ms-alternating&#8221; : &#8220;&#8221;;<br />
%&gt;<br />
&lt;TR&gt;&lt;TD-vb2&gt;<br />
&lt;%if (Enum.IsDefined(typeof(SPFieldType), spField.TypeAsString) &amp;&amp; spField.Type != SPFieldType.Lookup &amp;&amp; spField.Type != SPFieldType.User) {%&gt;<br />
&lt;A ID=&#8221;LinkEditField&lt;%= Convert.ToString(iIndex) %&gt;&#8221; HREF=&#8221;FldEdit.aspx?List=&lt;%SPHttpUtility.UrlKeyValueEncode(spList.ID.ToString(&#8220;B&#8221;).ToUpper(), Response.Output);%&gt;&amp;Field=&lt;%SPHttpUtility.UrlKeyValueEncode(spField.InternalName, Response.Output);%&gt;&#8221;&gt; &lt;%SPHttpUtility.HtmlEncode(spField.Title,Response.Output);%&gt;&lt;/A&gt;<br />
&lt;%} else {%&gt;<br />
&lt;A ID=&#8221;LinkEditField&lt;%= Convert.ToString(iIndex) %&gt;&#8221; HREF=&#8221;FldEditEx.aspx?List=&lt;%SPHttpUtility.UrlKeyValueEncode(spList.ID.ToString(&#8220;B&#8221;).ToUpper(), Response.Output);%&gt;&amp;Field=&lt;%SPHttpUtility.UrlKeyValueEncode(spField.InternalName, Response.Output);%&gt;&#8221;&gt; &lt;%SPHttpUtility.HtmlEncode(spField.Title,Response.Output);%&gt;&lt;/A&gt;<br />
&lt;%}%&gt;<br />
&lt;/TD&gt;<br />
&lt;TD-vb2&gt;&lt;%SPHttpUtility.HtmlEncode(spField.TypeDisplayName, Response.Output);%&gt;&lt;/TD&gt;<br />
&lt;TD<br />
colspan=2<br />
class=ms-vb2&gt;<br />
&lt;% if ( !spList.ContentTypesEnabled &amp;&amp; spField.Required == true ) { %&gt; &lt;IMG SRC=&#8221;/_layouts/images/check.gif&#8221; alt=&#8221;Checked&#8221;&gt; &lt;% ; } %&gt;<br />
&lt;%SPHttpUtility.HtmlEncode(GetUsedIn(spField), Response.Output);%&gt;<br />
&lt;/TD&gt;<br />
<strong>&lt;TD-vb2&gt;<br />
&lt;%SPHttpUtility.UrlKeyValueEncode(spField.InternalName, Response.Output);%&gt;<br />
&lt;/TD&gt;</strong><br />
&lt;/TR&gt;<br />
&lt;%<br />
}</div>
<p>The final outcome will be as follows,<br />
<a href="http://www.ktskumar.com/wp-content/uploads/2009/09/lstedit2.jpg" target="_blank"><img src="http://www.ktskumar.com/wp-content/uploads/2009/09/lstedit2.jpg" alt="Displaying ListEdit Page with Internal Names" /></a></ul>
</div>
<p>To download the listedit.aspx page, click <a href="http://www.ktskumar.com/wp-content/uploads/2009/09/listedit.txt" target="_blank">here</a>!</p>
]]></content:encoded>
			<wfw:commentRss>http://www.ktskumar.com/blog/2009/09/how-to-get-internalname-in-listedit-page/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>Uploading File from Local Machine to SharePoint ListItem as an attachment</title>
		<link>http://www.ktskumar.com/blog/2008/03/uploading-file-from-local-machine-to-sharepoint-listitem-as-an-attachment/</link>
		<comments>http://www.ktskumar.com/blog/2008/03/uploading-file-from-local-machine-to-sharepoint-listitem-as-an-attachment/#comments</comments>
		<pubDate>Mon, 31 Mar 2008 05:04:19 +0000</pubDate>
		<dc:creator>Shantha Kumar</dc:creator>
				<category><![CDATA[SharePoint]]></category>
		<category><![CDATA[Attachment]]></category>
		<category><![CDATA[File]]></category>
		<category><![CDATA[List]]></category>
		<category><![CDATA[ListIte]]></category>
		<category><![CDATA[MOSS]]></category>
		<category><![CDATA[Upload]]></category>

		<guid isPermaLink="false">http://ktskumar.wordpress.com/?p=17</guid>
		<description><![CDATA[To attach the file from Local Machine to SharePoint ListItem as an attachment, Import the System.IO namespace to use the Stream Class to read the file contents. Use System.Web.UI.WebControls.FileUpload control is named as fileUpload in code. Sample code for uploading the file from Local Machine to ListItem attachments as follows, //Check the FileUpload control has the [...]]]></description>
			<content:encoded><![CDATA[<p style="margin:0 0 10pt;" class="MsoNormal"><font face="Times New Roman">To attach the file from Local Machine to SharePoint ListItem as an attachment, </font><span style="font-size:11pt;line-height:115%;font-family:Calibri;"><font face="Times New Roman">Import the <strong>System.IO</strong> namespace to use the <strong>Stream</strong> Class to read the file contents.</font></span></p>
<p><span style="font-size:11pt;line-height:115%;font-family:Calibri;"></span><span style="font-size:11pt;line-height:115%;font-family:Calibri;"></span><span style="font-size:11pt;line-height:115%;font-family:Calibri;"></span><span style="font-size:11pt;line-height:115%;font-family:Calibri;"></span><span style="font-size:11pt;line-height:115%;font-family:Calibri;"></p>
<p style="margin:0 0 10pt;" class="MsoNormal"><font face="Times New Roman">Use System.Web.UI.WebControls.FileUpload control is named as fileUpload in code. </font></p>
<p style="margin:0 0 10pt;" class="MsoNormal">Sample code for uploading the file from Local Machine to ListItem attachments as follows,</p>
<p><span style="font-size:10pt;color:green;font-family:'Courier New';">//Check the FileUpload control has the file</span></p>
<p><span style="font-size:10pt;color:green;font-family:'Courier New';"></span><span style="font-size:10pt;color:blue;font-family:'Courier New';">if</span><span style="font-size:10pt;font-family:'Courier New';"> (fileUpload.PostedFile != <span style="color:blue;">null</span>)</span></p>
<p><span style="font-size:10pt;font-family:'Courier New';"></span><span style="font-size:10pt;font-family:'Courier New';"></span><span style="font-size:10pt;font-family:'Courier New';">{</span><span style="font-size:10pt;font-family:'Courier New';">item = list.Items.Add();</span></p>
<p><span style="font-size:10pt;font-family:'Courier New';"></span><span style="font-size:10pt;font-family:'Courier New';">item[<span style="color:#a31515;">"Title"</span>] = fileUpload.FileName;</span></p>
<p><span style="font-size:10pt;font-family:'Courier New';"></span><span style="font-size:10pt;color:green;font-family:'Courier New';">//Read the Contents from the file in Local machine</span></p>
<p><span style="font-size:10pt;color:green;font-family:'Courier New';"></span><span style="font-size:10pt;color:#2b91af;font-family:'Courier New';">Stream</span><span style="font-size:10pt;font-family:'Courier New';"> fs = fileUpload.PostedFile.InputStream;<span>                    </span></span></p>
<p><span style="font-size:10pt;font-family:'Courier New';"><span></span></span><span style="font-size:10pt;color:blue;font-family:'Courier New';">byte</span><span style="font-size:10pt;font-family:'Courier New';">[] fileContents = <span style="color:blue;">new</span> <span style="color:blue;">byte</span>[fs.Length];</span></p>
<p><span style="font-size:10pt;font-family:'Courier New';"></span><span style="font-size:10pt;font-family:'Courier New';">fs.Read(fileContents, 0, (<span style="color:blue;">int</span>)fs.Length);</span></p>
<p><span style="font-size:10pt;font-family:'Courier New';"></span><span style="font-size:10pt;font-family:'Courier New';">fs.Close();</span></p>
<p><span style="font-size:10pt;font-family:'Courier New';"></span><span style="font-size:10pt;color:green;font-family:'Courier New';">// Add the file to the ListItem as an Attachment</span></p>
<p><span style="font-size:10pt;color:green;font-family:'Courier New';"></span><span style="font-size:10pt;color:#2b91af;font-family:'Courier New';">SPAttachmentCollection</span><span style="font-size:10pt;font-family:'Courier New';"> attachments = item.Attachments;</span></p>
<p><span style="font-size:10pt;font-family:'Courier New';"></span><span style="font-size:10pt;color:blue;font-family:'Courier New';">string</span><span style="font-size:10pt;font-family:'Courier New';"> fileName = <span style="color:#2b91af;">Path</span>.GetFileName(fileUpload.PostedFile.FileName);</span></p>
<p><span style="font-size:10pt;font-family:'Courier New';"></span><span style="font-size:10pt;font-family:'Courier New';">attachments.Add(fileName, fileContents);</span><span style="font-size:10pt;font-family:'Courier New';"><span> </span></span></p>
<p><span style="font-size:10pt;font-family:'Courier New';"><span></span>item.Update();<span>                                            </span></span></p>
<p style="margin:0 0 10pt;" class="MsoNormal"><span style="font-size:10pt;line-height:115%;font-family:'Courier New';">}</span></p>
<p></span></p>
]]></content:encoded>
			<wfw:commentRss>http://www.ktskumar.com/blog/2008/03/uploading-file-from-local-machine-to-sharepoint-listitem-as-an-attachment/feed/</wfw:commentRss>
		<slash:comments>4</slash:comments>
		</item>
	</channel>
</rss>

