Export Video from SharePoint Asset Library via CSOM (Content Type Video is strange)

Elmo 41 Reputation points
2022-12-10T10:06:24.953+00:00

I have a SharePoint asset library with many files. Some of these files have the content type "Video". Files with the content type video behave strangely. E.g. the column "File Size" is empty only for videos.

I can easily download any type of files (e.g. pdfs) via CSOM the following way:

Microsoft.SharePoint.Client.File file = ctxSource.Web.GetFileByServerRelativeUrl(fileServerRelativeUrl);  
ctxSource.Load(file);  
ctxSource.ExecuteQuery();  
  
ClientResult<Stream> mstream = file.OpenBinaryStream();  
ctxSource.ExecuteQuery();  

But this does not work for videos.

It seems, videos do not have a valid serverRelativeUrl, that I can refer to.

My question: How can I download (or copy) a video from an asset library programatically via CSOM Code?

Thanks in advance for your help!

Elmo

Microsoft 365 and Office SharePoint Development
{count} votes

Accepted answer
  1. RaytheonXie_MSFT 40,471 Reputation points Microsoft External Staff
    2022-12-12T06:51:38.813+00:00

    Hi @Elmo
    Per my research, SharePoint creates a stub (think of it as a folder) to hold a video and all the related contents, such as user-defined properties, thumbnails, video renditions, and other documents related to the video. When you upload a video file, SharePoint automatically creates this stub for that video.
    If we have mp4 file named A.mp4, the file will be stored in a folder named A in Assets library. The url should be like following

    siteurl/Assets/A/A.mp4  
    

    Here is a similar issue with yours to reference
    https://sharepoint.stackexchange.com/questions/157170/csom-how-to-get-video-file


    If the answer is helpful, please click "Accept Answer" and kindly upvote it. If you have extra questions about this answer, please click "Comment".
    Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.


    1 person found this answer helpful.

0 additional answers

Sort by: Most helpful

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.