Avatar of prdeshpande
prdeshpande
 asked on

Problem while accessing Share Point Library content type and columns.

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.
C#Microsoft SharePoint.NET Programming

Avatar of undefined
Last Comment
GeorgeGergues

8/22/2022 - Mon
GeorgeGergues

You don't need to change anything in your code.

You have to differentiate between two types of Columns
[1] Site Columns
[2] Library Columns

when you add columns to your site , they are only visibile to your library or list.

If you are working with Content types, they are at the Site collection level , and they are only controlled at that level ,
If you plan to show or hide a Columun you have to do that at the Content type level not the Library level and that will show directly at the List / Library level.

To fix your issue , if you plan to use a specific column in your library that is not being used anywhere else in the site / web , create that only at the Library level and you can hide it as well.

Best of Luck.
prdeshpande

ASKER
See, I am not creating any columns at library level because for example if I want to use column “Company Name” in more than one library then I have to create again and again same column in each and every library, but if I create “Company Name” column at site level means as a site column and add this to content type and add this content type to one or more libraries then I don’t need to create “Company Name” again and again.
Even after adding content type to libraries we can change the status (Required, Optional, Hidden) of column and Information type (Single text, Choice etc) at library level, means in one library Company Name may be a single line of text and in another library it may be a choice as drop down and in other library it may be hidden or removed.
Now what should I do?
Regards,
GeorgeGergues

I am afraid that is not the way Site Columns work.

The site Column is of one type and is of one status.

If you want to have a static schema throughout the site , that is the way to go .


All of life is about relationships, and EE has made a viirtual community a real community. It lifts everyone's boat
William Peck
prdeshpande

ASKER
I am not talking about Default site columns given by SharePoint, I am creating my own Custom site columns and using these columns in libraries by adding in content type as per my requirements that’s the reason why Content Type comes in picture.
See, my purpose is to create a “Multiple Check In” utility means in one shot all the files which are uploaded by “Upload Multiple Documents” option should get Checked in.
And in my every SharePoint sites, I am creating sites columns and adding these columns in Content type and now adding content type in libraries as I already described in my last comment.
So What I want, when user will open utility and needs to click on library name from library List Box control and then Content type List Box control will come with the content type names which are added on library and then will click on content type then a grid view will come containing file id’s and columns on that content type and user will fill up columns for all the files then on single click files get checked in.
If you have any code regarding above requirement so please share with me.
Regards,
ASKER CERTIFIED SOLUTION
GeorgeGergues

THIS SOLUTION ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
See Pricing Options
Start Free Trial
GET A PERSONALIZED SOLUTION
Ask your own question & get feedback from real experts
Find out why thousands trust the EE community with their toughest problems.
prdeshpande

ASKER
Yes, it ok I am ready with one library at a time.
Please provide me your UI which you will design.

Regards,
SOLUTION
GeorgeGergues

THIS SOLUTION ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
See Pricing Options
Start Free Trial
⚡ FREE TRIAL OFFER
Try out a week of full access for free.
Find out why thousands trust the EE community with their toughest problems.