Topic Options
Rate This Topic
#129181 - 01/02/06 09:39 PM Add Attachments via .Net API
sheider162 Offline
enthusiast

Registered: 05/01/05
Posts: 226
**
Is the adding of attachments supported in the current .Net API?

When I set an attachment field (in a FieldValueList object) to the filename and path of a file (ie. c:\temp\myfile.zip) I receive this error "Error (310): Value has wrong data type for the field;" This error occurs with both the CreateEntry and SetEntry methods. Is there a separate method for adding an attachment?


ARS 6.3
VB.Net 2003
This posting was submitted via the Web interface

Top
#129182 - 01/02/06 09:57 PM Re: Add Attachments via .Net API [Re: niklas_asplund442]
tim_widowfield Offline
journeyman
*****

Registered: 11/04/05
Posts: 51
Did you create an Attachment object first, then set the value with the
SetValue() method? Check out the documentation under "Attachment class."

--Tim


--- "Heider, Stephen" wrote:

> Is the adding of attachments supported in the current .Net API?
>
> When I set an attachment field (in a FieldValueList object) to the
> filename and path of a file (ie. c:\temp\myfile.zip) I receive this
> error "Error (310): Value has wrong data type for the field;" This
> error occurs with both the CreateEntry and SetEntry methods. Is there a
> separate method for adding an attachment?
>
>
> ARS 6.3
> VB.Net 2003
>
>

> UNSUBSCRIBE or access ARSlist Archives at http://www.ARSLIST.org
> (Support: mailto:support@arslist.org)
>


UNSUBSCRIBE or access ARSlist Archives at http://www.ARSLIST.org
(Support: mailto:support@arslist.org)

Top
#129183 - 01/02/06 11:28 PM Re: Add Attachments via .Net API [Re: niklas_asplund442]
appajee_papolu935 Offline
newbie

Registered: 03/10/05
Posts: 21
Yes.

You need to instantiate an Attachment instance; call its one of the
several SetValue overloads to initialize the file name and file content
values; then assign it as a value for an attachment field as below:

// Instantiate an Attachment object
ARSystem.Attachment attach = new ARSystem.Attachment();

// Do some thing similar to one of the following 3 snippets
//1:
System.IO.Stream fileStream = System.IO.File.Open("..\\..\\TEST.JPG",
System.IO.FileMode.Open, System.IO.FileAccess.Read);
byte [] bytes = new byte[fileStream.Length];
fileStream.Read(bytes, 0, (int)fileStream.Length);
fileStream.Close();
attach.SetValue("My test attachment", bytes);

//Or 2:
attach.SetValue("My test attachment", "..\\..\\TEST.JPG");

//Or. 3:
System.IO.Stream fileStream = System.IO.File.Open("..\\..\\TEST.JPG",
System.IO.FileMode.Open, System.IO.FileAccess.Read);
attach.SetValue("My test attachment", fileStream);

// and finally...
fieldValues[536880912] = attach;


As Tim mentioned, look at the docs for Attachment class or Server's
CreateEntry/SetEntry documentation example snippets.

Regards
Appajee Papolu

-----Original Message-----
From: Action Request System discussion list(ARSList)
[mailto:arslist@arslist.org] On Behalf Of Tim Widowfield
Sent: Tuesday, January 03, 2006 1:58 PM
To: arslist@arslist.org
Subject: Re: Add Attachments via .Net API

Did you create an Attachment object first, then set the value with the
SetValue() method? Check out the documentation under "Attachment
class."

--Tim


--- "Heider, Stephen" wrote:

> Is the adding of attachments supported in the current .Net API?
>
> When I set an attachment field (in a FieldValueList object) to the
> filename and path of a file (ie. c:\temp\myfile.zip) I receive this
> error "Error (310): Value has wrong data type for the field;" This
> error occurs with both the CreateEntry and SetEntry methods. Is there
a
> separate method for adding an attachment?
>
>
> ARS 6.3
> VB.Net 2003
>
>


> UNSUBSCRIBE or access ARSlist Archives at http://www.ARSLIST.org
> (Support: mailto:support@arslist.org)
>



UNSUBSCRIBE or access ARSlist Archives at http://www.ARSLIST.org
(Support: mailto:support@arslist.org)


UNSUBSCRIBE or access ARSlist Archives at http://www.ARSLIST.org
(Support: mailto:support@arslist.org)

Top