> ## Documentation Index
> Fetch the complete documentation index at: https://devdocs.xbox.com/llms.txt
> Use this file to discover all available pages before exploring further.

# XGameSave Provider Save method reference

> Reference for the XGameSave wrapper Provider.Save method, which writes game-state bytes to a named blob (file) inside a specified save container.

# Microsoft.Xbox.Wrappers.XGameSave.Provider.Save

Saves data to the specified blob (file) within the specified container.

<a id="syntaxSection" />

## Syntax

```cpp theme={null}
HRESULT Save(const std::string& containerName,
             const std::string& blobName,
             size_t dataSize,
             const uint8_t* blobData);
```

<a id="parametersSection" />

### Parameters

*containerName*   \_In\_<br />Type: std::string

The name of the container.

*blobName*  \_In\_<br />Type: std::string

The name of the blob.

*dataSize*   \_In\_<br />Type: size\_t

The amount of data to write to the blob. This size is limited to a maximum of 16 MB (GS\_MAX\_BLOB\_SIZE).

*blobData*   \_In\_<br />Type: uint8\_t\*

A pointer to the bytes to write to the blob.

<a id="retvalSection" />

### Return value

Type: HRESULT

This method returns **S\_OK** upon success, and the following HRESULT codes upon failure:

* **GS\_INVALID\_CONTAINER\_NAME**
* **GS\_OUT\_OF\_LOCAL\_STORAGE**
* **GS\_UPDATE\_TOO\_BIG**
* **GS\_QUOTA\_EXCEEDED**
* **GS\_HANDLE\_EXPIRED**

<a id="exampleSection" />

## Example

The following code example demonstrates how to use the **Save** function.

```cpp theme={null}
using Microsoft::Xbox::Wrappers::GameSave;

std::vector<uint8_t> saveData; // Contains the player's data.

Provider provider = new Provider();

if(SUCCEEDED(provider->Initialize(userHandle, mySCID))
{  
   HRESULT hr = provider->Save("Save_slot_1", "progress", saveData.size(), saveData.data());
   if(FAILED(hr))
   {
      if(hr == E_GS_QUOTA_EXCEEDED)
      {
         // Message that the user must delete saves for this game.
      }
      else if(hr == E_GS_OUT_OF_LOCAL_STORAGE)
      {
         // Message to the user that they have run out of save
         // space on the local device.
      }
      else if(hr == E_GS_UPDATE_TOO_BIG)
      {
         // This is really a development time thing to catch.
         // Your save size was too large for this Save call. Save
         // calls are limited to a maximum size of
         // 16 MB (GS_MAX_BLOB_SIZE).
      }
      else if(hr == E_GS_HANDLE_EXPIRED)
      {
         // You must recreate the provider, and then try again.
      }
      else
      {
         // Log error.
      }
   }
}
```

<a id="remarksSection" />

## Remarks

You must call the [Initialize](/reference/system/Wrappers/classes/provider/methods/xgamesave_wrapper_provider_initialize) method before you can call any other method from the `Provider` class.

To initialize the save game wrapper, and synchronize all of the containers for the specified user, call [Initialize](/reference/system/Wrappers/classes/provider/methods/xgamesave_wrapper_provider_initialize).

To load the data from the given blob, from within the specified container, call [Load](/reference/system/Wrappers/classes/provider/methods/xgamesave_wrapper_provider_load).

<a id="requirementsSection" />

## Requirements

**Header:** xgamesavewrappers.hpp

**Supported platforms:** Windows, XBOX One family consoles and XBOX Series consoles

<a id="seealsoSection" />

## See also

[Microsoft.Xbox.Wrappers.XGameSave.Provider](/reference/system/Wrappers/classes/provider/xgamesave_wrapper_provider)<br />[XGameSave wrapper members](/reference/system/Wrappers/xgamesave_wrapper_members)<br />[Load](/reference/system/Wrappers/classes/provider/methods/xgamesave_wrapper_provider_load)


## Related topics

- [XGameSave Provider Initialize method reference](/reference/system/Wrappers/classes/provider/methods/xgamesave_wrapper_provider_initialize.md)
- [XGameSave Provider Load method reference](/reference/system/Wrappers/classes/provider/methods/xgamesave_wrapper_provider_load.md)
- [XGameSave Provider Delete(std::string&) method](/reference/system/Wrappers/classes/provider/methods/xgamesave_wrapper_provider_delete_string.md)
- [XGameSave Provider QueryContainers method](/reference/system/Wrappers/classes/provider/methods/xgamesave_wrapper_provider_querycontainers.md)
- [XGameSave Provider GetQuota method reference](/reference/system/Wrappers/classes/provider/methods/xgamesave_wrapper_provider_getquota.md)
