SharePoint 2013 - 文档库上传 c#

SharePoint 2013 - Document Library upload c#

我正在尝试使用 c# 将视频上传到 SharePoint 2013 文档库,每次代码运行时我都会遇到 "file not found" 异常,它只会引发 .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)
        {

        }

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

我对 SharePoint 没有具体的了解。但是对于网站和 IIS,如果扩展名未在 MIME Types 下列出,则浏览器将抛出 404。

SharePoint 似乎也有类似的东西。参见

https://kerseub.wordpress.com/2012/04/23/add-new-file-type-in-sharepoint/

https://social.technet.microsoft.com/Forums/office/en-US/ef4a0922-bacd-40df-9c97-25d09bed30ac/how-to-play-mp4-video-in-sharepoint-2013?forum=sharepointgeneral

您是否尝试过将文件从 SharePoint UI 上传到 SharePoint 文档库?效果好吗?可能是 SharePoint 站点可以配置为不允许某些文件类型。

https://support.office.com/en-us/article/types-of-files-that-cannot-be-added-to-a-list-or-library-30be234d-e551-4c2a-8de8-f8546ffbf5b3#ID0EAABAAA=2013,_2010

此外,上传到 SharePoint 的文件是否需要使用 CSOM 模型检索?

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);
     }
 }