# File Handling

The API provides endpoints for managing SPACE GASS `.sg` project files
— opening, saving, closing, and checking file status before operations.

## Opening a File

<CodeTabs>
```csharp title="C#"
using SpaceGassApi.Models;

await client.Job.Open.PostAsync(
    new OpenJobRequest
    {
        FilePath = @"C:\Projects\MyStructure.sg"
    });
```

```python title="Python"
from space_gass_api.models import OpenJobRequest

await client.job.open.post(
    OpenJobRequest(file_path="C:\\Projects\\MyStructure.sg"))
```

```bash title="curl"
curl -X POST http://localhost:34560/api/v1/job/open \
  -H "Content-Type: application/json" \
  -d '{"filePath": "C:\\Projects\\MyStructure.sg"}'
```
</CodeTabs>

## Checking File Status

Before opening a file, you can check its status to determine if it
is locked by another process or has unsaved changes:

<CodeTabs>
```csharp title="C#"
var status = await client.File.Status.GetAsync(config =>
    config.QueryParameters.FilePath = @"C:\Projects\MyStructure.sg");

// status contains CanOpenSafely, Description, RecommendedAction
```

```python title="Python"
status = await client.file.status.get(file_path=r"C:\Projects\MyStructure.sg")

# status contains can_open_safely, description, recommended_action
```

```bash title="curl"
curl "http://localhost:34560/api/v1/file/status?filePath=C:%5CProjects%5CMyStructure.sg"
```
</CodeTabs>

## Saving

The save endpoint handles both saving to the current path and
saving to a new path. Pass a `filePath` to save as a new file,
or omit it to save in place.

<CodeTabs>
```csharp title="C#"
// Save to current file
await client.Job.Save.PostAsync(new SaveJobRequest());

// Save to a new file path
await client.Job.Save.PostAsync(
    new SaveJobRequest
    {
        FilePath = @"C:\Projects\MyStructure_Copy.sg"
    });
```

```python title="Python"
from space_gass_api.models import SaveJobRequest

# Save to current file
await client.job.save.post(SaveJobRequest())

# Save to a new file path
await client.job.save.post(
    SaveJobRequest(file_path="C:\\Projects\\MyStructure_Copy.sg"))
```

```bash title="curl"
# Save to current file
curl -X POST http://localhost:34560/api/v1/job/save \
  -H "Content-Type: application/json"

# Save to a new file path
curl -X POST http://localhost:34560/api/v1/job/save \
  -H "Content-Type: application/json" \
  -d '{"filePath": "C:\\Projects\\MyStructure_Copy.sg"}'
```
</CodeTabs>

## Creating a New Job

<CodeTabs>
```csharp title="C#"
await client.Job.New.PostAsync();
```

```python title="Python"
await client.job.new.post()
```

```bash title="curl"
curl -X POST http://localhost:34560/api/v1/job/new
```
</CodeTabs>

## Creating a New Job From a Template

Upload a `.sgbase` template file to seed a new job. The template data
is loaded but the new job has no file path — use `Job.Save` with a
`FilePath` (see [Saving](#saving)) to write it to disk.

The body is a `multipart/form-data` upload with one part named
`template`. Both SDKs expose a `NewFromTemplateRequest` you construct
from a file path.

<CodeTabs>
```csharp title="C#"
using SpaceGassApi;

await client.Job.NewFromTemplate.PostAsync(
    new NewFromTemplateRequest(@"C:\Templates\my-template.sgbase"));
```

```python title="Python"
from space_gass_api import NewFromTemplateRequest

await client.job.new_from_template.post(
    NewFromTemplateRequest(r"C:\Templates\my-template.sgbase"))
```

```bash title="curl"
curl -X POST http://localhost:34560/api/v1/job/new-from-template \
  -F "template=@C:/Templates/my-template.sgbase"
```
</CodeTabs>

## Closing

<CodeTabs>
```csharp title="C#"
await client.Job.Close.PostAsync();
```

```python title="Python"
await client.job.close.post()
```

```bash title="curl"
curl -X POST http://localhost:34560/api/v1/job/close
```
</CodeTabs>
