C# 连接到Azure Blob并删除文件(如果存在)

C# 连接到Azure Blob并删除文件(如果存在),c#,visual-studio,azure,ssis,azure-storage-blobs,C#,Visual Studio,Azure,Ssis,Azure Storage Blobs,我需要使用SSIS脚本任务c#连接Azure容器并检查文件名(abc.csv)。如果文件存在,则将变量更新为1并删除该文件 以下是我在尝试了几个站点后编写的代码:- #region Namespaces using Microsoft.Extensions.Configuration; using Microsoft.WindowsAzure.Storage; using Microsoft.WindowsAzure.Storage.Blob; using System.Threading.Ta

我需要使用SSIS脚本任务c#连接Azure容器并检查文件名(abc.csv)。如果文件存在,则将变量更新为1并删除该文件

以下是我在尝试了几个站点后编写的代码:-

#region Namespaces
using Microsoft.Extensions.Configuration;
using Microsoft.WindowsAzure.Storage;
using Microsoft.WindowsAzure.Storage.Blob;
using System.Threading.Tasks;
#endregion

      public void Main()
            {
                CloudStorageAccount storageAccount = new CloudStorageAccount(
       new Microsoft.WindowsAzure.Storage.Auth.StorageCredentials(
       "Account_Name","XXX0sCXXQsBXXXxMnXXXXXXNXXXPCjPQ=="), true);

                // Create a blob client.
                CloudBlobClient blobClient = storageAccount.CreateCloudBlobClient();

                // Get a reference to a container named "mycontainer."
                CloudBlobContainer container = blobClient.GetContainerReference("test");

                if (container.GetBlockBlobReference("abc.csv").Exists())
                {
                    Dts.Variables["User::FileExistsFlg"].Value = "1";
                }

上述脚本因调用错误而失败。而且我不确定在变量更新为1后如何删除该文件。

正如我测试的那样,在
Dts.Variables[“User::FileExistsFlg”].Value=“1”之前它总是工作得很好

因此,我建议您可以检查脚本任务是ReadOnlyVariables还是ReadWriteVariables。这里有人从blob加载CSV,您可以参考

之后,您可以尝试编写脚本任务

注意: 在64位模式下运行包时,无法调试脚本任务。必须执行包才能调试到脚本任务中。如果仅执行单个任务,则脚本任务代码中的断点将被忽略

如果无法调试脚本任务,可以尝试


Integration Services日志提供程序可以将日志项写入文本文件、SQL Server Profiler、SQL Server、Windows事件日志或XML文件。

在哪里失败?我得到错误:-调用目标引发了异常。可能您需要查找代码的innerException。使用F12逐步调试。