0

I am trying to get .doc file names from SharePoint and then get the file by the name.

But I have a problem to using GetList() from this link.

So far I have a code:

string url = "https://mysharepoint.com/Things";

var ctx = new ClientContext(url);
Web web = ctx.Web;

var list = web.GetList("/Shared%20Documents/Test");

var listItems = list.GetItems(new CamlQuery());

ctx.Load(listItems,
 items => items.Include(
  item => item["Created"],
  item => item.File));

ctx.ExecuteQuery();

foreach(var item in listItems) {
 Console.WriteLine("{0} - {1}",
  item["Created"],
  item.File.ServerRelativeUrl);
}

But I can't understand why I have that Error:

Severity Code Description Project File Line Suppression State
Error CS1061 'Web' does not contain a definition for 'GetList' and no accessible extension method 'GetList' accepting a first argument of type 'Web' could be found (are you missing a using directive or an assembly reference?)   MestoDljaProb   C:\Ribbon1.cs   111 Active
0
void ctx_MixedAuthRequest(object sender, WebRequestEventArgs e) // function which tells to sharepoint that we need to log in with windows credentials. Without this it will tell us that we cant get in.
        {                                                                   // thats because we have sharepoint on premise 2016 with multiple(2) autents. we are using AD.
            try
            {
                //Add the header that tells SharePoint to use Windows authentication.
                e.WebRequestExecutor.RequestHeaders.Add(
                "X-FORMS_BASED_AUTH_ACCEPTED", "f");
            }
            catch (Exception ex)
            {
                MessageBox.Show("Error setting authentication header: " + ex.Message);
            }
        }
        private void UuendaNimekiri_Click(object sender, RibbonControlEventArgs e)
        {
            int ConnectionTest = 0; //will try to connect once
            ddList.Items.Clear();
            ClientContext ctx = new ClientContext("https://somesite/some");
            //Configure the handler that will add the header.
            ctx.ExecutingWebRequest +=
            new EventHandler<WebRequestEventArgs>(ctx_MixedAuthRequest);
            //Set the Windows credentials.
            ctx.AuthenticationMode = ClientAuthenticationMode.Default;
            ctx.Credentials = System.Net.CredentialCache.DefaultCredentials;
            //Get the web.
            Web w = ctx.Web;
            //Load lists with all properties. 
            List list = ctx.Web.Lists.GetByTitle("Documents");

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.