SharePoint 2013 - 文档库上载c#

Ton*_*ony 9 .net c# sharepoint-2013

我正在尝试使用c#将视频上传到SharePoint 2013文档库,每次代码运行时我都会收到"找不到文件"异常,它只会抛出.mp4文件的错误.如果我上传jpg或任何其他文件格式,它将起作用.我究竟做错了什么?在此先感谢您的帮助.

        string result = string.Empty;

        try
        {
            //site url
            ClientContext context = new ClientContext("siturl");

            // The SharePoint web at the URL.
            Web web = context.Web;

            FileCreationInformation newFile = new FileCreationInformation();
            newFile.Content = System.IO.File.ReadAllBytes(@"C:\test.mp4");
            newFile.Url = "test.mp4";

            List docs = web.Lists.GetByTitle("Learning Materials2");

            Microsoft.SharePoint.Client.File uploadFile = docs.RootFolder.Files.Add(newFile);
            context.Load(uploadFile);
            context.ExecuteQuery();
        }catch(Exception Ex)
        {

        }
Run Code Online (Sandbox Code Playgroud)

UPADTE 创建了一个库,供人们下载,可用于上传.mp4的 https://github.com/bikecrazyy/sharepoint-library-uploader

小智 2

string fileName=@"C:\test.mp4";

using (var clientContext = new ClientContext(siturl))
{
     using (var fs = new FileStream(fileName, FileMode.Open))
     {
         var fi = new FileInfo(fileName);
         var list = clientContext.Web.Lists.GetByTitle("Learning Materials2");
         clientContext.Load(list.RootFolder);
         clientContext.ExecuteQuery();
         var fileUrl = String.Format("{0}/{1}", list.RootFolder.ServerRelativeUrl, fi.Name);
         Microsoft.SharePoint.Client.File.SaveBinaryDirect(clientContext, fileUrl, fs, true);
     }
 }
Run Code Online (Sandbox Code Playgroud)