以编程方式将本地文件移动并签入到Sharepoint C#

时间:2015-12-22 20:13:54

标签: c# excel visual-studio sharepoint

下面是我用来以编程方式将本地文件从D:移动到sharepoint库的代码。我能够移动文件,但它不会将文件检入sharepoint。我不确定如何检查此文件。有没有人有sharepoint的类似问题?谢谢。

这是我的代码,我没有使用确切的目标和源URL,所以忽略它。它编译并运行正常,它可用于从文件中移动文件D:到我的文档,它jsut不会将文件检入sharepoint。

此外,我正在检查excel表,该表根据每日更新的数据执行大量计算。计算通过宏完成。是否可以编写一个宏来自动上传到sharepoint库并签入?如果是这样我可以将其添加到已经存在的宏而不是使用c#。谢谢。

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.IO;
using Microsoft.SharePoint.WorkflowServices;
using Microsoft.SharePoint.Client;
using Microsoft.SharePoint;
using System.Net;
namespace defectUpload
{
    class Program
    {
    static void Main(string[] args)
    {
        string fileName = "WS2016.xlsm";
        string sourcePath = @ source path "";
        string targetPath = @ destination path "" ;
        // Use Path class to manipulate file and directory paths.
        string sourceFile = System.IO.Path.Combine(sourcePath, fileName);
        string destFile = System.IO.Path.Combine(targetPath, fileName);
        // To copy a folder's contents to a new location:
        // Create a new target folder, if necessary.
        if (!System.IO.Directory.Exists(targetPath))
        {
            System.IO.Directory.CreateDirectory(targetPath);
        }

        System.IO.File.Move(sourceFile, destFile);
    }
    }
}

1 个答案:

答案 0 :(得分:1)

这篇帖子已在https://sharepoint.stackexchange.com/questions/133197/excel-vba-code-to-upload-document-into-sharepoint-online-2013

中解决
Dim SharepointAddress As String
Dim LocalAddress As String
Dim objNet As Object
Dim FS As Object

' Where you will enter Sharepoint location path
SharepointAddress = "\\sharepoint path to document library"  & "\" 
 ' Where you will enter the file path, ex: Excel file
LocalAddress = "your file path"                                     
Set objNet = CreateObject("WScript.Network")
Set FS = CreateObject("Scripting.FileSystemObject")
If FS.FileExists(LocalAddress) Then
FS.CopyFile LocalAddress, SharepointAddress
End If
Set objNet = Nothing
Set FS = Nothing

关于这个主题Using Microsoft Windows SharePoint Services with the Microsoft Office System,还有一篇关于MSDN的好文章。

当谷歌以“vba upload to sharepoint”为例时,还有很多样本......