SiteBaseCS_GetAnyEPTDocument Method Content Studio 5.7 SDK
Content Studio Web Content Management System

[This is preliminary documentation and is subject to change.]

Returns the published content of any XML document as an EPTXmlTextParser.

Namespace: ContentStudio.Site
Assembly: CS_SiteLib (in CS_SiteLib.dll) Version: 5.7.5016.0 (5.7.5016.0)
Syntax

public EPTXmlTextParser CS_GetAnyEPTDocument(
	DocumentId documentId
)

Parameters

documentId
Type: ContentStudio.DocumentDocumentId
The XML document to get content for. The document must be published, must be an EPT document and must have browse permissions for the caller.

Return Value

Type: EPTXmlTextParser
Returns the published content of any XML document as an EPTXmlTextParser.
Exceptions

ExceptionCondition
InvalidOperationExceptionThe document is not a valid EPT document
CSExceptionA business rule was violated in the underlying Content Studio database
  • 1001 - The Session is invalid.
  • 1002 - Permission denied.
  • 1038 - The document is not published.
  • 1804 - The document could not be found.
  • 1780 - The document does not contain an element required by the Content Studio EPT standard.
  • 1782 - Invalid document format. XML is not well formed.
FileNotFoundExceptionThe file on disc representing the document does not exist.
SqlExceptionAn error occurred when executing the command against the Content Studio database
Remarks

Browse permission on the document is required and anonymous calls are supported. Note: Do not use this method to open the EPT-document to be presented in a presentation template, in this case use the CS_DataFields property that returns the same object type but that already is instantiated. The returned EPTXmlTextParser makes it easy to get field values of any EPT document that is published and accessible to the visitor.

Security warning!
It is up to you as a programmer to wisely judge what information is acceptible to display on a public web page. For example: An EPT document might contain fields with classified data that are filtered out by using carefully crafted presentation templates. But, with the CS_GetAnyEPTDocument method, you can easily bypass any business rules specified in presentation templates thus causing unwanted information leaks.
Examples

The following example shows how the CS_GetAnyEPTDocument method can be used to enumerate all fields in an arbitrary EPT document and write the field names and their values to the HTML stream. The code also checks, by using the IsEmptyField(String) method, if a field value is empty or null and writes a note about this.
int documentId = 4372;
ContentStudio.Document.EPT.EPTXmlTextParser ept;
try
{
   ept = CS_GetAnyEPTDocument(DocumentID);
   Response.Write("<table>\r\n");
   Response.Write("  <tr style=\"text-align:left;\"><th>Field name</th><th>Field value</th></tr>\r\n");
   foreach(string s in ept)
   {
      Response.Write("  <tr>");
      Response.Write("<td>");
      Response.Write(Server.HtmlEncode(s));
      Response.Write("</td>");
      Response.Write("<td>");
      //Check if the field value is empty or null
      if(!ept.IsEmptyField(s))
         Response.Write(Server.HtmlEncode(ept[s]));
      else
         Response.Write("<i>The value is empty or unspecified</i>");
      Response.Write("</td>");
      Response.Write("</tr>\r\n");
   }
   Response.Write("</table>\r\n");
}
catch(ContentStudio.CSException ex)
{
   Response.Write("<b>" + Server.HtmlEncode(CS_TranslateMessage(ex)) + "</b>");
}
catch(Exception ex)
{
   Response.Write("<b>" + Server.HtmlEncode(ex.Message) + "</b>");
}
A second example shows how to open an EPT document and get the value of a single named field.

int documentId = 4372;
string FieldName = "Header";
ContentStudio.Document.EPT.EPTXmlTextParser ept;
try
{
  ept = CS_GetAnyEPTDocument(DocumentID);
  Response.Write(Server.HtmlEncode("Fieldvalue: " + ept[FieldName]));
}
catch (ContentStudio.CSException ex)
{
  Response.Write("<b>" + Server.HtmlEncode(CS_TranslateMessage(ex)) + "</b>");
}
catch (Exception ex)
{
  Response.Write("<b>" + Server.HtmlEncode(ex.Message) + "</b>");
}
See Also

Reference