c# - 如何使用 Asp.net Core MVC(Missing Namespace for .Net Core)在共享点上创建文档
问题描述
我知道如何使用 c# 创建一个 word 文档我遇到的问题我不知道如何将该文档放在共享点文件夹中。
var newfile = System.IO.Path.Combine(
Directory.GetCurrentDirectory(), "Documents", "filename" + ".docx");
System.IO.File.Create(newfile);
我使用下面的代码来访问共享点,但缺少“SPSite”的名称空间,SPFile 和 SPWeb 已经引用了 Microsoft.SharePoint.Client dll 和 Microsoft.SharePoint dll
#在 Asp.net Core 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();
}
解决方案
推荐阅读
- java - 比较java中的2个列表并返回差异
- python - 如何使用 sha-512 生成 hmac?
- html - 如何为 ng-repeat 使用无线电类型以及 ng-model 应该是什么?
- reactjs - 全部显示和隐藏 - React
- c# - 当前上下文中不存在“Amc”名称
- vue.js - 在 Storybook 中更改 Vue 组件的数据值
- vuejs2 - 在firebase + Vue + Quasar中更改个人资料图片之前为用户设置默认图像
- javascript - 检测匹配的对象值何时都有一个新的道具并从中触发一个方法
- php - CSRF 无效,因为注册过程中有两个实体
- visual-studio - Resharper 支持快速操作中的 Roslyn 诊断和代码修复