Problem saving Attachment to file  SOLVED

PDF-XChange Editor SDK for Developers

Moderators: TrackerSupp-Daniel, Tracker Support, Paul - Tracker Supp, Vasyl-Tracker Dev Team, Chris - Tracker Supp, Sean - Tracker, Ivan - Tracker Software, Tracker Supp-Stefan

Forum rules
DO NOT post your license/serial key, or your activation code - these forums, and all posts within, are public and we will be forced to immediately deactivate your license.

When experiencing some errors, use the IAUX_Inst::FormatHRESULT method to see their description and include it in your post along with the error code.
Post Reply
prime clinical systems
User
Posts: 211
Joined: Sun Aug 05, 2012 5:20 pm

Problem saving Attachment to file

Post by prime clinical systems »

Hi, I have this code, but gives error at bottom every time, please help
Dim nAttachmentsCount As Long
Dim sName As String
Dim i As Long
Dim pValue As PDFXEditCtl.IPXS_PDFVariant
Dim FS As PDFXEditCtl.IPXC_FileSpec
Dim pFile As PDFXEditCtl.IAFS_File
Dim destPath As PDFXEditCtl.IAFS_Name
Dim Tree1 As PDFXEditCtl.IPXC_NameTree


Set Tree1 = frmMain.PDFC.Doc.CoreDoc.GetNameTree("EmbeddedFiles")
nAttachmentsCount = Tree1.count
If nAttachmentsCount > 0 Then
For i = 0 To nAttachmentsCount - 1
Call Tree1.Item(i, sName, pValue)
If sName = "FlowComments" Then
Set destPath = frmMain.p_fsInst.DefaultFileSys.StringToName(TempFolder & "\FlowComments.docx")
Set FS = frmMain.PDFC.Doc.CoreDoc.GetFileSpecFromVariant(pValue)
Set pFile = frmMain.p_fsInst.DefaultFileSys.openFile(destPath, PDFXEditCtl.AFS_OpenFileFlags.AFS_OpenFile_CreateNew)
FS.EmbeddedFile.SaveToFile pFile
End If
Exit For
Next i
End If
at the openfile create new, it creates the zero byte file in the directory just fine, but save to file always fails.
I've tried openfile flags of CreateAlways, Write, Sharedwrite
Capture.PNG
Sasha - Tracker Dev Team
User
Posts: 5522
Joined: Fri Nov 21, 2014 8:27 am
Contact:

Re: Problem saving Attachment to file  SOLVED

Post by Sasha - Tracker Dev Team »

Hello prime clinical systems,

There is a code like that in the CoreAPIDemo application in the Form1.cs file:

Code: Select all

IAFS_Name name = afsInst.DefaultFileSys.StringToName(m_sFilePath);
IAFS_File file = afsInst.DefaultFileSys.OpenFile(name, (int)AFS_OpenFileFlags.AFS_OpenFile_Write | (int)AFS_OpenFileFlags.AFS_OpenFile_Read
	| (int)AFS_OpenFileFlags.AFS_OpenFile_CreateNew | (int)AFS_OpenFileFlags.AFS_OpenFile_ShareRead);

item.m_pxcEmbeddedFileStream.SaveToFile(file);
file.Close();

coreDoc = m_pxcInst.OpenDocumentFromFile(m_sFilePath, null);
bIsSuccessful = true;
break;
Cheers,
Alex
Subscribe at:
https://www.youtube.com/channel/UC-TwAMNi1haxJ1FX3LvB4CQ
prime clinical systems
User
Posts: 211
Joined: Sun Aug 05, 2012 5:20 pm

Re: Problem saving Attachment to file

Post by prime clinical systems »

Ok well so intuitive is the need for 4 flags, but thanks it worked...
User avatar
Tracker Supp-Stefan
Site Admin
Posts: 17901
Joined: Mon Jan 12, 2009 8:07 am
Location: London
Contact:

Re: Problem saving Attachment to file

Post by Tracker Supp-Stefan »

:)
Post Reply