AdvantageCMS.Core.Common.BaseClasses Namespace
Build With Advantage

ObjectDataContractXMLSerializer<(Of <(<'T>)>)>..::..SaveToFile Method

Serializes the specified object to a file using DataContractSerializer.

Namespace:  AdvantageCMS.Core.Utils
Assembly:  AdvantageCMS.Core (in AdvantageCMS.Core.dll)

Syntax


public static void SaveToFile(
	T obj,
	string path,
	string encoding,
	bool Indented
)

Parameters

obj
Type: T
The object to serialize.
path
Type: String
The file path to save to.
encoding
Type: String
The character encoding to use (default: "utf-8").
Indented
Type: Boolean
If true, the output XML will be indented for readability.

Examples


C#
var profile = new UserProfile { Name = "Alice", Age = 30 };

// Save with default encoding and no indentation
ObjectDataContractXMLSerializer<UserProfile>.SaveToFile(profile, @"C:\Data\profile.xml");

// Save with indentation for readability
ObjectDataContractXMLSerializer<UserProfile>.SaveToFile(profile, @"C:\Data\profile.xml", Indented: true);