Click or drag to resize
Askia

SurveyFactoryGet Method

Get an instance of an existing survey

Namespace:  AskiaCore
Assembly:  AskiaCore (in AskiaCore.dll) Version: 6.0.0-build000000000000000000000000000000000000000001
Syntax
public static ISurvey Get(
	IContext context,
	int id
)

Parameters

context
Type: AskiaCoreIContext
Context used to access the survey
id
Type: SystemInt32
Id of the survey to access

Return Value

Type: ISurvey
Return the instance of survey or null if not found
Remarks
This method can retrieves both surveys and survey templates.
Examples

Retrieves a specific survey and display its name

using AskiaCore;

namespace MyApp
{
    public class MyProgram
    {
        static void Main()
        {
            // Initialize the database connection string (Where the survey was stored)
            Persistent.InitDatabaseConnection("connectionstring", DatabaseTypes.PORTAL);

            // Create a new context
            IContext context = ContextFactory.Create();
            context.UserId = 1;
            context.SessionId = "xxxxx-xxxxx-xxxxx-xxxxxx";
            context.LanguageId = 2057; // Edit the survey with this language (English)

            // Get the survey with the AskiaPortal Id = 1
            ISurvey survey = SurveyFactory.Get(context, 1);
            if (survey == null)
            {
                Console.WriteLine("[ERROR] Could not find the survey with the AskiaPortal id 1");
            }
            else
            {
                Console.WriteLine("The name of the survey 1 is `{0}`", survey.Name);
            }

            // Release the database connection
            Persistent.EndDatabaseConnection();
        }
    }
}
See Also