Как создать документ на разделяемой точке, используя Asp.net Core MVC (отсутствует пространство имен для .Net Core) - PullRequest
1 голос
/ 26 июня 2019

Я знаю, как создать текстовый документ, используя c # проблему, с которой я столкнулся. Я не знаю, как поместить этот документ в папку общего ресурса.

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();
    }
Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...