Solved

Problem while accessing Share Point Library content type and columns.

Posted on 2011-03-08
7
432 Views
Last Modified: 2012-05-11
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.
0
Comment
Question by:prdeshpande
  • 4
  • 3
7 Comments
 
LVL 14

Expert Comment

by:GeorgeGergues
ID: 35068798
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.
0
 
LVL 1

Author Comment

by:prdeshpande
ID: 35082013
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,
0
 
LVL 14

Expert Comment

by:GeorgeGergues
ID: 35083926
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 .


0
DevOps Toolchain Recommendations

Read this Gartner Research Note and discover how your IT organization can automate and optimize DevOps processes using a toolchain architecture.

 
LVL 1

Author Comment

by:prdeshpande
ID: 35094198
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,
0
 
LVL 14

Accepted Solution

by:
GeorgeGergues earned 500 total points
ID: 35094605
You have to kow the content type before uploading the document.
If the document is uploaded to the document library , it take teh default content type ( and you must have at least one content type per list/ library)

if you plan to designate a different type , you cannot use the std. upload tool , you will need to select the Content type before you start the upload.



Let me know if I can help in any way , but I think you will need a better design,

I would design the UI to query the CTTYpes depending on the Library ( get the list of required fields per item  ) and then ask the user to fill the fields and have a "Defaults" button for quick fill , as that can get slow.

The only problem with batch checkin , is that you can only do that at one library at a time .

Best of luck.
0
 
LVL 1

Author Comment

by:prdeshpande
ID: 35105375
Yes, it ok I am ready with one library at a time.
Please provide me your UI which you will design.

Regards,
0
 
LVL 14

Assisted Solution

by:GeorgeGergues
GeorgeGergues earned 500 total points
ID: 35108867
I really don't know what is your design and functionality

but I can direct you here for more read .

http://www.codeproject.com/KB/sharepoint/File_Shunter.aspx


Thank you
0

Featured Post

Ransomware-A Revenue Bonanza for Service Providers

Ransomware – malware that gets on your customers’ computers, encrypts their data, and extorts a hefty ransom for the decryption keys – is a surging new threat.  The purpose of this eBook is to educate the reader about ransomware attacks.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

More often than not, we developers are confronted with a need: a need to make some kind of magic happen via code. Whether it is for a client, for the boss, or for our own personal projects, the need must be satisfied. Most of the time, the Framework…
Summary In SharePoint 2010 it is easy to create custom color themes to jazz up a site. Theme colors can also be created in PowerPoint 2010 with a few clicks. But how do the chosen colors actually look in the SharePoint site? The attached PowerPoint…
This video shows how to quickly and easily add an email signature for all users on Exchange 2016. The resulting signature is applied on a server level by Exchange Online. The email signature template has been downloaded from: www.mail-signatures…
Email security requires an ever evolving service that stays up to date with counter-evolving threats. The Email Laundry perform Research and Development to ensure their email security service evolves faster than cyber criminals. We apply our Threat…

777 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question