troubleshooting Question

Problem while accessing Share Point Library content type and columns.

Avatar of prdeshpande
prdeshpande asked on
.NET ProgrammingC#Microsoft SharePoint
7 Comments2 Solutions470 ViewsLast Modified:
Hi, I have created MIS library in sharePoint site and allowed manage content type.
I added two content types in MIS library names are “MIS Monthly” and “MIS Weekly” and one more content type given by default name is “Documents”.
Now I want to display the names of content types and columns also added in these content types by programmatically in c#.

And I wrote below code:
------------------------------------------------------------------------------------------------------------
mySite = SPContext.Current.Site;
myWeb = mySite.OpenWeb();
list = myWeb.Lists["MIS"]; //Library Name.
foreach (SPContentType ct in list.RootFolder.UniqueContentTypeOrder)
  {
    ListBox1.Items.Add(ct.Name); // Content types will come in list box.
  }
 protected void ListBox1_SelectedIndexChanged(object sender, EventArgs e)
  {
            mySite = SPContext.Current.Site;
            myWeb = mySite.OpenWeb();
            SPContentType ctt = myWeb.ContentTypes[ListBox1.Text];
        foreach (SPField field in ctt.Fields)
            {
                if (field.Title != "Content Type" && field.Title != "Document Modified By" && field.Title != "Document Created By")
                {
                    if (field.Hidden == false)
                    {
                        ListBox2.Items.Add(field.Title); /*fields(Columns) will come in another list box those who are added in content type at site level.*/
                    }
                }
            }
 }
------------------------------------------------------------------------------------------------------------

I have created Content types on Site level and added site columns into these content types and add content types in Document library by this option ¿ Add from existing site content types.
Now what happening, above code is working fine and showing content type names which are added in library and clicking on any of those content type showing columns respectively.

PROBLEM--->But IF I am going to hide or remove columns from content types from library settings still those columns are coming in results (when code is running and it should not come), but if those columns are hide or removed from content type from Site level setting then not coming in result, and if I will remove or hide from site level setting in content type then it will affect other libraries because the same content types are used in other libraries also and having same columns with different Status (means- Required, Optional, Hidden).
So what should I change in code?
Waiting for reply.
ASKER CERTIFIED SOLUTION
GeorgeGergues

Our community of experts have been thoroughly vetted for their expertise and industry experience.

Join our community to see this answer!
Unlock 2 Answers and 7 Comments.
Start Free Trial
Learn from the best

Network and collaborate with thousands of CTOs, CISOs, and IT Pros rooting for you and your success.

Andrew Hancock - VMware vExpert
See if this solution works for you by signing up for a 7 day free trial.
Unlock 2 Answers and 7 Comments.
Try for 7 days

”The time we save is the biggest benefit of E-E to our team. What could take multiple guys 2 hours or more each to find is accessed in around 15 minutes on Experts Exchange.

-Mike Kapnisakis, Warner Bros