Solved

Problem while accessing Share Point Library content type and columns.

Posted on 2011-03-08
7
430 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
Better Security Awareness With Threat Intelligence

See how one of the leading financial services organizations uses Recorded Future as part of a holistic threat intelligence program to promote security awareness and proactively and efficiently identify threats.

 
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

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

Suggested Solutions

SharePoint Designer 2010 has tools and commands to do everything that can be done with web parts in the browser, and then some – except uploading a web part straight into a page that is edited in SPD. So, can it be done? Scenario For a recent pr…
I thought I'd write this up for anyone who has a request to create an anonymous whistle-blower-type submission form created using SharePoint 2010 (this would probably work the same for 2013). It's not 100% fool-proof but it's as close as you can get…
Internet Business Fax to Email Made Easy - With eFax Corporate (http://www.enterprise.efax.com), you'll receive a dedicated online fax number, which is used the same way as a typical analog fax number. You'll receive secure faxes in your email, fr…
This video explains how to create simple products associated to Magento configurable product and offers fast way of their generation with Store Manager for Magento tool.

707 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

Need Help in Real-Time?

Connect with top rated Experts

11 Experts available now in Live!

Get 1:1 Help Now