Click here to Skip to main content
15,891,943 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
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();
       }
Posted
Updated 6-Aug-17 17:43pm

1 solution

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:
The name 'xxx' does not exist in the current context
where 'xxx' is a variable name.

What do you think is wrong with this line?
C#
ClientContextclientContext = new ClientContext(siteUrl);

This line will give you a hint:
C#
clientContext.ExecuteQuery();

What is this supposed to be?
C#
var securePassword = new();

a string? array of char?

This declaration looks very wrong:
C#
ListItemCreationInformationitemInfo = newListItemCreationInformation();

This looks like a class is either not declared or a using reference is missing:
C#
var onlineCredentials = newSharePointOnlineCredentials(login, securePassword);


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
 
Share this answer
 
v2

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900