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:
- Create c# Project
- Add AEServerObject.dll and AEStubObject.dll as references
- 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.