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

  • Home
  • SEARCH
  • 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 6751689
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T12:57:24+00:00 2026-05-26T12:57:24+00:00

I need to convert some VBScript code to C# 2.0, below is the VBScript

  • 0

I need to convert some VBScript code to C# 2.0, below is the VBScript code, which needs to be converted to c#.

' Component Template titles handled by the summary templates
FeaturedCT = "Featured Summary"
SummaryCT = "Summary"

' Set the looping variables on the first component presentation
If IsFirstComponent = 0 Then
    IsFirstComponent = 1

    ' Start out left handed by default
    IsLeftHand = True

    matchCount = 0
    Dim components()
    ReDim components(Page.ComponentPresentations.Count)

    ' Build a list of all the matching component presentations to be rendered out as summaries
    For Each objCP In Page.ComponentPresentations
        ' Is this a Summary component template?
        If objCP.ComponentTemplateTitle = SummaryCT Or objCP.ComponentTemplateTitle = FeaturedCT Then
            ' Check if this object should be included based on its approval status
            If staging Or getFieldValue(objCP.Component.MetadataFields("ApprovalStatus"), "") = "" Then
                If getFieldValue(objCP.Component.MetadataFields("EndDate"), "") <> "" Then
                    If getDateSerial(objCP.Component.MetadataFields("EndDate").Value(1), False) > getDateSerial(Now, False) Then
                        Set components(matchCount) = objCP
                        matchCount = matchCount + 1
                    End If
                Else
                    Set components(matchCount) = objCP
                    matchCount = matchCount + 1
                End If
            End If
        End If
    Next

    ' Resize the array to the amount of matches
    ReDim Preserve components(matchCount)
End If

For i = 0 to UBound(components) - 1
    ' Determine which component to render from the pre-selected array
    If components(i).ComponentID = Component.ID And components(i).OrdinalPosition = ComponentPresentation.OrdinalPosition Then
        ' Featured summary is always left aligned and causes all other items to be right-aligned
        If ComponentPresentation.ComponentTemplateTitle = FeaturedCT Then
            HasFeaturedSummary = 1
            IsLeftHand = True           
        End If

        Call RenderEntry(components, i)

        ' If a featured summary was previously present all following items are right-aligned
        If HasFeaturedSummary = 1 Then
            IsLeftHand = False
        Else
            ' Update the left-handed status
            UpdatePositioning
        End If

        If i = UBound(Components) - 1 Then
            WriteOut "<div class=""clearBoth""></div>"
        End If
    End If
Next

