Я пытался решить проблему с помощью
string fileName;
foreach (ImageFile img in documentData.ImageFiles)
{
fileName = img.FileName;
break;
}
вместо
documentData.ImageFiles[0]
Я знаю, что это решение действительно ужасно, и я постараюсь найти лучшее. Я только что узнал, что
string tempImgFileName = documentData.ImageFiles.ReleasedDirectory;
тоже работает. Наконец я использую этот код
public KfxReturnValue ReleaseDoc()
{
try
{
string tempPath = Path.GetTempPath();
documentData.ImageFiles.Copy(tempPath, -1);
string tempImgFileName = documentData.ImageFiles.ReleasedDirectory;
string fileExtension = Path.GetExtension(tempImgFileName);
string documentId = documentData.UniqueDocumentID.ToString("X8");
string filePath = Path.Combine(tempPath, documentId);
string tmpTargetFile = filePath + fileExtension;
string fileToRead = string.Empty;
if (File.Exists(documentData.KofaxPDFFileName)) // try to create a PDF binary
{
fileToRead = documentData.KofaxPDFFileName;
}
else if (File.Exists(tmpTargetFile)) // try to create a TIFF binary if PDF is not possible
{
fileToRead = tmpTargetFile;
}
else
{
// handle error
return KfxReturnValue.KFX_REL_ERROR;
}
string fileName = Path.GetFileName(tmpTargetFile);
byte[] binaryFile = File.ReadAllBytes(fileToRead);
File.Delete(tmpTargetFile);
// use fileName and binaryFile;
return KfxReturnValue.KFX_REL_SUCCESS;
}
catch (Exception e)
{
// handle error
return KfxReturnValue.KFX_REL_ERROR;
}
}