0

I'm trying to write code that uploads files to a certain folder on my SharePoint site.

Everything worked fine until a few days ago.

My problem is with this line of code:

Folder byUrl = Root.Folders.GetByUrl(folderName);

Here is the code with the declarations of the objects and their assigns:

public string SharePointSite { get; } = string.Empty;
public string DocumentLibraryName { get; } = string.Empty;
protected ClientContext Context { get; } = null;
protected List DocumentsList { get; } = null;
Folder Root { get; } = null;

SPArchive(string sharepointsite, string documentLibraryName)
{
    SharePointSite = sharepointsite;
    DocumentLibraryName = documentLibraryName;
    Context = new ClientContext(SharePointSite);
    DocumentsList = Context.Web.Lists.GetByTitle(DocumentLibraryName);
    Context.Load(DocumentsList, new Expression<Func<List, object>>[0]);
    Context.Load(DocumentsList.RootFolder, new Expression<Func<Folder, object>>[0]);
    Context.ExecuteQuery();
    Root = DocumentsList.RootFolder;
    Context.Load(Root, new Expression<Func<Folder, object>>[0]);
    Context.ExecuteQuery();
}

It worked before but does not work now.

Root is a Microsoft.SharePoint.Client.Folder object, folderName is the name of the folder and the folder exists on the SharePoint site.

The error message says:

'FolderCollection' does not contain a definition for 'GetByUrl' and no accessible extension method 'GetByUrl' accepting a first argument of type 'FolderCollection' could be found (are you missing a using directive or an assembly reference?)

I have these references from NuGet:

  • Microsoft.SharePoint.Client
  • Microsoft.Sharepoint.Client.Runtime
  • SharePoint
  • Sharepoint.Client.Runtime

What am I doing wrong?

Thank you in advance!

  • Is it possible put the full code. I mean where you assign the folder name variable – vinit kumar Sep 5 '18 at 17:08
0

Please try this code.

string folderName = "/myLibrary/Folder%20NameAndReplaceSpacesWith%20"; 
Folder folder = web.GetFolderByServerRelativeUrl(folderName);

Let us know if it works

Regards,

AHMED

0

I fixed it. I used an old DLL someone else wrote at my work place and now it works.

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.