Pregunta

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!

¿Fue útil?

Solución 2

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

Otros consejos

Please try this code.

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

Let us know if it works

Regards,

AHMED

Licenciado bajo: CC-BY-SA con atribución
scroll top