---
title: Attaching a File to a New Job in Script
slug: attaching-a-file-to-a-new-job-in-script
createdAt: 2026-06-11T23:11:18.484Z
---

## Overview

You can attach a file to a job before submitting it by creating a `JobAttachment` from a file stream and adding it to the job's attachment collection.

## Use Case

Use this approach when a script needs to create a new job and include one or more file attachments as part of the submission.

## Example

```csharp
using System.IO;

Job j = new Job();
j.Task = Evaluator.GetObject("=//Tasks/Log a Call") as Task;

string filePath = @"c:\temp\myreport.csv";

byte[] file = File.ReadAllBytes(filePath);

using (MemoryStream ms = new MemoryStream(file))
{
    JobAttachment ja = JobAttachment.Create(
        "activateextract.csv",
        "application/text",
        file.Length,
        ms
    );

    j.Attachments.Add(ja);
    j.Submit();
}
```

## How It Works

1. Create a new `Job` object.
2. Assign a task to the job.
3. Read the file into a byte array.
4. Create a `MemoryStream` from the file contents.
5. Create a `JobAttachment` using the stream.
6. Add the attachment to the job.
7. Submit the job.

## Key Points

- `JobAttachment.Create()` creates an attachment from a stream.
- The attachment must be added to the job's `Attachments` collection before submission.
- A task must be assigned to the job before calling `Submit()`.
- The attachment filename does not need to match the source file name.
- The MIME type should reflect the file being attached.

## Notes

- The example uses a `MemoryStream` to provide the attachment content.
- Ensure the file exists and is accessible before attempting to read it.
- Consider adding error handling to manage missing files, access issues, or submission failures.
