Call this method to load a document from the askSam file.
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.
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.
[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