gjshah7254
4/23/2014 - 9:56 PM

Macro - Get Category name for dynamically created pages

Macro - Get Category name for dynamically created pages

case "catgeory":
                    e.Match = true;
                    string GetCategoryName = "";
                    try
                    {
                        string ConnectionStringFromWebConfig = @"" + ConfigurationManager.ConnectionStrings["CMSConnectionString"].ConnectionString + "";
                        SqlConnection cn = new SqlConnection(ConnectionStringFromWebConfig);
                        SqlDataAdapter da = new SqlDataAdapter("SELECT TOP 1 [DocumentName] FROM [dbo].[View_CMS_Tree_Joined] WHERE [NodeAlias] = '" + CMS.CMSHelper.CMSContext.CurrentResolver.ResolveMacros("{?NodeAlias?}") + "'", cn);
                        DataSet ds = new DataSet();
                        da.Fill(ds);

                        if (ds.Tables[0].Rows.Count != 0)
                        {
                            GetCategoryName = ds.Tables[0].Rows[0]["DocumentName"].ToString();
                        }
                    }
                    catch { }
                    e.Result = GetCategoryName;
                    break;