This might help.  It's an edited snippet of some code I wrote long time ago.

Notes:

     -  str_vals[i] is the file name.

     -  The stat() function gets info about the file, namely the size.

     -  The switch/case block is inside a large 'for' loop of an 
ARUnsignedIntList.

     -  The fopen() call is just to see if we can open it.
...
ARAttachStruct      att_struct;
struct stat         stat_buf;
FILE                *att_file;
...

...
            case AR_DATA_TYPE_ATTACH:
                if (verbose_flag)
                    printf("\tThis is an attachment field.\n");

                /* Can we open the file? */
                if ((att_file = fopen(str_vals[i], "rb")) != NULL)
                {
                    /* Close it immediately */
                    fclose(att_file);

                    if (verbose_flag)
                        printf("\tAttaching %s\n", str_vals[i]);
                    
                    /* Get file info */
                    stat(str_vals[i], &stat_buf);

                    att_struct.name = strdup(str_vals[i]);
                    att_struct.origSize = (unsigned long) stat_buf.st_size;
                    att_struct.compSize = att_struct.origSize;

                    att_struct.loc.locType = AR_LOC_FILENAME;

                    att_struct.loc.u.filename = strdup(str_vals[i]);
                    
                    fvalue_list.fieldValueList[i].value.u.attachVal = 
                                                            &att_struct;
                    fvalue_list.fieldValueList[i].value.dataType = 
                                                            AR_DATA_TYPE_ATTACH;
                }
                else
                {
                    if (verbose_flag)
                        printf("\tCould not open file: %s\n", str_vals[i]);

                    perror("\tFile error");
                }
                break;


 
Tim Widowfield
[EMAIL PROTECTED]
v: 937-878-9045
f: 937-878-9055
m: 937-369-7012
http://www.widowfield.com

----- Original Message ----
From: jack9999 <[EMAIL PROTECTED]>
To: [email protected]
Sent: Thursday, September 14, 2006 12:53:43 PM
Subject: [ARSLIST] adding attachment using C API

Does anyone have some sample code to add an attachment using C API?
I did something like this and it didn't work:

        ARAttachStruct attach;
        attach.loc.locType= AR_LOC_FILENAME;
        attach.loc.u.filename = "c:\\test_attachment.txt";
        attach.name = "test_attachment.txt";

        fieldvalueList.fieldValueList[fieldnum].fieldId         = 
536870924;
    fieldvalueList.fieldValueList[fieldnum].value.dataType  =
AR_DATA_TYPE_ATTACH;
    fieldvalueList.fieldValueList[fieldnum].value.u.attachVal = &attach;


Thanks



-- 
View this message in context: 
http://www.nabble.com/adding-attachment-using-C-API-tf2272826.html#a6310156
Sent from the ARS (Action Request System) forum at Nabble.com.

_______________________________________________________________________________
UNSUBSCRIBE or access ARSlist Archives at http://www.wwrug.org





_______________________________________________________________________________
UNSUBSCRIBE or access ARSlist Archives at http://www.wwrug.org

Reply via email to