Cannot covert type 'Microsoft.SharePoint.Client.WebParts.WebPart' to 'GenericSmartPart.SmartPart'

Hi Concern,
I am using Client Site CSOM coding and getting error
Smart Parts user control detail is required and while converting throws error.
Cannot covert type ‘Microsoft.SharePoint.Client.WebParts.WebPart’ to ‘GenericSmartPart.SmartPart’
Code is associted as problem.
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.SharePoint.Client;
using Microsoft.SharePoint.Client.WebParts;
using Microsoft.SharePoint.Client.Utilities;
using System.Data;
namespace TrainingCsharp
class Class1
public void print()
// Starting with ClientContext, the constructor requires a URL to the
// server running SharePoint.
using (ClientContext context = new ClientContext("Site URL "))
// The SharePoint web at the URL.
Web web = context.Web;
// We want to retrieve the web's properties.
// context.Load(web, w => w.Title, w => w.Description);
context.Load(web, w => w.Title, w => w.Description, w => w.ServerRelativeUrl);
context.ExecuteQuery();
string sUrl= web.ServerRelativeUrl;
File oFile = context.Web.GetFileByServerRelativeUrl(sUrl+"/Pages/default.aspx");
LimitedWebPartManager limitedWebPartManager = oFile.GetLimitedWebPartManager(PersonalizationScope.Shared);
context.Load(limitedWebPartManager.WebParts,
wps => wps.Include(
wp => wp.WebPart.Title, wp => wp.WebPart.ZoneIndex ));
context.ExecuteQuery();
int count = limitedWebPartManager.WebParts.Count;
string[] arr, arr1;
if (count == 0)
Console.WriteLine("No Web Parts on this page.");
else
arr = new string[count];
arr1 = new string[count];
string sControlName = null;
for (int i = 0; i < count; i++)
WebPartDefinition oWebPartDefinition = limitedWebPartManager.WebParts[i];
WebPart oWebPart = oWebPartDefinition.WebPart;
arr[i] = oWebPart.Title;
if (arr[i].ToLower().Contains("generic"))
sControlName = ((GenericSmartPart.SmartPart)(oWebPart)).UserControlPath;
//else if (arr[i].ToLower().Contains("smartpart"))
//sControlName = ((SmartPart.SmartPart)(oWebPart)).UserControl;
//else if (arr[i].EndsWith("ListViewWebPart"))
//sControlName = ((Microsoft.SharePoint.Client.ListItemCollection)(oWebPart)).ListName;
//else if (arr[i].StartsWith("Microsoft.SharePoint.WebPartPages."))
//sControlName = arr[i].Length > 34 ? arr[i].Substring(34) : "";
//else
//sControlName = "";
arr1[i] = Convert.ToString(oWebPart.ZoneIndex);
Console.Write(arr[i] + " ");
Console.WriteLine("Position" + arr1[i]);
// ctx.ExecuteQuery();
List announcementsList = context.Web.Lists.GetByTitle("Announcements");
// This creates a CamlQuery that has a RowLimit of 100, and also specifies Scope="RecursiveAll"
// so that it grabs all list items, regardless of the folder they are in.
CamlQuery query = CamlQuery.CreateAllItemsQuery(1000);
ListItemCollection items = announcementsList.GetItems(query);
// Retrieve all items in the ListItemCollection from List.GetItems(Query).
context.Load(items,
itema => itema.Include(
item => item,
item => item["Title"],
item => item["Expires"],
item => item["Body"],
item => item.FieldValuesAsText["Body"],
item => item["Author"],
item => item["Editor"]
context.ExecuteQuery();
foreach (ListItem listItem in items)
// We have all the list item data. For example, Title.
Console.WriteLine("Title" + listItem["Title"]+ " ");
Console.WriteLine("Body" + listItem["Body"] != null ? Convert.ToString(listItem.FieldValuesAsText["Body"]) : string.Empty + " ");
Console.WriteLine("Expires " + Convert.ToDateTime(listItem["Expires"] + " "));
FieldUserValue oValue = listItem["Author"] as FieldUserValue;
String strAuthorName = oValue.LookupValue;
Console.WriteLine("Created at " + strAuthorName + " ");
FieldUserValue oValue1 = listItem["Editor"] as FieldUserValue;
String strAuthorName1 = oValue1.LookupValue;
Console.WriteLine("Last Modified " + strAuthorName1);
//Console.ReadKey();
DataTable table = new DataTable();
table.Columns.Add("Title");
table.Columns.Add("Body");
table.Columns.Add("Expires");
table.Columns.Add("Author");
table.Columns.Add("Editor");
foreach (ListItem listItem in items)
FieldUserValue oValue = listItem["Author"] as FieldUserValue;
String strAuthorName = oValue.LookupValue;
FieldUserValue oValue1 = listItem["Editor"] as FieldUserValue;
String strAuthorName1 = oValue1.LookupValue;
table.Rows.Add(listItem["Title"],listItem["Body"],Convert.ToDateTime(listItem["Expires"]),strAuthorName,strAuthorName1);
//datagrid.DataSource = table;
//ctx.ExecuteQuery();
List EventsList = context.Web.Lists.GetByTitle("Event Calendar");
// This creates a CamlQuery that has a RowLimit of 100, and also specifies Scope="RecursiveAll"
// so that it grabs all list items, regardless of the folder they are in.
CamlQuery queryEvent = CamlQuery.CreateAllItemsQuery(1000);
ListItemCollection itemsEvent = EventsList.GetItems(queryEvent);
// Retrieve all items in the ListItemCollection from List.GetItems(Query).
context.Load(itemsEvent,
itema => itema.Include(
item => item,
item => item["Title"],
item => item["Location"],
item => item["EventDate"],
item => item["EndDate"],
item => item["Description"],
item => item.FieldValuesAsText["Description"],
item => item["Event_x0020_Contact"],
item => item["Event_x0020_Category"],
item => item["Inhouse_x0020__x002f__x0020_Exte"],
item => item["Expires_x0020_On"],
item => item["Author"],
item => item["Editor"]
context.ExecuteQuery();
foreach (ListItem listItemEvent in itemsEvent)
// We have all the list item data. For example, Title.
Console.WriteLine("Items of Events to be Printed");
Console.WriteLine("Title: " + listItemEvent["Title"] + " ");
Console.WriteLine("Title: " + listItemEvent["Location"] + " ");
Console.WriteLine("Event Date: " + Convert.ToDateTime(listItemEvent["EventDate"] + " "));
Console.WriteLine("End Date: " + Convert.ToDateTime(listItemEvent["EndDate"] + " "));
string sDescription = listItemEvent["Description"] != null ? Convert.ToString(listItemEvent.FieldValuesAsText["Description"]) : "";
Console.WriteLine("Description: " + sDescription);
Console.WriteLine("Event Contact: " + listItemEvent["Event_x0020_Contact"] + " ");
Console.WriteLine("Event Category: " + listItemEvent["Event_x0020_Category"] + " ");
Console.WriteLine("Inhouse / External: " + listItemEvent["Inhouse_x0020__x002f__x0020_Exte"]);
Console.WriteLine("Expires: " + Convert.ToDateTime(listItemEvent["Expires_x0020_On"]));
FieldUserValue oAuthor = listItemEvent["Author"] as FieldUserValue;
String sAuthor = oAuthor.LookupValue;
Console.WriteLine("Author: " + sAuthor);
FieldUserValue oEditor = listItemEvent["Editor"] as FieldUserValue;
String sEditor = oEditor.LookupValue;
Console.WriteLine("Editor: " + sEditor);
//Console.ReadKey();
DataTable tableEvents1 = new DataTable();
tableEvents1.Columns.Add("Title");
tableEvents1.Columns.Add("Location");
tableEvents1.Columns.Add("EventDate");
tableEvents1.Columns.Add("EndDate");
tableEvents1.Columns.Add("Description");
tableEvents1.Columns.Add("Event Category");
tableEvents1.Columns.Add("Event Contact");
tableEvents1.Columns.Add("Inhouse / External");
tableEvents1.Columns.Add("Expires On");
tableEvents1.Columns.Add("Author");
tableEvents1.Columns.Add("Editor");
foreach (ListItem listItemEvent in itemsEvent)
FieldUserValue oValue = listItemEvent["Author"] as FieldUserValue;
String strAuthorName = oValue.LookupValue;
FieldUserValue oValue1 = listItemEvent["Editor"] as FieldUserValue;
String strAuthorName1 = oValue1.LookupValue;
tableEvents1.Rows.Add(listItemEvent["Title"]
, listItemEvent["Location"]
,Convert.ToDateTime(listItemEvent["EventDate"])
, Convert.ToDateTime(listItemEvent["EndDate"]), listItemEvent["Description"],
listItemEvent["Event_x0020_Category"],listItemEvent["Event_x0020_Contact"],listItemEvent["Inhouse_x0020__x002f__x0020_Exte"]
,Convert.ToDateTime(listItemEvent["Expires_x0020_On"])
,strAuthorName,strAuthorName1);
//datagrid.DataSource = table;
// ctx.ExecuteQuery();

Hi,
Would you mind providing more details about why you want to perform the type conversion?
According to your code, you might want to retrieve some properties of a web part in a page, please check that whether the built-in properties of
Microsoft.SharePoint.Client.WebParts.WebPart can fulfill your requirement.
WebPart members
http://msdn.microsoft.com/en-us/library/microsoft.sharepoint.client.webparts.webpart_members(v=office.15).ASPX
Feel free to reply if there are still any questions.
Best regards
Patrick Liang
TechNet Community Support

Similar Messages

  • System.Management.Automation.MethodInvocationException: Exception calling "ExecuteQuery" with "0" argument(s): "$Resources:core,ImportErrorMessage;" --- Microsoft.SharePoint.Client. ServerException: $Resources:core,ImportErrorMessage;

    Hi,
    I am getting an error  System.Management.Automation.MethodInvocationException: Exception calling "ExecuteQuery" with "0" argument(s): "$Resources:core,ImportErrorMessage;" ---> Microsoft.SharePoint.Client. ServerException:
    $Resources:core,ImportErrorMessage;
    Following is my powershell script on line
    $context.ExecuteQuery(); it is throwing this error.
    function AddWebPartToPage([string]$siteUrl,[string]$pageRelativeUrl,[string]$localWebpartPath,[string]$ZoneName,[int]$ZoneIndex)
        try
        #this reference is required here
        $clientContext= [Microsoft.SharePoint.Client.ClientContext,Microsoft.SharePoint.Client, Version=14.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c]
        $context=New-Object Microsoft.SharePoint.Client.ClientContext($siteUrl)
        write-host "Reading file " $pageRelativeUrl
        $oFile = $context.Web.GetFileByServerRelativeUrl($pageRelativeUrl);
        $limitedWebPartManager = $oFile.GetLimitedWebPartManager([Microsoft.Sharepoint.Client.WebParts.PersonalizationScope]::Shared);
        write-host "getting xml reader from file"
        $xtr = New-Object System.Xml.XmlTextReader($localWebpartPath)
         [void] [Reflection.Assembly]::LoadWithPartialName("System.Text")
        $sb = new-object System.Text.StringBuilder
             while ($xtr.Read())
                $tmpObj = $sb.AppendLine($xtr.ReadOuterXml());
             $newXml =  $sb.ToString()
        if ($xtr -ne $null)
            $xtr.Close()
        #Add Web Part to catalogs folder
        write-host "Adding Webpart....."
        $oWebPartDefinition = $limitedWebPartManager.ImportWebPart($newXml);
        $limitedWebPartManager.AddWebPart($oWebPartDefinition.WebPart, $ZoneName, $ZoneIndex);
    $context.ExecuteQuery();
        write-host "Adding Web Part Done"
        catch
        write-host "Error while 'AddWebPartToPage'" $_.exception| format-list * -force
    ERROR:
    Error while 'AddWebPartToPage' System.Management.Automation.MethodInvocationException: Exception calling "ExecuteQuery" with "0" argument(s): "$Resources:core,ImportErrorMessage;" ---> Microsoft.SharePoint.Client.
    ServerException: $Resources:core,ImportErrorMessage;
       at Microsoft.SharePoint.Client.ClientRequest.ProcessResponseStream(Stream responseStream)
       at Microsoft.SharePoint.Client.ClientRequest.ProcessResponse()
       at Microsoft.SharePoint.Client.ClientContext.ExecuteQuery()
       at ExecuteQuery(Object , Object[] )
       at System.Management.Automation.DotNetAdapter.AuxiliaryMethodInvoke(Object target, Object[] arguments, MethodInformation methodInformation, Object[] originalArguments)
       --- End of inner exception stack trace ---
       at System.Management.Automation.DotNetAdapter.AuxiliaryMethodInvoke(Object target, Object[] arguments, MethodInformation methodInformation, Object[] originalArguments)
       at System.Management.Automation.DotNetAdapter.MethodInvokeDotNet(String methodName, Object target, MethodInformation[] methodInformation, Object[] arguments)
       at System.Management.Automation.Adapter.BaseMethodInvoke(PSMethod method, Object[] arguments)
       at System.Management.Automation.ParserOps.CallMethod(Token token, Object target, String methodName, Object[] paramArray, Boolean callStatic, Object valueToSet)
       at System.Management.Automation.MethodCallNode.InvokeMethod(Object target, Object[] arguments, Object value)
       at System.Management.Automation.MethodCallNode.Execute(Array input, Pipe outputPipe, ExecutionContext context)
       at System.Management.Automation.ParseTreeNode.Execute(Array input, Pipe outputPipe, ArrayList& resultList, ExecutionContext context)
       at System.Management.Automation.StatementListNode.ExecuteStatement(ParseTreeNode statement, Array input, Pipe outputPipe, ArrayList& resultList, ExecutionContext context)
           

    Thanks Sethu for your comments. However i am running this powershell directly on server so believe
    SharePointOnlineCredentials is not required.
    I have tried it but still giving me same error

  • SharePoint Online : Unable to load type Microsoft.SharePoint.Upgrade.SPUpgradeCompatibilityException required for deserialization.

    From today's morning , We are having Issue on Our Online SharePoint Site.
    Each WebPart is not loading and displaying this Line
    Unable to load type Microsoft.SharePoint.Upgrade.SPUpgradeCompatibilityException required for deserialization.
    Please write in quick response to fix it at
    [email protected]

    Hi,
    According to your post, my understanding is that SharePoint Online Site was unable to load web part and got the “Microsoft.SharePoint.Upgrade.SPUpgradeCompatibilityException” error.
    Per my knowledge, the SPUpgradeCompatibilityException occurs during upgrade when the front-end Web server attempts to connect to an incompatible database.
    Please check whether the database is compatible.
    Regarding SharePoint Online, for quick and accurate answers to your questions, it is recommended that you initial a new thread in Office 365 forum.
    Office 365 forum
    http://community.office365.com/en-us/forums/default.aspx
    Best Regards,
    Linda Li
    Linda Li
    TechNet Community Support

  • The remote server returned an error: (401) Unauthorized error while using Microsoft.SharePoint.Client.dll

    I have access to sharepoint site and I have tested this by manually creating the lists and announcements in the sharepoint site.
    now the same thing when I try to do it through the c#.net code it always gives me the following :
    "An unhandled exception of type 'System.Net.WebException' occurred in
    Microsoft.SharePoint.Client.dll Additional information: The remote server returned an error:
    (401) Unauthorized."
    My code looks like below:
    string userName = "[email protected]";
    SecureString password = new SecureString();
    foreach (char c in "abc123".ToCharArray()) password.AppendChar(c);
    using (var context = new ClientContext("https://sharepoint.partners.extranet.adlabs.com/sites/UniTest"))
    context.Credentials = new SharePointOnlineCredentials(userName, password);
    context.Load(context.Web, w => w.Title);
    context.ExecuteQuery();
    Krrishna

    Hi Krrishna,
    You code is used to access SharePoint Online, if you are use SharePoint 2007, we can use SharePoint web service or custom web service to achieve your requirement. 
    Lists Web Service
    http://msdn.microsoft.com/en-us/library/lists(v=office.12).aspx
    Creating a Custom Web Service
    http://msdn.microsoft.com/en-us/library/ms464040(v=office.12).aspx
    About SharePoint 2007(MOSS 2007), you can also post it to the forum below, you will get more help and confirmed answers there.
    https://social.technet.microsoft.com/Forums/en-US/home?forum=sharepointdevelopmentlegacy
    Thanks,
    Dennis Guo
    TechNet Community 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]
    Dennis Guo
    TechNet Community Support

  • SharePoint Server 2013 Upgrade failure after Updating SP1 + Nov10 CU " Exception of type 'Microsoft.SharePoint.Upgrade.SPUpgradeException' was thrown"

    After Successfully having SharePoint Server 2013 Farm Installation on 2 Servers AD + Central Admin Application server, OS: win server 2008 R2 Ent SP1.
    I set up the configuration for SharePoint app and Workflow Manager to work properly on the Den environment,  the time for SP1 running has come and after downloading the Service pack 1 of SharePoint server 2013 and completing the wizard, I run the SharePoint
    2013 Configuration Wizard after installing SharePoint 2013 SP1, and the wizard failed on step 2 with the Error from the Log file as showing below,
    "Task upgradebootstrap has failed with an unknown exception 
    01/04/2015 00:43:30  11  ERR                  Exception: Microsoft.SharePoint.Upgrade.SPUpgradeException: Exception of type 'Microsoft.SharePoint.Upgrade.SPUpgradeException' was thrown.
       at Microsoft.SharePoint.Upgrade.SPManager.BootStrap(Guid sessionId, SPUpgradeOperationFlags flags)
       at Microsoft.SharePoint.PostSetupConfiguration.UpgradeBootstrapTask.Run()
       at Microsoft.SharePoint.PostSetupConfiguration.TaskThread.ExecuteTask()"
    Also I was not able to create websites like before, and the creating of new site is failed with error message :
    "Failed to call GetTypes on assembly Microsoft.Office.TranslationServices, Version=15.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c. Method not found: 'Microsoft.Office.Web.Common.ProcessImageInfo"
    Is there any solution to my problem with SP1 of SharePoint Server 2013, I don't think that SP1 should generate such bugs in a stable environment.
    Basel Badr ,SharePoint Specialist ,MCAD ,MCTS.

    Hi Basel,
    What edition of SharePoint do you have and what patch did you attempt to install?
    If you are on SharePoint 2013 Enterprise, please make sure you are installing Service Pack 1 for SharePoint Server:
    http://www.microsoft.com/en-us/download/details.aspx?id=42544
    If you are on SharePoint 2013 Foundation, please make sure you are installing  Service Pack 1 for SharePoint Foundation :
    http://www.microsoft.com/en-us/download/details.aspx?id=42548
    For more information, you can refer to the thread:
    https://social.technet.microsoft.com/Forums/sqlserver/en-US/ba9656e9-837e-4261-b164-b5bdfe8adce3/why-does-machine-translation-fail-when-i-do-not-use-it?forum=sharepointgeneral
    http://sharepoint.stackexchange.com/questions/84284/failed-to-call-gettypes-on-assembly-microsoft-office-translationservices
    Best Regards,
    Eric
    Eric Tao
    TechNet Community Support

  • Read selected values from a multi choice field programatically using Microsoft.SharePoint.Client namespace.

    All examples I found refer to classes under Microsoft.SharePoint namespace. However, I have the SharePoint CSOM that only gives me the Microsoft.Sharepoint.Client namespace.
    I need to read the selected values of a multichoice field, but not sure how to do it with classes in the namespace above.
    everthing works, exept the TSQL_x0020_Reference_x0020_Numbe field.
    my code looks like this:
    Webweb = cont.Web;
                cont.Load(web);
                cont.ExecuteQuery();
    Listsstest = web.Lists.GetByTitle("T-SQL
    Code Review Tracking");
    //CamlQuery query = CamlQuery.CreateAllItemsQuery();
    CamlQueryquery =
    newCamlQuery();
                query.ViewXml =
    @"<View>
                               <ViewFields>
                                    <FieldRef Name='Category'/>
                                    <FieldRef Name='Review_x0020_Type'/>
                                    <FieldRef Name='Review_x0020_Start_x0020_Date'/>
                                    <FieldRef Name='Title'/>
                                    <FieldRef Name='Location'/>
                                    <FieldRef Name='Project'/>
                                    <FieldRef Name='Author0'/>
                                    <FieldRef Name='AssignedTo'/>
                                    <FieldRef Name='TSQL_x0020_Reference_x0020_Numbe'/>
                                </ViewFields>
                             </View>"
     ListItemCollectionitems
    = sstest.GetItems(query);
                cont.Load(items);
                cont.ExecuteQuery();
    foreach(ListItemitem
    initems)
                    Output0Buffer.AddRow();
                    Output0Buffer.ReviewStatus = item.FieldValues[
    "Category"] !=
    null? item.FieldValues["Category"].ToString()
    : String.Empty;
                    Output0Buffer.ReviewType = item.FieldValues[
    "Review_x0020_Type"] !=
    null? item.FieldValues["Review_x0020_Type"].ToString()
    : String.Empty;
                    Output0Buffer.ReviewDate =
    DateTime.Parse(item.FieldValues["Review_x0020_Start_x0020_Date"].ToString());
                    Output0Buffer.Module = item.FieldValues[
    "Title"] !=
    null? item.FieldValues["Title"].ToString()
    : String.Empty;
                    Output0Buffer.BranchLocationURL = item.FieldValues[
    "Location"] !=
    null? item.FieldValues["Location"].ToString()
    : String.Empty;
                    Output0Buffer.ProjectName = item.FieldValues[
    "Project"] !=
    null? item.FieldValues["Project"].ToString()
    : String.Empty;
                    Output0Buffer.Author = item.FieldValues[
    "Author0"] !=
    null? item.FieldValues["Author0"].ToString()
    : String.Empty;
    FieldLookupValueflvAssignedTo =
    newFieldUserValue();
                    flvAssignedTo = item.FieldValues[
    "AssignedTo"]
    asFieldLookupValue;
    if(flvAssignedTo !=
    null)
                        Output0Buffer.AssignedTo = flvAssignedTo.LookupValue;
    varv = item.FieldValues["TSQL_x0020_Reference_x0020_Numbe"];
    if(v !=
    null)
                        Output0Buffer.Reason2 = v.ToString();
                 Output0Buffer.SetEndOfRowset();           

    Hi,
    According to your description, my understanding is that you want to read the selected choice field value using Client Object Model.
    In my environment, I create a list with a mutichoice fileld named "choice" and then I used the code snippet below to get the selected value in choice field.
    ClientContext clientContext = new ClientContext("http://sp2013sps/sites/test1");
    Microsoft.SharePoint.Client.List spList = clientContext.Web.Lists.GetByTitle("list1");
    clientContext.Load(spList);
    clientContext.ExecuteQuery();
    if (spList != null && spList.ItemCount > 0)
    Microsoft.SharePoint.Client.CamlQuery camlQuery = new CamlQuery();
    camlQuery.ViewXml =
    @"<View>
    <ViewFields><FieldRef Name='choice' /></ViewFields>
    </View>";
    ListItemCollection listItems = spList.GetItems(camlQuery);
    clientContext.Load(listItems);
    clientContext.ExecuteQuery();
    string value = listItems[0]["choice"].ToString();
    Console.WriteLine(value);
    Console.ReadKey();
    Thanks
    Best Regards
    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]

  • SharePoint Designer 2013 after installation getting error with runtime i.e. error writing to file Microsoft.SharePoint.Client.Runtime.Local.Resources.dll Verify that you have access to that directory

    SharePoint Designer 2013 after installation getting error with runtime i.e. error writing to file Microsoft.SharePoint.Client.Runtime.Local.Resources.dll Verify that you have access to that directory
    after retry..again SharePoint Designer requires the following component require to install Microsoft.NET framework version 4 i have downloaded and try to installed but fail not work please answer what to do?
    Thanks and Regards, Rangnath Mali

    Hi Rangnath,
    For running SharePoint Designer 2013, you need to install Microsoft .NET 4.0 Framework or higher.
    Please uninstall the Microsoft .NET 4.0 Framework, and install it again. After that, reboot your machine.
    Best Regards,
    Wendy
    Wendy Li
    TechNet Community Support

  • Creating SharePoint Custom List using a list using a Microsoft.SharePoint.Client.ClientContext object: Lists.Add method from existing Template does not Include Template Content (include content was checked for template)

    The code below works assuming you have a list template setup called "GenTasksTemplate".
    The problem is that even though the check box to include content was checked during the creation of the template, the task items in the new list do not get populated.  What am I missing?
    using System;
    using System.Linq;
    using Microsoft.SharePoint.Client;
    protected void createSPlist(object sender, EventArgs e)
    ClientContext context = new ClientContext("https://sharepointServer/sites/devcollection/");
    var web = context.Web;
    ListTemplateCollection ltc = context.Site.GetCustomListTemplates(context.Web);
    ListCollection siteListsColection = web.Lists;
    context.Load(ltc);
    context.ExecuteQuery();
    ListCreationInformation listCreationInfo = new ListCreationInformation
    Title = "New Task from Template",
    Description = "Tasks created from custom template"
    Microsoft.SharePoint.Client.ListTemplate listTemplate = ltc.First(listTemp => listTemp.Name == "GenTasksTemplate");
    listCreationInfo.TemplateFeatureId = listTemplate.FeatureId;
    listCreationInfo.TemplateType = listTemplate.ListTemplateTypeKind;
    listCreationInfo.DocumentTemplateType = listTemplate.ListTemplateTypeKind;
    //listCreationInfo.CustomSchemaXml =
    siteListsColection.Add(listCreationInfo);
    context.Load(siteListsColection);
    context.ExecuteQuery();
    http://www.net4geeks.com Who said I was a geek?

    Yes. I can create a list with the template using the UI.  I can also create list programmatically using the Microsoft.SharePoint library within a Windows Forms Application.  If I do create a provider-hosted app referencing Microsoft.SharePoint,
    it results in a 64bit / 32bit mismatch error.  I am running SharePoint 2013 on a 64 bit Windows 2012 Server.
    The problem is that with a provider-hosted SharePoint App, I am limited to only using the Microsoft.SharePoint.Client library which is very limited.
    http://www.net4geeks.com Who said I was a geek?

  • 'Uninstall app for SharePoint': Could not load type 'Microsoft.SharePoint.Administration.SPAppInstanceErrorDetails' from assembly 'Microsoft.SharePoint

    Hi there,
    I am new to developing with SharePoint and would like to create my first app for SP13 with VS12.
    To run SP13 and VS12 on the same virtual machine. The SP Tools Developer I have also installed.
    My problem:
    I select the Project Wizard from VS12 to create a new app SP13 using provider hosted option. After the project is created I want to directly deploy (F5), and yet I always get the following error:
    Error 1
    Error occurred in deployment step 'Uninstall app for SharePoint': Could not load type 'Microsoft.SharePoint.Administration.SPAppInstanceErrorDetails' from assembly 'Microsoft.SharePoint, Version=15.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c'.
    0 0
    SharePointApp20132106
    Does anybody advice?

    Please have a look at the below thread
    http://social.msdn.microsoft.com/Forums/en-US/7b8a50ed-651d-4aa5-95f0-a551edb95550/sharepoint-hosted-app-deployment-error-in-sharepoint-2013-preview?forum=appsforsharepoint
    My Blog- http://www.sharepoint-journey.com|
    If a post answers your question, please click Mark As Answer on that post and Vote as Helpful

  • Using microsoft.sharepoint.client.search.analytics to report the monthly hit count of site collections on SharePoint Online

    Is it possible to use microsoft.sharepoint.client.search.analytics to report the monthly hit count of site collections on SharePoint Online.
    GetHitCountForDay()
    GetHitCountForMonth()
    If yes, how can this be called and executed successfully from a Console application using the Client Object Model.
    Reference:
    http://download.microsoft.com/download/8/5/8/858F2155-D48D-4C68-9205-29460FD7698F/[MS-SPACSOM].pdf
    http://social.msdn.microsoft.com/Forums/windowsdesktop/en-US/54310f5f-e8a3-469e-86a3-63781b91670d/how-to-get-analytics-reports-programmatically-in-sharepoint-2013?forum=sharepointdevelopment

    Check if this works in 2013 as well.
    http://blogs.technet.com/b/sharepointdevelopersupport/archive/2012/10/04/how-to-retrieve-web-analytics-report-data-using-api.aspx
    This post is my own opinion and does not necessarily reflect the opinion or view of Slalom.

  • Cannot implicitly convert type 'Microsoft.SharePoint.SPListItemCollection' to 'System.Collections.Generic.List T '_

    Hi
    I want use SPListItemCollection' to 'System.Collections.Generic.List<T>'.
    How to achieve this.
    Thanks,
    Siva.

    Hi Siva,
    This is how I code it for looping all SPListItem in the SPListItemCollection using Generic List<T>
    public IEnumerable GetEnumerator()
    using (SPSite site = new SPSite(SPContext.Current.Site.Url))
    using (SPWeb web = site.OpenWeb())
    var list = web.Lists["Friends"];
    var query = new SPQuery();
    query.Query = "<FieldRef Name='ID'/>";
    IEnumerable items = list.GetItems(query);
    return items;
    Then calling the method would be
    var items = GetEnumerator();
    foreach(SPListItem item in items)
    Response.Write(item["FirstName"]);
    Murugesa Pandian| MCPD | MCTS |SharePoint 2010

  • Type 'Microsoft.SharePoint.WebControls.EmbeddedFormField' does not have a public property named 'div' - SharePoint 2013

    I was changing my Home page's Master Page, so I went to the advanced mode via SharePoint designer and changed the Master Page line, then that happened! I tried to export and Import the Home.aspx but same?!

    Hi,
    According to your post, my understanding is that you got errors when you changed the master page.
    Based on the earlier threads, If you forget the <zone template> tags, this issue may happen.
    You can wrap your whole code in a <div> tag, then check whether it works.
    There are some similar threads for your reference.
    http://mysharepointwork.blogspot.com/2011/07/type-microsoftsharepointwebcontrolsscri.html
    http://www.sharepointboris.net/2009/02/type-microsoftsharepointwebcontrolsformfield-does-not-have-a-public-property-named-xmlnssharepoint-error/
    http://social.technet.microsoft.com/Forums/en-US/89e99b85-5af3-45c1-a39e-677711329aba/error-systemwebuiwebcontrolscontentplaceholder-does-not-have-a-public-property-named?forum=sharepointadminprevious
    Thanks & Regards,
    Jason
    Jason Guo
    TechNet Community Support

  • How to delete a custom columns from a content-type in Sharepoint Client object model

    I have a windows interface where I create a content-type and then create a column and adds that column to the content-type.
    //availableCT is my content-type where the column is present.
    //get all available fields within this content-type
    FieldCollection fieldColl = availableCT.Fields;
    clientContext.Load(fieldColl);
    clientContext.ExecuteQuery();
    foreach (Field field in fieldColl)
    //columnFromList is the column that is to be deleted
    if (field.InternalName.Equals(columnFromList))
    field.DeleteObject();
    clientContext.ExecuteQuery(); // this throws an exception
    // Additional information: Site columns which are included in content types or on lists cannot be deleted. Please remove all instances of this site column prior to deleting it.

    hi,
    you can use the below code to delete it
    using (ClientContext sourceContext = new ClientContext(cmdSpoSite))
    Web web = sourceContext.Web;
    sourceContext.Load(web);
    sourceContext.Load(web.AvailableContentTypes, type => type.Include(c => c.FieldLinks, c => c.Name));
    sourceContext.ExecuteQuery();
    List<ContentType> ExistingContentType = web.AvailableContentTypes.ToList();
    IEnumerable<ContentType> contentTypesList = ExistingContentType.Where(ct => ct.Name == "<ContentTypeName>");
    ContentType ctype = contentTypesList.ElementAt(0);
    IQueryable<FieldLink> flinks = ctype.FieldLinks.Where(f => f.Name == "<FiledName");
    foreach (FieldLink flink in flinks)
    flink.DeleteObject();
    ctype.Update(true);
    sourceContext.ExecuteQuery();
    The difference being in your code and above code is you are removeing fileds which is eventually is deleting site column but a site column cannot be deleted if is alreday being used. So you need to deled the FieldLink in content type taht way column is removed
    from content type but not from site column.
    Now if you want to delete site column you can use your code to deleted Field.
    Whenever you see a reply and if you think is helpful,Vote As Helpful! And whenever you see a reply being an answer to the question of the thread, click Mark As Answer

  • Cannot create list in SharePoint 2010 using Client Object Model

    I am trying to utilize SharePoint 2010 Client Object Model to create a List based on a custom template. Here's my code:
    public void MakeList(string title, string listTemplateGUID, int localeIdentifier)
    string message;
    string listUrl;
    List newList;
    Guid template;
    ListCreationInformation listInfo;
    Microsoft.SharePoint.Client.ListCollection lists;
    try
    listUrl = title.Replace(spaceChar, string.Empty);
    template = GetListTemplate((uint)localeIdentifier, listTemplateGUID);
    listInfo = new ListCreationInformation();
    listInfo.Url = listUrl;
    listInfo.Title = title;
    listInfo.Description = string.Empty;
    listInfo.TemplateFeatureId = template;
    listInfo.QuickLaunchOption = QuickLaunchOptions.On;
    clientContext.Load(site);
    clientContext.ExecuteQuery();
    lists = site.Lists;
    clientContext.Load(lists);
    clientContext.ExecuteQuery();
    newList = lists.Add(listInfo);
    clientContext.ExecuteQuery();
    catch (ServerException ex)
    Now, this particular part, newList = lists.Add(listInfo); clientContext.ExecuteQuery();, the one that is supposed to create the actual list, throws an exception:
    Message: Cannot complete this action. Please try again.
    ServerErrorCode: 2130239231
    ServerErrorTypeName: Microsoft.SharePoint.SPException
    Could anyone please help me realize what am I doing wrong? Thanks.

    I've made progress - well, at least to some extent. The previous message related to the "Invalid file name" is not appearing any more. I now realize that it is necessary to specify feature ID, list template kind, as well as custom schema in order
    to order SharePoint 2010 to create the document library. 
    However, there's a new problem which isn't documented on the net almost at all (at least I was unable to find anything): The document library gets created, but I cannot access it. Further inspection showed that the doc lib views are not created. Basically,
    the only accessible doc lib page is the document library settings page. Also, I get the server exception with the message: 
    Server Out Of Memory. There is no memory on the server to run your program. Please contact your administrator with this problem.
    Any idea what is causing this issue? Thanks. 
    Hi Boris
    Borenović,
    I think I found the reason for this notorious "Server Out Of Memory" error.
    (Man, it took 4 hrs of frustrating troubleshooting without any direct hints... very disappointing
    MSFT developers :( ).
    Anyway,
    All the "Form" elements at the bottom need to have SetupPath="pages\form.aspx"
    attribute (by default this attrib is missing when you copy the whole List element from inside the stp's manifest.xml  file).
    Also, just make sure that each "View" element has correct "WebPartZoneID", "SetupPath" and "Url" attribute values otherwise that list/library will
    be created successfully but will fail to load when you try to access it (with the VERY helpful "Cannot complete this action, contact administrator" error). Even if you enable stack trace (or check ULS logs) you will find "An unexpected
    error has been encountered in this Web Part.  Error: A Web Part or Web Form Control on this Page cannot be displayed or imported. The type could not be found or it is not registered as safe." and you will never realize it's because of the
    incorrect attributes ("WebPartZoneID", "SetupPath" or "Url" as mentioned above).
    Come on Microsoft, you can do better than that?
    If the API needs this attrib then why is it missing inside the manifest.xml file when
    an STP file generated in the first place?

  • The Remote server returned an error (404) not found in SharePoint Client Context code

    Hi All,
    I am getting an error with below line.
    "The Remote server returned an error (404) not found"
    It occurs when I am trying to fetch some data from SharePoint 2010 List.
    For eg. I have a webpart in which i am showing some content on page load and that content is coming from a List.
    But I am getting error.
    Screen shot for your reference.

     Here is my code:
       ClientContext context1 = new ClientContext("site url");
                context1.AuthenticationMode = ClientAuthenticationMode.Anonymous;
                List list1 = context1.Web.Lists.GetByTitle("List1");
                CamlQuery query1 = new CamlQuery();
                query1.ViewXml = @"<Query><Query><OrderBy><FieldRef Name='Title' Ascending='True' /></OrderBy>      
       </Query></Query>";
                Microsoft.SharePoint.Client.ListItemCollection listCollection1 = list1.GetItems(query1);
                context1.Load(listCollection1);
                context1.ExecuteQuery();  
               Even i removed the line no. 2 from above code and placed below but still same issue.
               context1.Credentials = new NetworkCredential("user", "password", "domain");
    Hope someone will solve my issue here.

Maybe you are looking for

  • Key figure value in a level

    Hi is it possible to identify which key figures values has introduce a user ? and which CVC has the user uses for inserting the key figure value? REgards. PS :We have APO DP 5.0

  • Issue in select of billing documents from VBRK using FKART and FKDAT

    Hi All, I have to select the billing documents VBELN using the billing date and billing type. As both are not key fields , im unable to perform such select . How can get billing documents using these fields. Is there any other table where i can use t

  • Clusterware patch for 10.2.0.4

    Will there be any separate patch to upgrade oracle clusterware from 10.2.0.1 to 10.2.0.4.... why because we installed oracle clusterware 10.2.0.1 and Oracle RAC database 10.2.0.1 and upgraded with patch 10.2.0.4.....which upgraded both clusterware an

  • In Firefox browser only (NOT IE,) Yahoo Mail screen jumps up, then down 1 line every few seconds.

    The following happens ONLY when I use Firefox. It does NOT happen when I use IE; and it happens ONLY in Yahoo Mail. Whenever I'm in Yahoo Mail, my screen jumps 1 line--alternating up, then down--every 5-15 seconds. While composing e-mail, when I get

  • Acrobat Pro 7.1.0 to 7.1.1 - .msp?

    The 7.1.0 update for Acrobat Pro was an .exe; the 7.1.1 update is an .msp -- what am I supposed to do with the .msp file? (Adobe Support won't tell me how to apply the .msp because Acrobat v7 is no longer supported, even though they created the .msp