SharePoint 365上的CSOM错误 - System.Xml.XmlException未处理,缺少根元素

时间:2018-01-13 07:32:15

标签: c# xml sharepoint office365 csom

我创建了一个控制台应用程序来添加/更新和删除SharePoint 365中的项目。它在两天前工作,现在我收到此错误:

string login = "username@web365.onmicrosoft.com";   
string password = "pooo%yup12"; //give your password  
var securePassword = new SecureString();
foreach (char c in password)
{
  securePassword.AppendChar(c);
}
string siteUrl = "https://web365.onmicrosoft.com/sites/test";
ClientContext clientContext = new ClientContext(siteUrl);

//Add New Item
//Create new object of List
List newlist = clientContext.Web.Lists.GetByTitle("Test");
ListItemCreationInformation itemInfo = new ListItemCreationInformation();
ListItem newItem = newlist.AddItem(itemInfo);
newItem["Title"] = "2";
newItem.Update();

var onlineCredentials = new SharePointOnlineCredentials(login, securePassword);
clientContext.Credentials = onlineCredentials;
clientContext.Load(clientContext.Web, w => w.Title);
clientContext.ExecuteQuery();

这是我的代码,我是从网上修改过来的。

<UserControl.Resources>
    <Style x:Key="EmptyButtonStyleWithExtraMenuImage" TargetType="{x:Type Button}">
        <Setter Property="ContextMenu">
            <Setter.Value>
                <ContextMenu >
                    <MenuItem Header="Duplicate Table" Style="{StaticResource MenuItemStyle}"/>
                    <MenuItem Header="Edit Table" Style="{StaticResource MenuItemStyle}"/>
                    <MenuItem Header="View Summary" Style="{StaticResource MenuItemStyle}"/>
                    <Separator Style="{StaticResource SeparatorStyle}"/>
                    <MenuItem Header="Delete Table" Style="{StaticResource MenuItemStyle}"/>
                </ContextMenu>
            </Setter.Value>
        </Setter>
        <Setter Property="Template">
            <Setter.Value>
                <ControlTemplate TargetType="{x:Type Button}">
                    <Image Name="ExtraMenuImage" Source="..."/>
                </ControlTemplate>
            </Setter.Value>
        </Setter>
    </Style>

    <Style x:Key="OptionsListViewItemStyle" TargetType="{x:Type ListViewItem}">
        <Setter Property="Template">
            <Setter.Value>
                <ControlTemplate TargetType="{x:Type ListViewItem}">
                    <Grid>
                        <Border >
                            <DockPanel LastChildFill="True" Margin="0,10,10,10">
                                <ContentPresenter DockPanel.Dock="Left"/>
                                <Button x:Name="buttonControl" 
                                        Style="{StaticResource ResourceKey=EmptyButtonStyleWithExtraMenuImage}" 
                                        DockPanel.Dock="Right"/>
                            </DockPanel>
                        </Border>
                    </Grid>
                </ControlTemplate>
            </Setter.Value>
        </Setter>
    </Style>
</UserControl.Resources>

<ListView x:Name="SpecificationTablesUI" Style="{StaticResource OptionsListViewStyle}" 
        ItemsSource="{Binding Path=SpecTables}">
    <ListView.ItemTemplate>
        <DataTemplate>
            <DockPanel LastChildFill="True">
                <Expander Header="{Binding TableName}" Style="{StaticResource StatusGroupExpander}">
                    <TextBlock Text="{Binding SelectedQuantity}"/>
                </Expander>
            </DockPanel>
        </DataTemplate>
    </ListView.ItemTemplate>
    <ListView.ItemContainerStyle>
        <Style TargetType="{x:Type ListViewItem}" BasedOn="{StaticResource OptionsListViewItemStyle}">
            <Setter Property="Tag" Value="{Binding Path=DataContext, RelativeSource={RelativeSource Mode=FindAncestor, AncestorType=ListView}}"/>
        </Style>
    </ListView.ItemContainerStyle>
</ListView>

我再次调试,我注意到clientContext正在抛出此异常 ServerVersion ='clientContext.ServerVersion'引发了类型'Microsoft.SharePoint.Client.PropertyOrFieldNotInitializedException'的异常

1 个答案:

答案 0 :(得分:0)

我在网上找到了一个解决方案,建议删除位于users文件夹下的appdata文件,我只是这样做了,错误就消失了。