Quantcast
Channel: SQL Server Integration Services forum
Viewing all articles
Browse latest Browse all 24688

AddIn deprecated for SSIS Script task

$
0
0
I'm trying to use this code which compiles on vs2008 in vs2010:
// C# code
// Fill SSIS variables with file properties using System; using System.Data; using System.IO;                       
// Added to get file properties using System.Security.Principal;       
// Added to get file owner
using System.Security.AccessControl;
// Added to get file owner
using Microsoft.SqlServer.Dts.Runtime;
using System.Windows.Forms;
using System.IO;
using System;
using System.Data;
using System.Security.Principal;
//using System.Security.AccessControl;
namespace ST_9ef66c631df646e08e4184e34887da16.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
        public void Main()
        {
            // Variable for file information            
            FileInfo fileInfo;

            // Fill fileInfo variable with file information            
            fileInfo = new FileInfo(Dts.Variables["User::FilePath"].Value.ToString());

            // Check if file exists            
            Dts.Variables["User::FileExists"].Value = fileInfo.Exists;
            // Get the rest of the file properties if the file exists            
            if (fileInfo.Exists)
            {
                // Get file creation date                
                Dts.Variables["User::FileCreationDate"].Value = fileInfo.CreationTime;

                // Get last modified date                
                Dts.Variables["User::FileLastModifiedDate"].Value = fileInfo.LastWriteTime;

                // Get last accessed date                
                Dts.Variables["User::FileLastAccessedDate"].Value = fileInfo.LastAccessTime;

                // Get size of the file in bytes                
                Dts.Variables["User::FileSize"].Value = fileInfo.Length;

                // Get file attributes                
                Dts.Variables["User::FileAttributes"].Value = fileInfo.Attributes.ToString();
                Dts.Variables["User::FileIsReadOnly"].Value = fileInfo.IsReadOnly;

                //////////////////////////////////////////////////////                
                // Check if the file isn't locked by an other process                
                try
                {
                    // Try to open the file. If it succeeds, set variable to false and close stream
                    FileStream fs = new FileStream(Dts.Variables["User::FilePath"].Value.ToString(), FileMode.Open);
                    Dts.Variables["User::FileInUse"].Value = false;
                    fs.Close();
                }
                catch (Exception ex)
                {
                    // If opening fails, it's probably locked by an other process                    
                    Dts.Variables["User::FileInUse"].Value = true;

                    // Log actual error to SSIS to be sure                     
                    Dts.Events.FireWarning(0, "Get File Properties", ex.Message, string.Empty, 0);
                }
                //////////////////////////////////////////////////////                
                // Get the Windows domain user name of the file owner                
                FileSecurity fileSecurity = fileInfo.GetAccessControl();
                IdentityReference identityReference = fileSecurity.GetOwner(typeof(NTAccount));
                Dts.Variables["User::FileOwner"].Value = identityReference.Value;
            }
            Dts.TaskResult = (int)ScriptResults.Success;
        }
    }
}

The "AddIn" method shows not found by the 2010 compiler.   AddIn seems like the component that gets SSIS to talk to vs2010/c#.  So what replaces AddIn or is there a new template for finding file properties for SSIS 2012?

Viewing all articles
Browse latest Browse all 24688

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>