terça-feira, 5 de junho de 2012

Deploying Custom Child Content Types declaratively VS Deploying Custom Child Content Types using object Model in Sharepoint 2007




So,  one day I was trying to deploy a child content type to MOSS inheriting from a Custom Content Type defined in the UI.

Seemed like a easy and uncomplicated task, but it wasn't, and it actually compromised my WSS content database!

Context by steps taken:

STEP 1: Using the UI I created a Custom Content Type inheriting from the Article Page, which I named

STEP 2: Using a Feature I tried to create a new content type using the previous content type as a parent.
<ContentType   ID=
"0x010100C568DB52D9D0A14D9B2FDCC96666E9F2007948130EC3DB064584E219954237
AF3900242457EFB8B24247815D688C526CD44D009E1CF1269B1F4F4E940C8F13F7D544DD01"
         Name="FilhoDeclarativo" Group="Tipos de Conteúdo Personalizados" 
Version="1">
        <Folder TargetName="_cts/FilhoDeclarativo" />
        <DocumentTemplate TargetName="/_layouts/CreatePage.aspx" />
        <XmlDocuments>
            <XmlDocument NamespaceURI="http://schemas.microsoft.com/sharepoint
/v3/contenttype/forms">
                <FormTemplates xmlns="http://schemas.microsoft.com/sharepoint
/v3/contenttype/forms">
                    <Display>DocumentLibraryForm</Display>
                    <Edit>DocumentLibraryForm</Edit>
                    <New>DocumentLibraryForm</New>
                </FormTemplates>
            </XmlDocument>
        </XmlDocuments>
    </ContentType>
 
 
 
You can notice the 01 in bold on the content type ID.
Although this feature activated properly the content type didn't
show on the UI.
And when I tried to create a new child content type using the UI 
I kept getting:


This happens because the column NextChildByte of the table dbo.ContentType 
in the WSS_contentDatabase still has a value of "1". 






















http://social.msdn.microsoft.com/Forums/en-US/sharepoint2010general/thread/5e30ade2-93b0-4f5c-8acd-25b73946500c/
 
 
This situation could be corrected by updating this value 1 to a value of 2 using 
a SQL comand, but this is not advisable since microsoft doesn't support this. 
 
 
So I decided to try to create a child content type using the Object Model.

  public override void FeatureActivated(SPFeatureReceiverProperties properties)
    {
      SPSite siteCurrent = (SPSite)properties.Feature.Parent;

      SPSecurity.RunWithElevatedPrivileges(() =>
        {


          using (SPSite site = new SPSite(siteCurrent.RootWeb.Url))
          {
            bool original = site.AllowUnsafeUpdates;
            site.AllowUnsafeUpdates = true;

            using (SPWeb objWeb = site.OpenWeb())
            {

              bool originalobjWeb = objWeb.AllowUnsafeUpdates;
              objWeb.AllowUnsafeUpdates = true;


              createContentType(
                @"0x010100C568DB52D9D0A14D9B2FDCC96666E9F2007948130EC3DB0
64584E219954237AF3900242457EFB8B24247815D688C526CD44D009E1CF1269B1F4F4E9
40C8F13F7D544DD", "FilhoProgramado", site);



              objWeb.AllowUnsafeUpdates = originalobjWeb;

            }

            site.AllowUnsafeUpdates = original;

          }




        });
    }
 
 
 
 
   public static SPContentType createContentType(string parentCtypeID,
 string contentTypeName, SPSite site) 
    {      
      
      SPContentTypeId parentID = new SPContentTypeId(parentCtypeID);
      SPContentType cTypeParent = site.RootWeb.AvailableContentTypes[parentID];

      SPContentType custom = new SPContentType(cTypeParent, 
site.RootWeb.ContentTypes, contentTypeName);
      site.RootWeb.ContentTypes.Add(custom);
      custom.Update();
      site.RootWeb.Update();
      
      return custom ;   
    
    }
 
 
So by using the Object Model it's possible to inherit from a 
Custom Content type defined in the UI, most probably because you don't define 
the ChildByte yourself.

  
 
 Cheers!
 
 

 
 

quinta-feira, 31 de maio de 2012

Changing MOSS 2007 Machine Name


  • This same instrutction are all over the web, this is almost an  exact copy from technet.


    Change each alternate access mapping for your MOSS/WSS deployment in Central Administration:
    • Open Central Administration, "Operations" Tab, "Alternate access mappings" link
    • Modify each mapping item to reflect your newly chosen server name
  • Use stsadm.exe to invoke the "renameserver" command option:
    • Open a command prompt window
    • cd "C:\Program Files\Common Files\Microsoft Shared\web server extensions\12\BIN"
    • stsadm -o renameserver -newservername <newname> -oldservername <oldname>
  • Rename your Server via Change Name Operation in Windows Server 2003:
    • Start Menu | Control Panel | System, "Computer Name" tab, "Change" button.
    • Input your new server name
    •  
·    
I
     SIf your machine the VM belongs to a Domain, then chang it to a WorkGroup first, after that add it again to the Domain. http://technet.microsoft.com/en-us/library/cc771844%28WS.10%29.aspx
  • Reboot the server NOW.
  • After reboot, open command prompt
    • cd C:\Program Files\Common Files\Microsoft Shared\web server extensions\12\BIN
    • stsadm -o updatefarmcredentials -userlogin <domainuser> -password <password>
    • iisreset /noforce
  • Check all application pool identities in IIS, update where the old machine name is still there.

A Screencast for a Great start on SharePoint 2007 Unit Testing

A Screencast for a Great start on SharePoint 2007 Unit Testing,

http://www.screencast.com/users/jthake/folders/SharePointDevWiki.com%20Screencast/media/bb2c534d-7339-4c20-84c1-0fd6b5ad5653

Keys Points:

  • More Code
  • Use  SharePoint Guidance
  • Makes it possible for a SP Project to keep growing even when the Developer team is bound to change overtime.
  • Doesn't stop Performance issues from bad code

Cheers!

sábado, 19 de maio de 2012

Debug your WSP assemblies using Vs2008 with Sharepoint 2007



When you can't debug your assemblies you definitely must go and check this Great Blog from Doug Ware!

http://www.elumenotion.com/Blog/Lists/Posts/Post.aspx?ID=23

Key points:

1 . No NEED to COPY PDB files to GAC!!!!!
2 .

"
Open Tools | Options.  -> Check Show all settings if needed and locate Enable Just My Code (Managed only) (UNCHECK it)

Attach to the w3wp.exe process for the instance you want to debug.

To verify that you attached the correct instance of w3wp.exe, open the Modules window by pressing CTRL-ALT-U.



"

You may need to define some Symbol paths, or even to recompile you project after these steps , to make sure everything is in sync!

Happy Debugging! :)

quinta-feira, 1 de março de 2012

So you're almost finished with your work for the day, and feel all happy about making a final deploy, but instead of success you get this:

"Error occurred in deployment step 'Recycle IIS Application Pool': Provider load failure "

I have resolved this executing the following comands in Powershell

restart-service sptimerv4
restart-service spusercodev4
restart-service spadminv4
restart-service TrustedInstaller
restart-service Winmgmt -force

iisreset /noforce
 
 
Source: http://stackoverflow.com/questions/4503928/provider-load-error-when-deploying-sharepoint-2010-solution
 
 
 

domingo, 12 de fevereiro de 2012

For that awkward moment when you no longer remember why Sharepoint?!?