Skip to main content

Hi, 

Has anyone done as a 'Save As' of a smartform using the K2 smartform Api? I have seen this done in a demo once and i want to be able to do to make a form generator using templates. Without someone actually going into the designer to create a copy of existing form.

 

Thanks

 

 

Hi,

 

I have not done it myself but i was told it can be done trough the Authoring assemblies.

 

Below is sample code that might direct you in the correct direction.

 

using (AuthoringType instance = this.GetAuthoringInstanceFromDefinition(def))

using (var cloningcontext = new SourceCode.Framework.CloningContext())

using (AuthoringType clone = instance.CloneInContext<AuthoringType>(cloningcontext, Guid.NewGuid()))

{

       //do something with the clone.. Deploy or checkin of whatever.

}

 

private AuthoringType GetAuthoringInstanceFromDefinition(string xml)

{

    try

    {

        if (typeof(AuthoringType).IsAssignableFrom(typeof(SourceCode.Forms.Authoring.Form)))

            return SourceCode.Forms.Design.DefinitionUtility.LoadForm(_formsSessionData.SessionConnection, xml).TryConvert<AuthoringType>();

 

        if (typeof(AuthoringType).IsAssignableFrom(typeof(SourceCode.Forms.Authoring.View)))

            return SourceCode.Forms.Design.DefinitionUtility.LoadView(_formsSessionData.SessionConnection, xml).TryConvert<AuthoringType>();

    }

    catch

    {

        //swallow to allow direct load from Authoring API

    }

 

    if (typeof(AuthoringType).IsAssignableFrom(typeof(SourceCode.Forms.Authoring.IXmlSerializableObject)))

    {

        AuthoringType ret = Activator.CreateInstance<AuthoringType>();

        (ret as SourceCode.Forms.Authoring.IXmlSerializableObject).FromXml(xml);

 

        return ret;

    }

 

    throw new NotSupportedException();

}

 

Regards

Jurie


Reply