And below is the code which is attempted by me in c#.

  public string RenderSummaryCT()
    {
        string FeaturedCT = "Featured Summary CT";
        string SummaryCT = "Summary CT";
        int IsFirstComponent = 0;
        string result = string.Empty;
        int hasFeaturedSummary = 0;
        Component comp = null;
        bool IsLeftHand = false;
        StringBuilder sbOutput = new StringBuilder();

        List<tc.ComponentPresentation> cmp = new List<tc.ComponentPresentation>();

        if (IsFirstComponent == 0)
        {
            IsFirstComponent = 1;
            IsLeftHand = true;

            //m_Logger.Info("CMP Array-" + cmp.Count);
            foreach (tc.ComponentPresentation objCMP in m_Page.ComponentPresentations)
            {
                if ((objCMP.ComponentTemplate.Title == SummaryCT) || (objCMP.ComponentTemplate.Title == FeaturedCT))
                {
                    comp = objCMP.Component;
                    string approvalStatus = string.Empty;
                    string endDate = string.Empty;

                    if (comp.Metadata != null)
                    {
                        ItemFields compItemfields = new ItemFields(comp.Metadata, comp.MetadataSchema);
                        approvalStatus = th.GetSingleStringValue("ApprovalStatus", compItemfields);
                        endDate = th.GetSingleStringValue("EndDate", compItemfields);
                    }
                    if ((baseutility.GetStagingConstantValue(m_Engine, m_Package)) || (string.IsNullOrEmpty(approvalStatus)))
                    {
                        if (!string.IsNullOrEmpty(endDate))
                        {
                            DateTime eDate = Convert.ToDateTime(baseutility.GetDateSerial(Convert.ToDateTime(endDate), false));
                            DateTime currentDate = Convert.ToDateTime(baseutility.GetDateSerial(DateTime.Now, false));
                            if ((eDate) > (currentDate))
                            {
                                cmp.Add(objCMP);
                            }
                        }
                        else
                        {
                            cmp.Add(objCMP);
                            //m_Logger.Info("2. Adding cmp: " + maxCount.ToString() + "-- " + cmp[maxCount].Component.Title);                              
                        }
                    }
                }
            }
        }
        bool lastFlag = false;
        int cnt = 0;
        int totalLength = cmp.Count;

        foreach (tc.ComponentPresentation cm in cmp)
        {
            m_Logger.Info(cm.Component.Id + "--" + m_Component.Id);

            m_Logger.Info(cnt + "--" + totalLength);

            if (cm.Component.Id == m_Component.Id)
            {
                if (cm.ComponentTemplate.Title == FeaturedCT)
                {
                    m_Logger.Info("inside featured CT");
                    hasFeaturedSummary = 1;
                    IsLeftHand = true;
                }
                sbOutput.Append("" + SummaryBase.SummaryHelper.RenderEntry(cmp, cnt, IsLeftHand, lastFlag));

                m_Logger.Info("IsLeftHand -: " + IsLeftHand.ToString());

                if (hasFeaturedSummary == 1)
                {
                    IsLeftHand = false;
                }
                else
                {
                    //sbOutput.Append("" + SummaryBase.SummaryHelper.UpdatePositioning(IsLeftHand));
                    if (IsLeftHand)
                    {
                        IsLeftHand = false;
                    }
                    else
                    {
                        //m_Logger.Info("UpdatePositioning");
                        sbOutput.Append("<div class=\"clearBoth\"></div>");
                        IsLeftHand = true;
                    }
                }

                m_Logger.Info("CMP Title -: " + cm.Component.Title);

                cnt = cnt + 1;
                if (totalLength == cnt)
                {
                    m_Logger.Info("cnt-" + cnt);
                    lastFlag = true;
                }
                if (lastFlag)
                {
                    sbOutput.Append(" <div class=\"clearBoth\"></div>");
                }
            }
        }

        return sbOutput.ToString();
    }

I am sure there is something wrong, can you please suggest the suitable logic using above VBScript logic.

  • 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-26T12:57:24+00:00Added an answer on May 26, 2026 at 12:57 pm

    There’s more to this than just “Converting VBScript to .NET”, you’re also moving from COM-based Tridion Object Model, to the .NET TOM – which works quite differently.

    My recommendation here would be to take a very analytic view to it:

    1. Break down your code and write the logic on paper first
    2. Try to understand why it needs to happen and if it should still be the case

    This should make it a lot easier for you to rewrite the code later on.

    I would certainly take this opportunity to rewrite parts of it so it makes more sense – like having the IsFirstComponent variable converted to a boolean instead of an int, and remove all HTML from your c# code (not that you have much in there, but the next person working on this code would probably like to know that the HTML is not being created by some assembly “hidden” somewhere on your server).

    I’ll try to take a look at this VBScript later, but I think that understanding really what the code does may be more important at this point.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

The following is some old ASMX code which I need to convert to WCF
I need to convert some code done by someone else, to work in my
As part of my Final Year Project, I need to convert some FORTRAN code
I need to convert some MATLAB code to C++. I am using Visual Studio
I need to convert some files to PDF and then attach them to an
I need to convert some strings, and pull out the two first integers e.g:
In a Win32/WTL/C++ app, I need to convert some 8.3 paths to their true
I have a need to convert Pixels to Points in C#. I've seen some
For some reason I need to cast/convert a DateTime into one of many custom
I need to convert some variables that use parentheses instead of bracket in a

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.