I'm trying to read content of a file as stream in document library on sharepoint online site.
I'm using AppOnlyAccessToken
. Source code work fine before today. And I have no idea for this problem.
My source code:
string realm = TokenHelper.GetRealmFromTargetUrl(SiteUrl);
var token = TokenHelper.GetAppOnlyAccessToken(TokenHelper.SharePointPrincipal, SiteUrl.Authority, realm);
var context = TokenHelper.GetClientContextWithAccessToken(SiteUrl.ToString(), token.AccessToken);
//Initial
Stream stream = null;
var list = context.Web.GetList("/sites/mysites/mydoclib");
var document = list.GetItemById(fileId);
context.Load(document.File);
context.ExecuteQuery();
////Read File and return stream content of file
var streamX = document.File.OpenBinaryStream();
context.ExecuteQuery();
stream = streamX.Value;
return stream;
Error when ExecuteQuery()
to get BinaryStream
.
Error Message:
The label that's applied to this item prevents it from being edited or deleted. Check the item's label for more details.
It work with txt file and get error with csv and excel (xlsx) file.