The following C# code example retrieves file attachments.
Each file attachment is saved as a TXT file.
using System;
using System.Collections;
using System.ComponentModel;
using System.Data;
using System.IO ;
namespace RetrieveTasks
{
class Class1
{
[STAThread]
static void Main(string[] args)
{
try
{
//Create a TaskManagerServiceService object and set authentication values
TaskManagerServiceService taskManager = new TaskManagerServiceService();
taskManager.Credentials = new System.Net.NetworkCredential("administrator", "password");
//Retrieve file attachments associated with the task
Boolean myTrue = true;
Object[] fileAttachments = taskManager.getAttachmentListForTask(304,myTrue);
//Determine the number of returned tasks
int num = fileAttachments.Length;
//Iterate through the Object array
for (int i=0; i<num;i++)
{
//Extract the BLOB instance from the Object array
BLOB fileAttachment = (BLOB)fileAttachments[i];
//Populate a byte array with a BLOB data
byte[] outByteArray=outDoc.binaryData;
//Create a new file that represents the file attachment
string FILE_NAME = "C:\\FileAtt" +i+".txt" ;
FileStream fs2 = new FileStream(FILE_NAME, FileMode.OpenOrCreate);
//Create a BinaryWriter object
BinaryWriter w = new BinaryWriter(fs2);
w.Write(outByteArray);
w.Close();
fs2.Close();
}
}
catch (Exception ee)
{
Console.WriteLine(ee.Message);
}
}
}
}
|
|
|