Microsoft Professional

Sunday, February 05, 2006

Create Resource Gallery Programmatically(MCMS)

Publishing API cannot create Resource Galleries. To solve this problem you can use ASP file called resstub.asp. This file is used bt Site Manager and can do many things which can't be done by CMS APIs (for example create resource gallery). This file depend on transferring requestes using XML. These XMLs has some parameters depend on versions of MCMS (internalClientVersion, clientVersion, clientVersionNumber).

Steps to use this file:

  1. Create c# Project
  2. Add AEServerObject.dll and AEStubObject.dll as references
  3. Use Code Below:
    // {0} = CMSAUTHTOKEN value
    // {1} = GUID of Parent Resource Gallery
    // {2} = Name of new Resource Gallery
    private const string requestCreate = "";
    // {0} = CMSAUTHTOKEN value
    // {1} = GUID of new Resource Gallery
    private const string requestCommit = "";
    ///
    /// The main entry point for the application.
    ///

    [STAThread]
    static void Main(string[] args) {
    // LOG ON AND GET THE AUTHENTICATION STRING AESERVEROBJECTLib.AESessionClass session = new AESessionClass();
    session.Login("WinNT://DOMAIN/username", "password", "localhost", 0);
    // FIND THE ROOT RESOURCE GALLERY
    string rootGuid = null;
    AESERVEROBJECTLib.IAEServer server = session.GetDefaultServer();
    foreach(string s in server.Children)
    {
    AESERVEROBJECTLib.IAENode n = server.GetNodeByGUID(s, false);
    if(n.Name == "Resources") { rootGuid = s; break; } }

    // LOOP THROUGH THE XML RECURSIVELY
    string newGuid = CreateResourceGallery(session, "resource1", parentGuid);
    // COMMIT session.CommitAll();
    }
    static string CreateResourceGallery(AESERVEROBJECTLib.AESessionClass session, string newName, string parentGuid)
    {
    AEStubClass stub = new AEStubClass();
    XmlDocument doc = new XmlDocument();
    doc.LoadXml(stub.ProcessRequest((AESTUBOBJECTLib.IAESession6)session, "127.0.0.1", String.Format(requestCreate, session.LoginCookie, parentGuid, newName)));
    string newGuid = doc.DocumentElement.SelectSingleNode("
    mailto:Node/@GUID;
    stub.ProcessRequest((AESTUBOBJECTLib.IAESession6)session, "127.0.0.1", String.Format(requestCommit, session.LoginCookie, newGuid, newName)); return newGuid;
    }

Notes:
1. To run sample below you need to adjust these parameters (internalClientVersion, clientVersion, clientVersionNumber) depending on you MCMS version.
2. To Use this file to do many action like sample code. you need to trace foramt of passed XML between Site manager and resstub.asp. Easy way to do that change file resstub.asp to save requests from Site Manager.

5 Comments:

  • Ouch, Stefan is not a fan of your article (http://blogs.technet.com/stefan_gossner/archive/2006/02/08/419003.aspx).
    While your code tries to address a glaring hole in the API, most MCMS users cannot afford to be in an unsupported configuration.

    By Blogger Christopher Bermingham, at 6:19 AM  

  • Stefan's comment makes me wonder whether the 'freedom to innovate' movement was aborted with two billion payed to Sun Microsystems.

    Did that money purchase Microsoft the license to not allow innovation by others on its products (like adding delegates to java).

    By Blogger Chicken Little, at 7:47 PM  

  • internet business opportunitiesinternet business opportunitiesBuy one of our Directory Websites contact us at santa@uktoy.com for full details.
    http://websitewizardsite.com/article_directory/

    internet business opportunities http://websitewizardsite.com/article_directory/ Title: 25000 pages of quality articles coverng wide range of subjec
    URL: http://websitewizardsite.com/article_directory/
    Section: Education
    Description: Article Directory - Over 25500 articles available to view
    Submitted by: Tony ads@barnsley-freeads.co.uk
    Submission details at the end of this message

    internet business opportunities

    By Blogger Barnsley-Freeads, at 7:30 PM  

  • Stefan did the right thing when he raised the support issue.

    you should add an update to your article that clearly states that this is an unsupported way of using the API and it will result in an unsupported configuration.

    cheers

    By Blogger Stephen Cawood, at 7:45 PM  

  • Hello.

    First of all, excuse my bad English.

    Sorry, but I'm triying to play this exemple, but don't work.

    I have a W2003 Server and MCMS2002 and I create a WinForm (in C#), and just put the code of you exemple.

    The first part run correctly, but in the "doc.LoadXml(strXML)" I get an error. I separate de inside intruction to an after variables called strXML (string strXML = stub.ProcessRequest((AESTUBOBJECTLib.IAESession6)session, "localhost", String.Format(requestCreate, session.LoginCookie, parentGuid, newName));).

    Can anyone helpme?

    Thank You Very Much!

    By Anonymous Anonymous, at 2:46 AM  

Post a Comment

Links to this post:

Create a Link

<< Home