Skip to main content

Posts

Showing posts with the label Object Model

Object Model SPListItem Class

You can use an indexer to return a single item from a list item collection. For example, if the collection is assigned to a variable named  collListItems , use  collListItems[ index ]  in Microsoft C#, or  collListItems( index )  in Microsoft Visual Basic, where  index  is the index number of the item in the collection, or the internal name or display name of a list field. For an indexer based on a name, Microsoft SharePoint Foundation first looks for the field by internal name and then by display name. To assign values to a field in a list item using an indexer, the values must be represented in a format that is appropriate for each built-in field type. The following table shows how the data types that are used in SharePoint Foundation field types map to Microsoft .NET Framework types. Name Format Attachments System.Boolean Boolean System.Boolean Calculated N/A Choice System.String Computed N/A Counter Syste...

SharePoint 2010: Attach files to List/Library using Managed Client Object Model

Client Objet Model (OM) is a great new addition in SharePoint 2010. I have discussed before how to manipulate lists and list items using Managed Object Model. Today I’ll discuss on how to attach file to list item or add file to library using Managed Client Object Model. Upload File in Library The following code snippet shows how to upload file in document library: public void UploadFileInLibrary( string siteUrl, string webName, string libraryName, string subfolderPath, string fileName) { using (ClientContext clientContext = new ClientContext(siteUrl)) { string uploadLocation = Path.GetFileName(fileName); if (! string .IsNullOrEmpty(subfolderPath)) { uploadLocation = string .Format( "{0}/{1}" , subfolderPath, uploadLocation); } uploadLocation = string .Format( "/{0}/{1}/{2}" , webName, libraryName, uploadLocation); var list = clientContext.Web.Lists.GetByTitle(libraryName); ...