0

I'm trying to upload a video to an asset library through c# csom. I've successfully created a videoset through csom, but every attempt to get a video into the video set falls short.

VideoSet.CreateVideo(targetCtx, targetMediaList.RootFolder, "Video Name", ct.Id);
targetCtx.ExecuteQuery();

It's creating the video set, but I haven't been able to get a video to associate itself to the videoset. Using VideoSet.UploadVideo, File.SaveBinaryDirect, or Folder.Files.Add will get the video into the videoset, but it's not the video... it shows up in explorer view in the folder but I still get just a blank video when I open the video set in a browser.

2 Answers 2

0

So what I found... I uploaded the file as I would any other file and set the content type to my video content type. Then I ran VideoSet.MigrateVideo and it converted it to a videoset for me.

var item = targetMediaList.GetItemById(956);
targetCtx.Load(item, listItem => listItem.File);
targetCtx.ExecuteQuery();

var result = VideoSet.MigrateVideo(targetCtx, item.File);
targetCtx.ExecuteQuery();
0

You could instead utilize VideoSet.UploadVideo method, it creates a video set and uploads file

Example

var sourceFileName = @"d:\sample.mp4";

using (var targetCtx = GetContext(webUrl, username, password))
{
     var targetMediaList = targetCtx.Web.Lists.GetByTitle("Assets");
     var targetFolder = targetMediaList.RootFolder;
     if (!targetMediaList.IsPropertyAvailable("RootFolder"))
     {
          targetCtx.Load(targetFolder, f => f.ServerRelativeUrl);
          targetCtx.ExecuteQuery();
     }
     using (var fs = new FileStream(sourceFileName, FileMode.Open))
     {
         var resultVideo = VideoSet.UploadVideo(targetCtx, targetMediaList, System.IO.Path.GetFileName(sourceFileName),fs,true,targetFolder.ServerRelativeUrl);
         targetCtx.ExecuteQuery();
     }
}

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.