Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/sharepoint/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
动态创建文件并将其上载到SharePoint C中#_Sharepoint_Sharepoint Clientobject - Fatal编程技术网

动态创建文件并将其上载到SharePoint C中#

动态创建文件并将其上载到SharePoint C中#,sharepoint,sharepoint-clientobject,Sharepoint,Sharepoint Clientobject,我想在MemoryStream中编写,然后在Sharepoint中的共享文档中放置/上载相同的内容。下面是我正在尝试的代码:- var clientContext = new ClientContext("https://server.info/"); string fileUrl = "/Shared Documents/NewDocumentFromTemplate.txt"; var ms = new MemoryStr

我想在MemoryStream中编写,然后在Sharepoint中的共享文档中放置/上载相同的内容。下面是我正在尝试的代码:-

 var clientContext = new ClientContext("https://server.info/");

                string fileUrl = "/Shared Documents/NewDocumentFromTemplate.txt";

                var ms = new MemoryStream();
                using (var file = new StreamWriter(ms))
                {

                    file.WriteLine("Wrinting in file");
                }

                Microsoft.SharePoint.Client.File.SaveBinaryDirect(clientContext, fileUrl, ms, true);
它实际上创建了一个新文件NewDocumentFromTemplate.txt,但它是空的。它什么也没写(

实际上,我想动态创建一个文件,然后将其上传到共享点


请帮助我,我是第一次使用Share Point客户端。

是的..Flush确实有效..谢谢

                var clientContext = new ClientContext("https://server.info/");

                using (var memoryStrm = new MemoryStream())
                {
                    using (var writer = new StreamWriter(memoryStrm))
                    {
                        writer.WriteLine("sfdgfg");

                        writer.Flush();  //added flush
                        memoryStrm.Position = 0;

                        const string fileUrl = "/Shared Documents/NewDocumentFromTemplate.txt";

                        Microsoft.SharePoint.Client.File.SaveBinaryDirect(clientContext, fileUrl, memoryStrm, true);
                    }
                }

您可能应该在WriteLine之后使用flush。使用flush也没有帮助..它仍然没有写入文件..谢谢Madhur Ahuja..它实际上很有效。。