Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

1.1K
Visualizações
File Not Found Error When Uploading Files to Sharepoint

I am getting the File Not Found exception in the ExecuteQuery() method but the file is sitting there in the mentioned folder.

I have included my code below. I am working on a .NET core application.

FileCreationInformation newFile = new FileCreationInformation();
newFile.Url = System.IO.Path.GetFileName(filePath);
newFile.Content = System.IO.File.ReadAllBytes(filePath);

Folder library = SPClientContext.Web.Folders.GetByUrl(fullFolderUrl);
Microsoft.SharePoint.Client.File uploadFile = library.Files.Add(newFile);
SPClientContext.Load(uploadFile);
SPClientContext.ExecuteQuery();



Microsoft.SharePoint.Client.ServerException
  HResult=0x80131500
  Message=File Not Found.
  Source=Microsoft.SharePoint.Client.Runtime
  StackTrace:
   at Microsoft.SharePoint.Client.ClientRequest.ProcessResponseStream(Stream responseStream)
   at Microsoft.SharePoint.Client.ClientRequest.ProcessResponse()
   at Microsoft.SharePoint.Client.ClientRequest.ExecuteQueryToServer(ChunkStringBuilder sb)
   at Microsoft.SharePoint.Client.ClientRequest.ExecuteQuery()
   at Microsoft.SharePoint.Client.ClientRuntimeContext.ExecuteQuery()
   at Microsoft.SharePoint.Client.ClientContext.ExecuteQuery()
   at SharePointTest.Program.<Main>d__0.MoveNext() in C:\Users\O
over 4 years ago · Santiago Trujillo
2 Respostas
Responde à pergunta

0

You need to at least call Load and ExecuteAsync method after you call GetByUrl method on library

FileCreationInformation newFile = new FileCreationInformation();
newFile.Url = System.IO.Path.GetFileName(filePath);
newFile.Content = System.IO.File.ReadAllBytes(filePath);

Folder library = SPClientContext.Web.Folders.GetByUrl(fullFolderUrl);
SPClientContext.Load(library);
SPClientContext.ExecuteQuery();
var files = library.Files;
SPClientContext.Load(files);
SPClientContext.ExecuteQuery();
Microsoft.SharePoint.Client.File uploadFile = files.Add(newFile);
SPClientContext.Load(uploadFile);
SPClientContext.ExecuteQuery();
over 4 years ago · Santiago Trujillo Relatório

0

Please check whether the path of the file you need to upload is correct , then check the path of “fullFolderUrl” , you need to fill in the exact path of the specific library that you want to upload to.

Here is an example that will upload a file to SharePoint library:

static void Main(string[] args)
{
     string filePath = "C:\\Users/Administrator.SP01/Desktop/New folder/test.xlsx";
     string fullFolderUrl = "https://abc.sharepoint.com/sites/xxx/LibraryTest";
     var SPClientContext = GetonlineContext();
     Web web = SPClientContext.Web;
            
     FileCreationInformation newFile = new FileCreationInformation();
     newFile.Url = System.IO.Path.GetFileName(filePath);
     newFile.Content = System.IO.File.ReadAllBytes(filePath);

     Folder library = SPClientContext.Web.Folders.GetByUrl(fullFolderUrl);
     Microsoft.SharePoint.Client.File uploadFile = library.Files.Add(newFile);
     SPClientContext.Load(uploadFile);
     SPClientContext.ExecuteQuery();
}
over 4 years ago · Santiago Trujillo Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda