WSS 3.0: change parent type for a content type - sharepoint

I have created a hierarchy of content types. The root of my hierarchy has the content type "Document" as a parent. There are about 20 other content types derived from my root.
Now, I want to change the parent from "Document" to something else. Is it possible? Either in the web interface or in code? Can the definition of content types be dumped to a text file and then recreated? Or any other trick?

If you can create a feature that contains all your custom content types, you will be able to change the XML that defines each content type and it's columns.
This will give you the ability to change the content types for your site by removing the feature and installing it again with the changes (using a Solution is best).
Note that any content using the older content types will still use them after updating the feature (content types are stored at the site level, list level and on the actual item).

Related

Sharepoint online use the same new/display/edit forms for two or more libraries

I'm trying to develop a Sharepoint online site to show inventory of every departments. Since I have several thousands of items, I separate the items into several libraries by departments. Each library will have the same columns.
Currently, I'm facing a problem of how to standard the new/display/edit forms for all libraries. Of cause I can use library template to do so. But what if I need to update the form, e.g. add a reference link or change the layout? Then I need to modify the form one by one for each library.
Is there any solutions that I can create one master form so that (1) it can be applied to two or more libraries, and (2) whenever the master form is changed, the change is automatically applied to the libraries?
Thanks
This is a great use case for Content Types.
At the Site Settings level, Create the columns you want. Then create the Content type you want, called "Inventory" for example. Add the columns to that Content Type.
Add the content type to each library.
Library Settings -> Advanced Settings -> Allow Management of Content Types
Remove the default content type from the library settings page
Now, you can update the columns at the site Content Type level, and it will publish to and update each library.

Best practice for deploying multiple content types with dependencies in SharePoint

I'm developing a solution with approx. 15 custom content types. Therefore I created in Visual Studio a SharePoint Project and added content types defined in XML Markup.
As some of these content types use references between each other (Lookup-Columns), I added List Definitions and List Instances as well. As lookups can be declared in XML since SharePoint 2010 - everything's fine.
Now my feature contains all the content types, the list definitions and the list instances.
But the problem is: Sometimes the deployment succeeds and sometimes it fails. I suppose this may occur because the elements within the features have no activation order. Now I could change my project and create a feature for every content type and define acitvation dependencies to define an activation order. But this would lead to at least 20 features and in my opinion this can't be the supposed solution to handle this correctly.
What's the correct way to deploy content types with lookups to other content types within the same solution?
There's one restriction: everything has to be sandboxed because I want to deploy in SharePoint Online.
I believe I had the same problem as you - I defined two content types; A and B, B relied on A. and both were in the single feature. However when it came time to deploy I received an error:
Error occurred in deployment step 'Activate Features':
The parent content type specified by content type identifier 0x010029043F0D68EC4DF1BC85141AFF451661 does not exist.
I looked in the Manifest.xml file that Visual Studio generates inside the wsp/cab file and noticed the two content type Elements.xml files were defined the wrong way around:
B/Elements.xml
A/Elements.xml
A work around to this is to simply force the order of certain Elements.xml file in the feature (i.e. put the 'root' content type files first).
Open the feature, go to Manifest, open Edit Options and enter the file you need to be specified first in the list of Elements.xml files.
<ElementManifests>
<ElementManifest Location="A\Elements.xml" />
</ElementManifests>
This emits the following XML into the manifest file:
<ElementManifests>
<ElementManifest Location="A\Elements.xml" />
<ElementManifest Location="B\Elements.xml" />
</ElementManifests>

Programmatically determine file types in SharePoint

Is there a way to programmatically determine a file type in SharePoint? I want to limit the types of files that are being uploaded into a document library. I have written an EventReceiver that on ItemAdding conducts the following -
if (!(properties.AfterUrl.Contains(".docx") || properties.AfterUrl.Contains(".pptx") || properties.AfterUrl.Contains(".xlsx") ))
Surely there's a better way to do so?
Blocking file types is only possible at the farm level (through the central admin).
An Event Handler checking the file's extension is the only way to go if you want to be able to administer this at a document library level.
So no, there is no better way of doing this.
If you are really interested in restricting certain types of files, I would recommend to go beyond file's extension or mime types and inspect file's content to determine its nature, which is what IE and Firefox do.
(BTW, there's an IE API whose name I cannot remember right now that gives you the mime type of a file after inspecting it.)

How do I discover the Content Types available on a Document Library?

I have a user that has requested the ability to add files from a custom web site that will upload a file and populate the content types. I have the first part done, uploading the file. I do not know how to read the possible content types and how to update the content types for the specific file being uploaded.
Your question is not very clear - files external to sharepoint do not have a predictable content type. It's not like file extension associations, where .exe is always an executable, and .gif is always an image. Within sharepoint, the only limitation for files' content types is that the content type inherit from the Document content type. The association you make with any given type of file must be invented by you
As for finding out what content types exist on a document library, examine the SPList instance's .RootFolder.ContentTypes property.
Secondly, to set the content type on a file that has been uploaded you will most likely have to develop an Event Receiver which is a class derived from SPItemEventReceiver. You can trap the ItemAdded event and set the file's content type programmatically. This is done by setting one of it's internal properties to the ID of one of the SPContentType's retrieved in the earlier step.
-Oisin

How can I best create a SharePoint list view that shows only root folder contents?

I have a custom SharePoint list definition that is based on the Document content type. My library instance that I create from this contains many HTML documents, and each of those documents has some images saved into a subfolder inside this library. What's the best way to create a view that will show all of those top-level HTML documents without showing all of the image accessory files? I'd prefer to define this within the schema.xml file for my list definition.
I believe adding Scope="FilesOnly" to the View tag in your list definition should do the trick.

Resources