Reputation: 421
I need to find out the mime-type from the object of type Microsoft.SharePoint.Client.File
. For example - if it's a pdf, I need a field which would contain "application/pdf".
Upvotes: 0
Views: 2597
Reputation: 59378
I guess you are looking for a MIME type, in SharePoint CSOM API the closest property you could get is file type:
var file = ctx.Web.GetFileByServerRelativeUrl(fileUrl);
ctx.Load(file, f => f.ListItemAllFields);
ctx.ExecuteQuery();
var fileType = file.ListItemAllFields["File_x0020_Type"];
To get MIME type, System.Web.MimeMapping.GetMimeMapping
method could be utilized from .NET (4.5 or above):
var file = ctx.Web.GetFileByServerRelativeUrl(fileUrl);
ctx.Load(file);
ctx.ExecuteQuery();
string mimeType = MimeMapping.GetMimeMapping(file.Name);
Upvotes: 3