Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/296.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
C# 如何在给定HttpPostedFile的情况下将文件上载到文档库_C#_Asp.net_Sharepoint - Fatal编程技术网

C# 如何在给定HttpPostedFile的情况下将文件上载到文档库

C# 如何在给定HttpPostedFile的情况下将文件上载到文档库,c#,asp.net,sharepoint,C#,Asp.net,Sharepoint,我有一个HttpPostedFile对象,在本地将该文件上载到服务器后,我想将该临时文件移动到sharepoint中的文档库中。这是我的密码: private void UploadWholeFile(HttpContext context, List<FilesStatus> statuses) { for (int i = 0; i < context.Request.Files.Count; i++) { HttpP

我有一个HttpPostedFile对象,在本地将该文件上载到服务器后,我想将该临时文件移动到sharepoint中的文档库中。这是我的密码:

private void UploadWholeFile(HttpContext context, List<FilesStatus> statuses) {
            for (int i = 0; i < context.Request.Files.Count; i++) {
                HttpPostedFile file = context.Request.Files[i];
                file.SaveAs(ingestPath + Path.GetFileName(file.FileName));
                string fileName = Path.GetFileName(file.FileName);
}
private void UploadWholeFile(HttpContext上下文,列表状态){
for(int i=0;i

有人能给我一些示例代码吗?我找到了一个关于Streams的教程,但不确定它在我的情况下是否也能起到同样的作用

下面是将文件内容放入字节数组缓冲区的代码:

var file = (HttpPostedFileBase)Request.Files[0];
var buffer = new byte[file.ContentLength];
file.InputStream.Read(buffer, 0, file.ContentLength);
var root = HttpContext.Current.Server.MapPath(@"~/_temp");
var temp_file_name = "somefilename";
var path = Path.Combine(root, temp_file_name);

using (var fs = new FileStream(path, FileMode.Create))
{
    using (var br = new BinaryWriter(fs))
    {
        br.Write(buffer);
    }
}

将以
file.SaveAs
开头的两行替换为以下内容:

var myDocumentLibrary = SPContext.Current.Web.Folders["MyDocumentLibrary"];
var myFile = myDocumentLibrary.Files.Add(file.Name, file.FileContent, true);