C#console:将数据插入datalist sharepoint。 [英] C# console : insert data to datalist sharepoint.

查看:82
本文介绍了C#console:将数据插入datalist sharepoint。的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

为什么Visual Studio 2017无法验证我的代码?即使我已经把参考文献如:microsoft.sharepoint.client / runtime和system.security



图片链接:Imgur:image [ ^ ]



我尝试过:



why my code cannot be verify by Visual Studio 2017 ? even though i already put the reference such as : microsoft.sharepoint.client /runtime and also system.security

image link : Imgur: image[^]

What I have tried:

static void Main(string[] args)
       {
           string login = "admin@listdemo.onmicrosoft.com"; //give your username here
           string password = "givepasswordhere"; //give your password
           var securePassword = new();
           foreach(char c in password)
           {
               securePassword.AppendChar(c);
           }

           string siteUrl = "https://listdemo.sharepoint.com/sites/mysite";
           ClientContextclientContext = new ClientContext(siteUrl);
           Microsoft.SharePoint.Client.ListmyList = clientContext.Web.Lists.GetByTitle("myproducts");
           ListItemCreationInformationitemInfo = newListItemCreationInformation();
           ListItemmyItem = myList.AddItem(itemInfo);
           myItem["Title"] = "My New Item";
           myItem["Description"] = "New Item Description";
           try {
               myItem.Update();
               var onlineCredentials = newSharePointOnlineCredentials(login, securePassword);
               clientContext.Credentials = onlineCredentials;
               clientContext.ExecuteQuery();
               Console.WriteLine("New Item inserted Successfully");
           } catch (Exception e)
           {
               Console.WriteLine(e.Message);
           }
           Console.ReadLine();
       }

推荐答案

您复制,粘贴和重命名变量了吗?那些红色的波浪形线条可以告诉你为什么会出现问题。将鼠标悬停在上方将为您提供修复语法错误的线索。它会说:

Did you copy, paste and rename a variable? Those red squiggly lines are there to tell you why there is a problem. Hovering your mouse over will give you the clues to fix your syntax error(s). It will say something like:
Quote:

当前上下文中不存在名称'xxx'

The name 'xxx' does not exist in the current context

其中'xxx'是变量名。



你认为这条线有什么问题?

where 'xxx' is a variable name.

What do you think is wrong with this line?

ClientContextclientContext = new ClientContext(siteUrl);



这一行会给你一个提示:


This line will give you a hint:

clientContext.ExecuteQuery();



这应该是什么?


What is this supposed to be?

var securePassword = new();



a string? char数组?



这个声明看起来非常错误:


a string? array of char?

This declaration looks very wrong:

ListItemCreationInformationitemInfo = newListItemCreationInformation();



这看起来像是没有声明一个类或者缺少使用引用:


This looks like a class is either not declared or a using reference is missing:

var onlineCredentials = newSharePointOnlineCredentials(login, securePassword);





请先执行一些基本功能:

1.复制并粘贴其他人的代码时检查错误

2.使用那些红色波浪线 - 非常有用的信息。不能强调足够的

3.修复任何缺少的命名空间引用



Please, do some basic functions first:
1. check for errors when you copy and paste someone else's code
2. make use of those red squiggly lines - very helpful information. Can't stress that enough
3. fix any missing namespace references


这篇关于C#console:将数据插入datalist sharepoint。的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