C# 如何使用Asp.net Core MVC(缺少.net Core的命名空间)在共享点上创建文档
我知道如何使用c#创建word文档。我遇到的问题是,我不知道如何将该文档放置在共享点文件夹中C# 如何使用Asp.net Core MVC(缺少.net Core的命名空间)在共享点上创建文档,c#,sharepoint,ms-word,C#,Sharepoint,Ms Word,我知道如何使用c#创建word文档。我遇到的问题是,我不知道如何将该文档放置在共享点文件夹中 var newfile = System.IO.Path.Combine( Directory.GetCurrentDirectory(), "Documents", "filename" + ".docx"); System.IO.File.Create(newfile); 我使用下面的代码访问sharepoint,但缺少“SPSite”的名称空间,“SPFile”和“SPWeb”已经引用了Mic
var newfile = System.IO.Path.Combine(
Directory.GetCurrentDirectory(), "Documents", "filename" + ".docx");
System.IO.File.Create(newfile);
我使用下面的代码访问sharepoint,但缺少“SPSite”的名称空间,“SPFile”和“SPWeb”已经引用了Microsoft.sharepoint.Client dll和Microsoft.sharepoint dll
#在Asp.net核心MVC 2.1上开发
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Threading.Tasks;
using Microsoft.AspNetCore.Mvc;
using Sharepoint.Models;
using Microsoft.SharePoint;
using System.IO;
using Microsoft.SharePoint.Client;
public IActionResult Index()
{
String fileToUpload = @"C:\YourFile.txt";
String sharePointSite = "http://yoursite.com/sites/Research/";
String documentLibraryName = "Shared Documents";
using (SPSite oSite = new SPSite(sharePointSite))
{
using (SPWeb oWeb = oSite.OpenWeb())
{
if (!System.IO.File.Exists(fileToUpload))
throw new FileNotFoundException("File not found.", fileToUpload);
SPFolder myLibrary = oWeb.Folders[documentLibraryName];
// Prepare to upload
Boolean replaceExistingFiles = true;
String fileName = System.IO.Path.GetFileName(fileToUpload);
FileStream fileStream = File.OpenRead(fileToUpload);
// Upload document
SPFile spfile = myLibrary.Files.Add(fileName, fileStream, replaceExistingFiles);
// Commit
myLibrary.Update();
}
}
return View();
}