An NDoc Documented Class Library

Engine.LoadDoc Method 

Call this method to load a document from the askSam file.

public static ASERR LoadDoc(
   ASFP file,
   DocType type,
   FormatType format,
   ASDOC doc,
   ref int sub,
   StringBuilder buff,
   ASSIZE size,
   out ASSIZE size_used,
   out doc_hdr hdr
);

Parameters

file
The file handle returned by OpenASFile or OpenASFileEx.
type
The document type you wish to load.
format
The format type you wish to load the with document.
doc
The document handle to load.
sub
Filled with a handle that identifies this loading process, this handle is freed after this methods returns 1, 0, or a call to StopLoadDoc is made.
buff
The buffer to hold the loaded data.
size
The size of the buffer given.
size_used
The amount of buffer space used during the load.
hdr
Filled with the document header information from the file, set to NULL if you do not wish to load this info.

Return Value

Returns 0 if there was an error. Use GetLastASError to find out why. Returns 1 if this method succeeded. Returns MORE_TO_COME if there is more data to load. Returns NEED_MORE_BUFFER if the buffer give is filed or the buffer size is too small, if size_used > 0 than the buffer size is ok.

Remarks

Call this method to load a document from the askSam file given the document handle.

Set the type value to DT_DATA for Standard Documents, to DT_ENTRY for Entry Forms, to DT_REPORT for Reports, to DT_MAILMERGE for Mail Merges.

Set the format parameter to FF_TEXT for text buffer, to FF_HTML for HTML buffer, to FF_RTF for an RTF buffer.

Example

