Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/ssis/2.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
SSIS脚本删除或替换Sharepoint库文件_Sharepoint_Ssis_Sharepoint 2013 - Fatal编程技术网

SSIS脚本删除或替换Sharepoint库文件

SSIS脚本删除或替换Sharepoint库文件,sharepoint,ssis,sharepoint-2013,Sharepoint,Ssis,Sharepoint 2013,我正在尝试使用SSIS脚本任务将excel文件复制到Sharepoint库中,但该库中已存在同名文件。不管是先删除旧文件,然后复制新文件,还是只复制并替换新文件。我不知道如何删除旧文件,在旧文件消失之前,它不会复制新文件。到目前为止,我已经: /* Microsoft SQL Server Integration Services Script Task Write scripts using Microsoft Visual C# 2008. The ScriptMain is the ent

我正在尝试使用SSIS脚本任务将excel文件复制到Sharepoint库中,但该库中已存在同名文件。不管是先删除旧文件,然后复制新文件,还是只复制并替换新文件。我不知道如何删除旧文件,在旧文件消失之前,它不会复制新文件。到目前为止,我已经:

/*
Microsoft SQL Server Integration Services Script Task
Write scripts using Microsoft Visual C# 2008.
The ScriptMain is the entry point class of the script.
*/

using System;
using System.Data;
using Microsoft.SqlServer.Dts.Runtime;
using System.Windows.Forms;
using System.IO;

namespace ST_be5f0817a6b54483a96a8c9e79402175.csproj
{
[System.AddIn.AddIn("ScriptMain", Version = "1.0", Publisher = "", Description = "")]
public partial class ScriptMain : Microsoft.SqlServer.Dts.Tasks.ScriptTask.VSTARTScriptObjectModelBase
{

    #region VSTA generated code
    enum ScriptResults
    {
        Success = Microsoft.SqlServer.Dts.Runtime.DTSExecResult.Success,
        Failure = Microsoft.SqlServer.Dts.Runtime.DTSExecResult.Failure
    };
    #endregion

    /*
    The execution engine calls this method when the task executes.
    To access the object model, use the Dts property. Connections, variables, events,
    and logging features are available as members of the Dts property as shown in the following examples.

    To reference a variable, call Dts.Variables["MyCaseSensitiveVariableName"].Value;
    To post a log entry, call Dts.Log("This is my log text", 999, null);
    To fire an event, call Dts.Events.FireInformation(99, "test", "hit the help message", "", 0, true);

    To use the connections collection use something like the following:
    ConnectionManager cm = Dts.Connections.Add("OLEDB");
    cm.ConnectionString = "Data Source=localhost;Initial Catalog=AdventureWorks;Provider=SQLNCLI10;Integrated Security=SSPI;Auto Translate=False;";

    Before returning from this method, set the value of Dts.TaskResult to indicate success or failure.

    To open Help, press F1.
*/

    public void Main()
    {
        string fileDir = (string)Dts.Variables["fileDir"].Value;
        string SPDir = (string)Dts.Variables["SPDir"].Value;

        if (File.Exists(Path.Combine(SPDir, "filename.CSV")))
            {
                File.Delete(Path.Combine(SPDir, "filename.CSV"));
            }

        File.Copy(Path.Combine(fileDir, "filename.CSV"), Path.Combine(SPDir, "filename.CSV"));


        Dts.TaskResult = (int)ScriptResults.Success;
    }
}
}
我想我可以通过在脚本之前运行带有sharepoint列表连接器的数据流组件来删除该文件,并让脚本将文件复制过来,但我试图避免使用太多的组件和连接,而这种方法通常听起来更复杂


欢迎提供任何帮助或建议。

通过将相关行更改为:File.CopyPath.CombinefileDir、filename.CSV、Path.combinesdir、filename.CSV、true,解决了此问题


布尔参数指定是否覆盖现有文件,如果未指定,则为false。

现有文件有什么问题?它是否生成错误?它没有删除当前在Sharepoint上的文件。如果我让它按原样运行,那么我会得到一个错误,即该文件已经存在。如果我注释掉If语句和copy语句,只保留delete语句,它不会给出错误,也不会删除文件。当您在调试器中运行它时,它是否会命中文件。delete,line,还是If测试为false?据我所知,它正在命中delete行。我注释掉了if部分,使其读取//if File.ExistsPath.combinesdir,filename.CSV{File.DeletePath.combinesdir,filename.CSV;}//File.CopyPath.combinefdir,filename.CSV,Path.combinesdir,filename.CSV;这并没有给出一个错误。对不起,我不知道如何在这里添加换行符。。我以为它应该是双空格,但这似乎不行。这篇文章中似乎有很多有用的信息:如果你尝试一个没有路径的测试会怎么样。合并并只放入文件的完整路径?