Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6348299
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T21:23:32+00:00 2026-05-24T21:23:32+00:00

I have simple script : public void Main() { // TODO: Add your code

  • 0

I have simple script :

 public void Main()
    {
        // TODO: Add your code here
        Dts.TaskResult = (int)ScriptResults.Success;


        //MYCode

        Variables varCollection = null;
     

        string DestinationRoot = varCollection("User::DestinationRoot").Value.ToString();
        int MonthStartPosition = Convert.ToInt32(varCollection("User::MonthStartPosition").Value);
        int MonthLength = Convert.ToInt32(varCollection("User::MonthLength").Value);
        int MonthValue = 0;
        string MonthNameFormat = varCollection("User::MonthNameFormat").Value.ToString();
        string FolderName = string.Empty;
        string MonthwiseDirectory = string.Empty;

        if (MonthStartPosition > 0 && MonthLength > 0)
        {
            MonthValue = Convert.ToInt32(FileName.Substring(MonthStartPosition - 1, MonthLength));
        }

        if (FileName.Length > 0 && MonthValue > 0)
        {
            FolderName = new DateTime(1, MonthValue, 1).ToString(MonthNameFormat);
        }

        MonthwiseDirectory = System.IO.Path.Combine(DestinationRoot, FolderName);

        if (!System.IO.Directory.Exists(MonthwiseDirectory))
        {
            System.IO.Directory.CreateDirectory(MonthwiseDirectory);
        }

        varCollection("User::DestinationFolder").Value = MonthwiseDirectory;

//Error 1 : also getting error here like 'varCollection' is a 'variable' but is used like a 'method'   

        Dts.TaskResult = Dts.Results.Success; //Error 2 
    }

But it gives error like :

Error 1 : ‘varCollection’ is a ‘variable’ but is used like a ‘method’

Error 2: ‘Microsoft.SqlServer.Dts.Tasks.ScriptTask.ScriptObjectModel’ does not contain a definition for ‘Results’ and no extension method ‘Results’ accepting a first argument of type ‘Microsoft.SqlServer.Dts.Tasks.ScriptTask.ScriptObjectModel’ could be found (are you missing a using directive or an assembly reference?) C:\Users\AppData\Local\Temp\SSIS\dfac06a62ee9472bac783737af4957de\ScriptMain.cs 91 34 st_7c1dde41280d4efc996c50fead62bfa9

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-24T21:23:33+00:00Added an answer on May 24, 2026 at 9:23 pm

    First of all, couple of things about how to use Stack Overflow.

    1. Please do not post new questions when you can just ask the person who answered your question How do I create a package that would copy all files from a given folder into a new folder? about how to do this in C#. Also, always mention the version that you are using in the questions that you post.

    2. Please do not post your questions in answer.

    Anyways, here is the C# code for the VB.NET code that I posted. I have also updated the original answer to your other question How do I create a package that would copy all files from a given folder into a new folder? to include the C# code.

    public void Main()
    {
        Variables varCollection = null;
        Dts.VariableDispenser.LockForRead("User::SourceFilePath");
        Dts.VariableDispenser.LockForRead("User::DestinationRoot");
        Dts.VariableDispenser.LockForRead("User::MonthStartPosition");
        Dts.VariableDispenser.LockForRead("User::MonthLength");
        Dts.VariableDispenser.LockForRead("User::MonthNameFormat");
        Dts.VariableDispenser.LockForWrite("User::DestinationFolder");
        Dts.VariableDispenser.GetVariables(ref varCollection);
    
        string SourceFilePath = varCollection["User::SourceFilePath"].Value.ToString();
        string FileName = SourceFilePath.Substring(SourceFilePath.LastIndexOf('\\') + 1);
        string DestinationRoot = varCollection["User::DestinationRoot"].Value.ToString();
        int MonthStartPosition = Convert.ToInt32(varCollection["User::MonthStartPosition"].Value);
        int MonthLength = Convert.ToInt32(varCollection["User::MonthLength"].Value);
        int MonthValue = 0;
        string MonthNameFormat = varCollection["User::MonthNameFormat"].Value.ToString();
        string FolderName = string.Empty;
        string MonthwiseDirectory = string.Empty;
    
        if (MonthStartPosition > 0 && MonthLength > 0)
        {
            MonthValue = Convert.ToInt32(FileName.Substring(MonthStartPosition - 1, MonthLength));
        }
    
        if (FileName.Length > 0 && MonthValue > 0)
        {
            FolderName = new DateTime(1, MonthValue, 1).ToString(MonthNameFormat);
        }
    
        MonthwiseDirectory = System.IO.Path.Combine(DestinationRoot, FolderName);
    
        if (!System.IO.Directory.Exists(MonthwiseDirectory))
        {
            System.IO.Directory.CreateDirectory(MonthwiseDirectory);
        }
    
        varCollection["User::DestinationFolder"].Value = MonthwiseDirectory;
    
        Dts.TaskResult = (int)ScriptResults.Success;
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a simple java class: package test; class Hello { public static void
I have a simple script which is used to start another program. This other
I have a simple script that does some search and replace. This is basically
I have a simple Python script that I want to stop executing if a
I have a simple linux script: #!/bin/sh for i in `ls $1` do echo
I have a simple php script on a server that's using fsockopen to connect
I have a simple PowerShell script that uses WMI to create a web site
I have this simple php script <?php echo '<pre>'; // Outputs all the result
I have a simple bat script that copies files from an known directory to
I have an extremely simple script with PHP exec , calling mysql command: $dbhost

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.