Opens an askSam database
Returns 0 if the file open process failed. Use GetLastASError to find out why the file open failed. Returns greater than 0 if the file was opened successfully. This returns value will be needed by most other askSam Engine methods to work with the file.
Use this method to open an askSam and get a database file handle. If the database is opened successfully you must call CloseASFile passing it the return value from this method to properly close this file and to release memory allocated to work with the file. The the database file is password protected you must use OpenASFileEx to open the database.
[C#]
ASERR asError;
string fileName = @"C:\Inetpub\wwwroot\asNetSDKRegressionTest\blank.ask";
ASFP file_id = Engine.OpenASFile(fileName, OpenFileHow.ASOF_NEW, OpenFileShare.ASOF_EXCLUSIVE);
string result = "";
if (file_id == 0)
{
string path = System.IO.Directory.GetCurrentDirectory();
result += "(path: " + path + ")\n";
string tmp = @"C:\Inetpub\wwwroot\asNetSDKRegressionTest\blank.ask";
if (System.IO.File.Exists(tmp))
result += tmp + " found \n";
else
result += fileName + " not found. \n";
string dir = @"C:\Inetpub\wwwroot\asNetSDKRegressionTest\";
DirectoryInfo di = new DirectoryInfo(dir);
result += di.LastAccessTime.ToShortDateString().ToString() + "\n";
result += "Error while trying to open a file: \n";
asError = Engine.GetLastASError(file_id);
StringBuilder strError = new StringBuilder(1024);
if (Engine.ASErrorToString(asError, strError, 1024))
{
result += strError.ToString() + "\n";
}
else
{
result += "Not enough memory to hold error message.";
}
}
else
{
// Always close file to release memory
ASERR close_file = Engine.CloseASFile(file_id);
if (close_file == 0)
{
result += " Error while trying to close file: \n";
asError = Engine.GetLastASError(file_id);
StringBuilder strError = new StringBuilder(1024);
if (Engine.ASErrorToString(asError, strError, 1024))
{
result += strError.ToString();
}
else
{
result += "Not enough memory to hold error message.\n";
}
}
result += "Test successful \n";
}
return result;