I'm looking for a good way to get filesize from the Microsoft.SharePoint.Client.File
object.
The Client
object does not have a Length
member.
I tried this:
foreach (SP.File file in files)
{
string path = file.Path;
path = path.Substring(this.getTeamSiteUrl().Length);
FileInformation fileInformation = SP.File.OpenBinaryDirect(this.Context, path);
using (MemoryStream memoryStream = new MemoryStream())
{
CopyStream(fileInformation.Stream, memoryStream);
file.Size = memoryStream.Length;
}
}
Which gave me a length through using the MemoryStream
, but it's not good for performance. This file also does not belong to a document library. Since it's an attached file, I can't convert it to a ListItem
object using ListItemAllFields
. If I could convert it to a ListItem
, I could get its size using: ListItem["File_x0020_Size"]
How do I get the filesize of the Client
object in SharePoint using C#?
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…