Я пытаюсь загрузить файл, созданный во время выполнения в C #, но я получил исключение ниже.
Свойство или поле 'ServerRelativeUrl' не было инициализировано. Он не был запрошен или запрос не был выполнен. Может потребоваться явный запрос.
Я также использую SharePoint CSOM и Microsoft.SharePoint.Client
using (var ctx = new ClientContext(siteUrl))
{
try
{
ctx.Credentials = SPOCredentials;
ctx.ExecuteQuery();
}
catch(ClientRequestException)
{
ctx.Credentials = SPCredentials;
ctx.ExecuteQuery();
}
catch(NotSupportedException)
{
ctx.Credentials = SPCredentials;
ctx.ExecuteQuery();
Console.WriteLine("SharePoint On-Premise");
}
var library = ctx.Web.Lists.GetByTitle("testtest");
var fileBytes = new byte[] { };
fileBytes = ReadData();
//Information about the file
var fileInformation = new FileCreationInformation
{
//Server relative url of the document
Url = library.RootFolder.ServerRelativeUrl + "/file.pdf",
//Overwrite file if it's already exist
Overwrite = true,
//Content fo the file
Content = fileBytes
};
//Upload the file to root folder of the Document library
library.RootFolder.Files.Add(fileInformation);
ctx.Load(library);
ctx.ExecuteQuery();
}