Attach a custom content type and set as default for picture library using client object model

Hi,
How to associate custom content type to a picture libraray and set it as default using the client object model?
Thanks

Hello,
Here you go:
http://social.msdn.microsoft.com/Forums/sharepoint/en-US/b1de0697-0006-4f89-8909-1b94aa18ad89/how-to-reorder-content-types-in-list-with-client-context
http://www.niteenbadgujar.com/2013/05/change-default-content-type.html
Hope it could help
Hemendra:Yesterday is just a memory,Tomorrow we may never see
Please remember to mark the replies as answers if they help and unmark them if they provide no help

Similar Messages

  • Setting the default value to taxonomy column in sharepoint 2010 using client object model

    I am creating a metadata column and I want to set its default value in sharepoint 2010 using client object model. Can anyone help me?
    My code for creating metadata column is as below:
                ClientContext clientContext = new ClientContext(siteUrl);
                Web site = clientContext.Web;
                List list = site.Lists.GetByTitle("LibraryName");
                FieldCollection collField = list.Fields;
                string fieldSchema = "<Field Type='TaxonomyFieldType' DisplayName='SoftwareColumn' Name='SoftwareColumn' />";
                collField.AddFieldAsXml(fieldSchema, true, AddFieldOptions.DefaultValue);
                //oneField.DefaultValue = "ASP.NET|4c984b91-b308-4884-b1f1-aee5d7ed58b2"; // wssId[0].ToString() + ";#" + term.Name + "|" + term.Id.ToString().ToLower();
                clientContext.Load(collField);           
                clientContext.ExecuteQuery();

    Hi,
    Please try the code like this:
    ClientContext clientContext = new ClientContext("http://yoursite/");
    List list = clientContext.Web.Lists.GetByTitle("List1_mmsfield");
    clientContext.Load(list);
    clientContext.ExecuteQuery();
    FieldCollection fields = list.Fields;
    clientContext.Load(fields);
    clientContext.ExecuteQuery();
    Field f = fields.GetByTitle("mms");
    clientContext.Load(f);
    clientContext.ExecuteQuery();
    Console.WriteLine(f.Title + "---" + f.DefaultValue);
    //2;#A2|a0a95267-b758-4e4d-8c39-067069fd2eef
    //1;#A1|641f5726-992c-41c8-9ddc-204a60b88584
    f.DefaultValue = "1;#A1|641f5726-992c-41c8-9ddc-204a60b88584";
    f.Update();
    clientContext.Load(f);
    clientContext.ExecuteQuery();
    Console.WriteLine(f.Title + "---" + f.DefaultValue);
    Best regards
    Patrick Liang
    TechNet Community Support

  • How to activate Custom Feature in SharePoint 2010 using Client Object model

    I am trying to Activate a custom feature using Client Object Model in SharePoint 2010. Here is the code I used. When I execute the code, I got the error "Feature with Id 'xx' is not installed in this farm, and cannot be added to this scope while
    creating site collection". Can anyone help?
    ClientContext clientContext = new ClientContext(spURL);
    //GUID of the custom feature                    
    Guid districtFeatureId = new Guid("5b3529de-5045-46da-af87-8d2e32c121a7");
    Site clientSite = clientContext.Site;
    FeatureCollection clientSiteFeatures = clientSite.Features;
    clientContext.Load(clientSiteFeatures);
    clientContext.ExecuteQuery();
    //Activate the feature
    clientSiteFeatures.Add(districtFeatureId, false, FeatureDefinitionScope.Site);
    clientContext.ExecuteQuery();

    Hi shil chan,
    When you activate a feature on the site collection, the feature should be scoped to site or farm, the error message shows it cannot find the specific feature, this will happen when you have a feature in web
    scope or the feature isn’t installed.  
    So, to troubleshooting this issue:
    Verify whether the feature is scoped to web. Please go to
    Site Setting->Site Features . If the feature is a web scope feature, then add the feature to webfeatures.
    Make sure the feature is installed correctly.
    Please inform me freely if you have any questions.
    Thanks

  • Assigning External content type field column value using Client Object Model

    I have a problem assinging External column value to ListItem object with client object model-based application I'm developing. To be precise, I am able to retrieve data related to external content type by reading external list created from this content type
    but I don't know how to properly use it to assign value to this field. By doing some research on my own I concluded that BDC ID column from external list is the way to go since it uniquely defines selected row from external list but that doesn't
    tell me much since I don't know what to do with it. Currently I ended up with partial solution - to assign plain string value of picker column but that makes this value visible only in "View Properties" option on Sharepoint and not in "Edit Properties"
    which pritty much makes sence since it isn't properly related to rest of the data in specific row. Does someone have a better solution for this?
    Igor S.

    I think I understand your problem.
    In my example I have an external data column "Beneficiary Name", using a Beneficiary external content type (accessing a table of beneficiaries in a SQL table).
    I want to set the "Beneficiary Name" property using the client object model. I know the name of the beneficiary but not the ID value.
    It is a fairly simple solution. You just need to identify the name of the property SharePoint assigns to the ID field, in my case it is called "Beneficiary_ID". Then set the two properties as follows:
    thisItem["Beneficiary_Name"] = "Charitable Trust";
    thisItem["Beneficiary_ID"] = -1;
    thisItem.Update();
    Setting the ID property to -1 causes the server to do an automatic lookup for the ID from the value assigned to the item.

  • To extract the users permission on files and folders in sharepoint 2010 using client object model

    To extract the users permission on files and folders in sharepoint 2010 using client object model

    Hello,
    This is sample code to get item level permisison: (Just written in notepad so it is not tested)
    public void ItemLevelPermission()
    SecurableObject curObj = null;
    ListItem curItem = ctx.Web.Lists.GetByTitle("LibraryName").GetItemById(ItemId); -> Use Id of file or folder.
    IEnumerable roles = null;
    roles = ctx.LoadQuery(
    curObj.RoleAssignments.Include(
    roleAsg => roleAsg.Member,
    roleAsg => roleAsg.RoleDefinitionBindings.Include(
    roleDef => roleDef.Name, // for each role definition, include roleDef’s Name
    roleDef => roleDef.Description)));
    ctx.ExecuteQuery();
    Hope it could help
    Hemendra:Yesterday is just a memory,Tomorrow we may never see
    Please remember to mark the replies as answers if they help and unmark them if they provide no help

  • Custom content type and choice field

    Hi,
    I try to create costum content type in visual studio, and I want to add choice field to this content type, but I didn't found, how can I programmatically fill choice datasource
    Can anyone help me?
    Thanks,
    Mykie

    I've only done this one but I seem to recall packaging these up as XML as normal columns and sompl referenced them in the Content type definition.  Having had a quick look on the inertubes for a refresher, I think this might point you in the right direction.
    http://www.skylinetechnologies.com/Blog/Article/76/Creating-Lists-in-SharePoint-Using-Visual-Studio-2012.aspx
    Something like this should be your end product.
    Steven Andrews
    SharePoint Business Analyst: LiveNation Entertainment
    Blog: baron72.wordpress.com
    Twitter: Follow @backpackerd00d
    My Wiki Articles:
    CodePlex Corner Series
    Please remember to mark your question as "answered" if this solves (or helps) your problem.

  • How to Set Item limit for Picture library Slideshow webpart in SharePoint 2013

    Picture library Slideshow webpart is using the default view "All Pictures" and if I set a filter condition in the view, the images are displaying based on it but if I set an Item limit as "5" or any number in the "All Pictures"
    view it is not reflecting in the slideshow webpart.
    Any suggestion would be a great help as the users want to see only the latest 5 images in the slideshow webpart.
    Thanks & regards,
    Asha

    I don't think so there is any way to set a item count limit on Picture Library Slideshow web wart.
    Web Part setting only allows to provide library and View, In List view also you can only set Item Limit to be shown on the 'List View'. Slideshow web part take all the items in the list and show, view is only used to provide which field needs to be shown.
    There could be 2 options:
    - Write a JavaScript to limit the count, and in the view add Sorting by 'Created' date. You can get some example on how to modify "Library Slideshow web part" javascript here: http://blog.vgrem.com/2013/04/27/beyond-the-slideshow-web-part-capabilities-in-sharepoint-2010/
     This link does not have solution of what you want, but it gives a very well idea on what you can look and modify. It will not be that straight forward for sure.
     - Create a custom webpart, it could be a easier approach. As there are many slideshow Javascript library present, and through code you will just need do a query and pull data from library with required number of items to be shown.
    get2pallav
    Please click "Propose As Answer" if this post solves your problem or "Vote As Helpful" if this post has been useful to you.

  • How to connect sharepoint online using client object model and authentictae against window login

    Iam developing A console application where in need to connect to sharepoint online and authenticate against window login can u please suggest me the code

    Hi,
    There is couple of helper method to check and validate the SPO credentials in the same solution.
    string userName = GetUserName();
    SecureString pwd = GetPassword();
    /* End Program if no Credentials */
    if (string.IsNullOrEmpty(userName) || (pwd == null))
    return;
    // Open connection to Office365 tenant
    ClientContext cc = new ClientContext(siteUrl);
    cc.AuthenticationMode = ClientAuthenticationMode.Default;
    cc.Credentials = new SharePointOnlineCredentials(userName, pwd);
    if you give incorrect user name or password it will throws an exception in the console.
    Murugesa Pandian.,SharePoint 2010 MCPD | MCTS|Configure

  • Custome Content type can't be seen in remote system

    hi,
    i have 2 systems on LAN. i have created site with document library, and created custom content types and added them to my document library everything works fine on the server system and i can see those templates when i click new in document library.
    Problem is since i have 2 systems on Lan, i am accessing that site from another system it logged in successfully and when i go to my document library and click on new i don't see any custom templates but i can see them in document library settings :( whats
    the wrong thing i am doing????
    i am using sharepoint server 2007 build 12.0.0.6679 and MS office 2007.
    please help me.

    I believe this is a known bug that is set to be fixed in the next service pack release (due out in June).

  • Sharepoint client object model - Pull files from one site and move to another

    Dear All,
    I am using client object model to retrieve files of certain criteria using caml query and copy them to some other site using 
    client object model. There is no exception being thrown, but the application is not performing either. No files are being copied to destination. Here is the code. Please advise.
    The message box that I have kept at the end is being displayed, but no files are being copied.
    using System;
    using System.Collections.Generic;
    using System.ComponentModel;
    using System.Data;
    using System.Net;
    using System.Drawing;
    using System.Linq;
    using System.Text;
    using System.Windows.Forms;
    using Microsoft.SharePoint;
    using SP = Microsoft.SharePoint.Client;
    namespace WindowsFormsApplication2
        public partial class Form1 : Form
            public Form1()
                InitializeComponent();
            private void Form1_Load(object sender, EventArgs e)
            private void button1_Click(object sender, EventArgs e)
                SP.ClientContext srcContext = new SP.ClientContext(textBox1.Text);
                srcContext.Credentials = new NetworkCredential(textBox3.Text, textBox4.Text, textBox5.Text);
                SP.ClientContext destContext = new SP.ClientContext(textBox2.Text);
                destContext.Credentials = new NetworkCredential(textBox3.Text, textBox4.Text, textBox5.Text);
                SP.CamlQuery camlQuery = new SP.CamlQuery();
                camlQuery.ViewXml = "<View Scope='RecursiveAll'><Query><Where><And><Geq><FieldRef Name='Created' /><Value IncludeTimeValue='TRUE' Type='DateTime'>2013-01-01T04:16:20Z</Value></Geq><And><Lt><FieldRef
    Name='Created' /><Value IncludeTimeValue='TRUE' Type='DateTime'>2013-12-31T04:16:43Z</Value></Lt><Or><Eq><FieldRef Name='Document_x0020_Classification' /><Value Type='Choice'></Value></Eq><Eq><FieldRef
    Name='Document_x0020_Classification' /><Value Type='Choice'>Case Studies</Value></Eq></Or></And></And></Where></Query></View>";
                SP.Web oWebsite = srcContext.Web;
                srcContext.Load(oWebsite, website => website.Webs);
                srcContext.ExecuteQuery();
                SP.Web dWebsite = destContext.Web;
                destContext.Load(dWebsite);
                destContext.ExecuteQuery();
                foreach (SP.Web web in oWebsite.Webs)
                    MessageBox.Show(web.Title);
                    foreach (SP.List list in web.Lists)
                        if (list.BaseType.ToString() == "DocumentLibrary")
                            MessageBox.Show(list.Title);
                            SP.ListItemCollection collListItem = list.GetItems(camlQuery);
                            srcContext.Load(collListItem);
                            srcContext.ExecuteQuery();
                            foreach (var doc in collListItem)
                                        SP.File f = doc.File;
                                        srcContext.Load(f);
                                        srcContext.ExecuteQuery();
                                        string destLibrary = "shared Documents";
                                        string nLocation = dWebsite.ServerRelativeUrl.TrimEnd('/') + "/" + destLibrary.Replace(" ", "")
    + "/" + f.Name;
                                        SP.FileInformation fileInfo = SP.File.OpenBinaryDirect(srcContext, f.ServerRelativeUrl);
                                        SP.File.SaveBinaryDirect(destContext, nLocation, fileInfo.Stream, true);
                MessageBox.Show("Completed");
    sk.Rakhishma

    Hi,
    To copy files from one site collection to another site collection, the simplest way is to open document library in windows explorer view.
    Go to document library, click library tab, click open with explorer.
    You can open the document library1 in explorer then copy the files which you want to paste to another site collection
    document library2, then open the document library2 in explorer to paste the documents.
    Besides, there are other method:
    https://social.msdn.microsoft.com/Forums/office/en-US/67282348-25c7-4bd0-9d95-61024c6892f9/how-we-move-a-document-library-from-one-site-collection-to-another-sitecollection?forum=sharepointgeneralprevious
    https://social.msdn.microsoft.com/Forums/sharepoint/en-US/8c112d85-1ab8-426b-be37-d010cf8647fe/copy-a-list-from-one-site-collection-to-another-using-web-service
    Best Regards,
    Lisa Chen
    TechNet Community Support
    Please remember to mark the replies as answers if they help, and unmark the answers if they provide no help. If you have feedback for TechNet Support, contact
    [email protected]

  • Required field in custom content type not required in custom list instance

    I have an issue with a custom SharePoint 2013 solution. Among other components, it consists of:
    a feature with several custom fields with different types, some of which are taxonomy fields,
    a feature with three custom content types using different sets of the custom fields with partially different configuration, e.g. whether they are required or not,
    a feature with a custom document library template and instance using two of the custom content types and a default picture library that is programmatically customized when the feature is activated, e.g. it is assigned the third custom content type.
    When deploying the solution and activating the feature, everything is set up correctly except a single taxonomy field for one of the doc lib's content types. It is defined to be required in both content types but indeed it does not show up as required for
    the default content type whereas everything works fine for the other. And it does not matter which of the two custom content types is defined first (= default) in the list template's schema.xml, the issue always occurs for the same taxonomy field in the doc
    lib's default content type. When I use the built-in Document content type as default, the field is required for both custom content types. However, using the Document content type is not an option.
    If you think this behavior is not strange enough: When the list content type's field is set required through the SharePoint UI, it becomes optional again when the list column is updated, e.g. its display name is changed.
    Any ideas?

    Hi,
    Thank you for your question.
    We are currently looking into this issue and will give you an update as soon as possible.
    Thank you for your understanding and support.
    Linda Li                
    Forum Support
    Please remember to mark the replies as answers if they help and unmark them if they provide no help. If you have feedback for TechNet Subscriber Support, contact
    [email protected]
    Linda Li
    TechNet Community Support

  • Select option "Show this View : in Folder of Content type : {Custom Content Type Name}" while creating view using CSOM

    Hi,
    I am trying to create "View" in a Document Library and need to enable following:
    1. Mark as default View
    2. Folders -> Show this view : in Folders of Content Type : {Custom Content Type name}
    I am using following code which sets "in Folders of Content Type : " to "Folder" rather than selecting custom content type despite passing Content Type ID of custom content type.
    code:
    var itemContentTypes = clientContext.LoadQuery(web.AvailableContentTypes.Where(ct => ct.Name == viewContentType));
    clientContext.ExecuteQuery();
    var itemContentType = itemContentTypes.FirstOrDefault();
    view.ContentTypeId = itemContentType.Id;
    view.DefaultViewForContentType = true;
    view.Update();
    clientContext.ExecuteQuery();
    Please highlight what seems to be missing?
    Thanks
    Sonal

    Hi,
    Before you set the content type ID for the view, you need to add the custom content type to the library firstly.
    You can add the content type to library using OOTB feature “Add from existing site content types” in library settings or using Client Object Model.
    Here is a code snippet for your reference:
    var list = context.Web.Lists.GetByTitle(listTitle);
    list.ContentTypesEnabled = true;
    var contentType = context.Site.RootWeb.ContentTypes.GetById("0x0120");
    list.ContentTypes.AddExistingContentType(contentType);
    context.ExecuteQuery();
    More information about add exist content type using Client Object Model:<o:p></o:p>
    http://msdn.microsoft.com/en-us/library/microsoft.sharepoint.client.contenttypecollection.addexistingcontenttype%28v=office.15%29.aspx
    Best regards,
    ZhengyuGuo
    Zhengyu Guo
    TechNet Community Support

  • Having templates appear when users click the "New Document" button in a document library with custom content types

    Hi all,
    I'm using SharePoint Online, but I'm seeing the same behavior in an on-prem 2013 instance as well. My situation is this:
    - I've created a document library
    - I've created a custom content type and attached a custom document template to it
    - I've assigned the custom content type to the document library, and disabled the default "document" option
    What I'm expecting to see is that when I browse to the document library and click "new document", that either a) a picklist appears allowing me to specify the document template I want (using the custom template I specified) or b) open the custom
    template itself. That doesn't happen - instead, when I click new document I'm prompted to upload a file, which seems to contradict the whole point of using a custom content type/custom document template combo.
    Am I missing something? The custom template isn't in the Forms library, which seems to be a problem if I wanted to use the custom document template instead of the default.
    Ideally I'd like a menu like the one shown here:
    http://social.msdn.microsoft.com/Forums/en-US/59ce3bd8-bf7f-4872-ae76-60d8c81dfc32/display-content-types-on-new-document-button-in-document-libraries?forum=sharepointgeneral, except with me being able to control the list of items that is shown.
    Any ideas? Thanks!

    Hi Brain,
    What you have done is by design behavior.
    If you want to show the Office document templates list (e.g. below image from your above referenced link) to select when click "+new document" link, this will need to install Office Web App 2013 which provides this feature,
    you can new document and see it is using WopiFrame.aspx page, please see more from below article about how to configure OWA 2013 for SharePoint 2013 on-premise.
    http://technet.microsoft.com/en-us/library/ff431687(v=office.15).aspx
    Thanks,
    Daniel Yang
    Forum Support
    Please remember to mark the replies as answers if they help and unmark them if they provide no help. If you have feedback for TechNet Subscriber Support, contact [email protected] 
    Daniel Yang
    TechNet Community Support

  • How to use custom aspx page as template for custom content type

    Hi,
    I have created custom content type and custom aspx page. I want to use aspx page as template for custom content type.
    Can anybody please let me know how to accomplish this?
    Any help would be appreciated.
    Thank you,
    AA.

    Check if you are looking for the below
    http://www.sharepointpals.com/post/How-to-Create-a-Page-Layout-(PageLayout)-with-ContentType-in-SharePoint-2013
    Please remember to click 'Mark as Answer' on the answer if it helps you

  • Custom Content type Programmatically

    HI,
    I am using sharepoint server 2007 in windows server 2003.
    i am successfully created custom content type using MS office templates(using SharePoint GUI). now i want to do below things programmatically (want to know whether it works or not).
    1. creating custom content type and assigning a template to it programmatically.
    2. using these content types in document library (i have written code and working perfectly).
    for the 1st point This Link tells that we can't create content types in SharePoint 2007 but we can in SharePoint 2010,
    my question is are their any alternatives????? or links will be sufficient.
    for 2nd point , i have created custom content types using SharePoint GUI and
    adding them to document library programmatically which works perfectly no prob. in this.
    Please suggest me if their is any way to create custom content type programmatically.
    Regards,
    Jithendra.

    I hope you are looking for this
    http://www.dotnetspark.com/kb/3776-creating-list-programmatically-with-custom.aspx
    namespace customl.Customlist
        [ToolboxItemAttribute(false)]
        public class Customlist : WebPart
            Button btn;
            protected override void CreateChildControls()
                base.CreateChildControls();
                btn = new Button();
                btn.Text = "show";
                btn.Click += new EventHandler(btn_Click);
                Controls.Add(btn);
            void btn_Click(object sender, EventArgs e)
                try
                    SPWeb web = SPContext.Current.Web;
                    web.AllowUnsafeUpdates = true;
    SPListTemplateCollection listTemplates = site.GetCustomListTemplates(mySite);
    SPListTemplate template = listTemplates["Enter template name here"];
    Guid listId = web.Lists.Add("checkcustomlist", "The new custom list", template);
    SPList list = web.Lists[listId];
    web.AllowUnsafeUpdates = false;
                catch (Exception ex)
                    Context.Response.Output.Write("Error (btn_Click): " + ex.Message.ToString());
            protected override void Render(HtmlTextWriter writer)
                base.Render(writer);

Maybe you are looking for

  • CRM Upgrade from 7.0 to EhP1 Error - The requested resource does not exist

    Hello All, We have recently upgrade our pilot system in CRM from CRM 7.0 to Ehp1. The upgrade was successful. However, when I login into the WebUI, I get an error message as follows: 404 Not Found The requested resource does not exist Details: Go to

  • Settlement of Reserve for immenent loss to CO-PA

    Hi Experts, We are working on ECC6.0. In projects system, while doing project settlement we are getting error saying “Complete PA transfer structure PS” message no. KD514. Diagnosis says “There is no value field assignment for cost element 9020001000

  • MB GUI locking up when waking from sleep

    This doesn't happen every time, but sometimes when I wake the MB, the screen will freeze. The OS is still operating, I can ssh in to the machine. The cursor still responds, but I can't click on anything. The clock will be frozen at the time when the

  • Tried to delete bookmarks. Doesn't work.

    When I try to delete my bookmarks, they don't go away. Now I have an overloaded supply of bookmarks that I don't want. [email protected]

  • Scan failure error codes

    Computer is a Media center m495c running win 7; Printer is Photosmart C6150 all in one. Scaner is Scanjet G4050.  Everything was working fine then it stopped scanning documents to PDF. Off loaded all Photosmart and Scanner software and reloaded just