[C#]

ASFP asFileHandle = 0;
StringBuilder strError = new StringBuilder(1024);
ASERR asError = 0;
string result = "";

// Open File

asFileHandle = Engine.OpenASFile(@"C:\Inetpub\wwwroot\asNetSDKRegressionTest\google_news.ask", OpenFileHow.ASOF_READWRITE, OpenFileShare.ASOF_READWRITE);
if (asFileHandle == 0)
{
	Engine.ASErrorToString(Engine.GetLastASError(asFileHandle), strError, 1024);
	result += strError.ToString() + "\n";
	throw new Exception("File was unable to be opened.");
}

// Get the last document in the database as a test case

ASDOC asDocument = 0;
try
{
	asDocument = Engine.LastDoc(asFileHandle, DocType.DT_DATA);
}
catch 
{
	asError = 0;
	Engine.CloseASFile(asFileHandle);
	throw new Exception("Problem Retrieving the Document");
}

// Retrieve the document's size
ASSIZE documentSize = 0;
asError = Engine.GetASDocSize(asFileHandle, DocType.DT_DATA, asDocument, out documentSize);
if (asError == 0)
{
	Engine.ASErrorToString(Engine.GetLastASError(asFileHandle), strError, 1024);
	Engine.CloseASFile(asFileHandle);
	throw new Exception("LoadDoc threw and exception: \n" + strError.ToString());
}

// Retrieve a document's contents

DocType documentType = askSam.DocType.DT_DATA;
FormatType documentFormat = askSam.FormatType.FF_HTML;
int loadingHandle = 0;
StringBuilder strDocument = new StringBuilder(documentSize.Value);
ASSIZE sizeUsed = 0;
doc_hdr documentHeader;
try
{
	asError = Engine.LoadDoc(asFileHandle, documentType, documentFormat, asDocument, ref loadingHandle, strDocument, documentSize, out sizeUsed, out documentHeader);
}
catch (Exception ex)
{
	Engine.ASErrorToString(Engine.GetLastASError(asFileHandle), strError, 1024);
	Engine.CloseASFile(asFileHandle);
	throw new Exception("LoadDoc threw and exception: \n" + ex.Message + "\n" + strError.ToString());
}
if (asError == 0)
{
	Engine.ASErrorToString(Engine.GetLastASError(asFileHandle), strError, 1024);
	result += "LoadDoc: " + strError.ToString() + "\n ";
}
else
{
	asError = Engine.StopLoadDoc(asFileHandle, ref loadingHandle);
	if (asError == 0)
	{
		Engine.ASErrorToString(Engine.GetLastASError(asFileHandle), strError, 1024);
		result += "StopLoadDoc: " + strError.ToString() + "\n ";
	}
	else
	{
		result += strDocument.ToString() + "\n";
	}
}
asError = Engine.CloseASFile(asFileHandle);
if (asError == 0)
{
	Engine.ASErrorToString(Engine.GetLastASError(asFileHandle), strError, 1024);
	result += "CloseASFile: " + strError.ToString() + "\n ";
}
return result;
[VB.NET]
Dim Doc_hdr As doc_hdr

Dim aSFP As ASFP = aSFP.op_Implicit(0)
Dim stringBuilder1 As StringBuilder = New StringBuilder(1024)
Dim aSERR As ASERR = aSERR.op_Implicit(0)
Dim str1 As String = ""
aSFP = Engine.OpenASFile("C:\Inetpub\wwwroot\asNetSDKRegressionTest\google_news.ask", CType(2, OpenFileHow), CType(2, OpenFileShare))
If aSFP.op_Equality(aSFP, 0) Then
    Engine.ASErrorToString(Engine.GetLastASError(aSFP), stringBuilder1, 1024)
    str1 = String.Concat(str1, stringBuilder1.ToString(), Chr(10))
    Throw New Exception("File was unable to be opened.")
End If
Dim aSDOC As ASDOC = aSDOC.op_Implicit(CLng(0))
Try
    aSDOC = Engine.LastDoc(aSFP, CType(1, DocType))
Catch
    aSERR = aSERR.op_Implicit(0)
    Engine.CloseASFile(aSFP)
    Throw New Exception("Problem Retrieving the Document")
End Try
Dim aSSIZE1 As ASSIZE = ASSIZE.op_Implicit(0)
aSERR = Engine.GetASDocSize(aSFP, CType(1, DocType), aSDOC, aSSIZE1)
If aSERR.op_Equality(aSERR, 0) Then
    Engine.ASErrorToString(Engine.GetLastASError(aSFP), stringBuilder1, 1024)
    Engine.CloseASFile(aSFP)
    Throw New Exception(String.Concat("LoadDoc threw and exception: " & Chr(10), stringBuilder1.ToString()))
End If
Dim docType As DocType = CType(1, DocType)
Dim formatType As FormatType = CType(2, FormatType)
Dim i As Integer = 0
Dim stringBuilder2 As StringBuilder = New StringBuilder(aSSIZE1.Value)
Dim aSSIZE2 As ASSIZE = ASSIZE.op_Implicit(0)
Try
    aSERR = Engine.LoadDoc(aSFP, docType, formatType, aSDOC, i, stringBuilder2, aSSIZE1, aSSIZE2, Doc_hdr)
Catch e As Exception
    Engine.ASErrorToString(Engine.GetLastASError(aSFP), stringBuilder1, 1024)
    Engine.CloseASFile(aSFP)
    Throw New Exception(String.Concat("LoadDoc threw and exception: " & Chr(10), e.Message, Chr(10), stringBuilder1.ToString()))
End Try
If aSERR.op_Equality(aSERR, 0) Then
    Engine.ASErrorToString(Engine.GetLastASError(aSFP), stringBuilder1, 1024)
    str1 = String.Concat(str1, "LoadDoc: ", stringBuilder1.ToString(), Chr(10) & " ")
Else
    aSERR = Engine.StopLoadDoc(aSFP, i)
    If aSERR.op_Equality(aSERR, 0) Then
        Engine.ASErrorToString(Engine.GetLastASError(aSFP), stringBuilder1, 1024)
        str1 = String.Concat(str1, "StopLoadDoc: ", stringBuilder1.ToString(), Chr(10) & " ")
    Else
        str1 = String.Concat(str1, stringBuilder2.ToString(), Chr(10))
    End If
End If
aSERR = Engine.CloseASFile(aSFP)
If aSERR.op_Equality(aSERR, 0) Then
    Engine.ASErrorToString(Engine.GetLastASError(aSFP), stringBuilder1, 1024)
    str1 = String.Concat(str1, "CloseASFile: ", stringBuilder1.ToString(), Chr(10) & " ")
End If
Dim str2 As String = str1
Return str2

See Also

Engine Class | askSam Namespace