none
How to hide the content type in edit form RRS feed

  • Question

  • Hi,

    I have a custom list definition.while adding new element he can choose the respective content types.But i want to hide this content type while editing the properties of document so that the user cannot change the content type for the document which is set by the another user(actual user who uploaded the document ) .Please help me through this.I just want to hide the content type field in edit properties.

    Any changes any in any xml or schema files??

    Thanx in advance :)

    • Changed type Clayton Cobb Tuesday, May 31, 2011 2:23 PM Always use the Question Type
    Monday, May 30, 2011 9:00 AM

Answers

  • Hi ,

    I finally found the solution to hide the content type from the edit properties of the document in sie definition through C# feature.

    So the solution is :

    We have to push a content editor webpart through feature on to the editform.aspx of that document libray.

    So 1 select the editform url of the list as :

    SPList list = web.Lists[listname];

     EditFormURL = list.DefaultEditFormUrl;

     now you have to create a content editor webpart as :

    ContentEditorWebPart objContentEditor = new ContentEditorWebPart();

    / / Fetch the Validation Script 

    sScript = GetValidationScript(); 

    // create a new XmlElement and put the results there
      

    XmlDocument xmlDoc = new XmlDocument();

    // Content will not be saved.
     
     

    objContentEditor.Content = xmlElement;

    Now write the validationscript function which will include the JQuery in it which will hide the content type :

     StringBuilder sbScript = new StringBuilder();

     string sJQueryURL = give reference of jquery-1.4.4.min.js";//exact path of your js file

    sbScript.Append("<script src='" + sJQueryURL + "' type='text/javascript'></script>");

    sbScript.Append("<script type='text/javascript'>");

      //JQuery function

     sbScript.Append("$(document).ready(function() { " );

     sbScript.Append("$(\":input[title='Content Type']\").parent().parent().hide();" );

    sbScript.Append("}); " ); 

     sbScript.Append("</script>" );

    just run the feature and the first row will["Content Type"] will be hide of a particular list.

    Hope this will be helpfull to someone and saves the time as it took me a long time to find the solution for it.

     

    Tuesday, May 31, 2011 12:29 PM
  • ok, I did just that in my blogpost http://marijnsomers.blogspot.com/2011/04/hide-content-type-field-in-editform-via.html

     

    The code you need:

    $(document).ready(function() {
    $("select[id*='ContentTypeChoice']").closest('tr').hide();
    }



    Don't forget a reference to the jquery library.


    Regards, Marijn Somers|| SharePoint Consultant- MCTS SharePoint 2007, 2010 configuring http://www.beyond-it.be || Twitter: http://twitter.com/marijnsomers || http://marijnsomers.blogspot.com
    Tuesday, May 31, 2011 2:49 PM

All replies

  • Never tried this before, but you should be able to edit the edit form in either Infopath (if you are using enterprise and have it) or SharePoint Designer and hide or remove it entirely.
    Monday, May 30, 2011 8:35 PM
  • Hi chris,

    Actually i am creating a site definition.So i want to have the same edit form which will hide the content type on the sites which will be created using my site definition.Using SPD is not a correct solution as it will be used for 1 site only but i have to make it available on each and every site automatically whenever new site is created from my site definition.

    Tuesday, May 31, 2011 5:05 AM
  • Hi ,

    I finally found the solution to hide the content type from the edit properties of the document in sie definition through C# feature.

    So the solution is :

    We have to push a content editor webpart through feature on to the editform.aspx of that document libray.

    So 1 select the editform url of the list as :

    SPList list = web.Lists[listname];

     EditFormURL = list.DefaultEditFormUrl;

     now you have to create a content editor webpart as :

    ContentEditorWebPart objContentEditor = new ContentEditorWebPart();

    / / Fetch the Validation Script 

    sScript = GetValidationScript(); 

    // create a new XmlElement and put the results there
      

    XmlDocument xmlDoc = new XmlDocument();

    // Content will not be saved.
     
     

    objContentEditor.Content = xmlElement;

    Now write the validationscript function which will include the JQuery in it which will hide the content type :

     StringBuilder sbScript = new StringBuilder();

     string sJQueryURL = give reference of jquery-1.4.4.min.js";//exact path of your js file

    sbScript.Append("<script src='" + sJQueryURL + "' type='text/javascript'></script>");

    sbScript.Append("<script type='text/javascript'>");

      //JQuery function

     sbScript.Append("$(document).ready(function() { " );

     sbScript.Append("$(\":input[title='Content Type']\").parent().parent().hide();" );

    sbScript.Append("}); " ); 

     sbScript.Append("</script>" );

    just run the feature and the first row will["Content Type"] will be hide of a particular list.

    Hope this will be helpfull to someone and saves the time as it took me a long time to find the solution for it.

     

    Tuesday, May 31, 2011 12:29 PM
  • That's a pretty heavy sledgehammer to fix something like this.  Is there a reason you didn't customize the list form using SPD or InfoPath?
    SharePoint Architect || Microsoft MVP || My Blog
    Planet Technologies || SharePoint Task Force
    Tuesday, May 31, 2011 2:23 PM
  • ok, I did just that in my blogpost http://marijnsomers.blogspot.com/2011/04/hide-content-type-field-in-editform-via.html

     

    The code you need:

    $(document).ready(function() {
    $("select[id*='ContentTypeChoice']").closest('tr').hide();
    }



    Don't forget a reference to the jquery library.


    Regards, Marijn Somers|| SharePoint Consultant- MCTS SharePoint 2007, 2010 configuring http://www.beyond-it.be || Twitter: http://twitter.com/marijnsomers || http://marijnsomers.blogspot.com
    Tuesday, May 31, 2011 2:49 PM
  • Hi Clayton,

    I am creating a site definition.And if i use SPD it will be for one site only the settings which i will make on Editform.aspx.I want to assign the properies and all when the site will be provisioned using my site definition.So it is essential to deploy it as a feature.Therefore i have to struggle a bit far and lastly i come up with this solution which will be usefull to someone who designs document library and all through site definition.

     

    Wednesday, June 1, 2011 8:23 AM
  • Just go to List Settings->Change new button order and default content type->select only one content type
    • Edited by Matinee016 Monday, July 15, 2013 10:18 AM invalid link
    Monday, July 15, 2013 10:17 AM