Web API Reference MapGuide Open Source

virtual void MgResourceService::SetResourceData MgResourceIdentifier resource,
CREFSTRING  dataName,
CREFSTRING  dataType,
MgByteReader data
[pure virtual, inherited]
 

Adds resource data to the specified resource.

Remarks:
This uploads the data and stores it in the repository. It does not perform any necessary conversion (for example, converting a version 2 SDF file into a version 3 SDF). If the data needs to be converted into a form that can be used with the MapGuide server, you must use the Studio application or the Studio API.
.Net Syntax
virtual void SetResourceData(MgResourceIdentifier resource, string dataName, string dataType, MgByteReader data);
Java Syntax
virtual void SetResourceData(MgResourceIdentifier resource, String dataName, String dataType, MgByteReader data);
PHP Syntax
virtual void SetResourceData(MgResourceIdentifier resource, string dataName, string dataType, MgByteReader data);

Parameters:
resource (MgResourceIdentifier) Resource to which this data is to be associated.
dataName (String/string) Name for the data.
This name must match an element name within the XML content document. If the data name is UserCredentials, then MgResourceTag::Username and MgResourceTag::Password can be inserted into the XML content document to represent provider specific username and/or password. See the example below.
If resource data with the same name has already been set for this resource, the API will overwrite the old setting. No exception is generated. The data name may be any valid UTF-8 string
dataType (String/string) Data type for the resource data. It must match one of the types defined in MgResourceDataType and is case sensitive. Data names must be unique.
data (MgByteReader) Data to set.
Returns:
Returns nothing.
Examples (PHP)
This example sets resource data and stores it as a file:
    /// // Assuming that $resourceService has already been initialized
    /// // Assuming that 'Library://Geography/Calgary points of interest.FeatureSource' has already been added to the repository
    /// $resourceID = new MgResourceIdentifier('Library://Geography/Calgary points of interest.FeatureSource');
    /// $byteSource = new MgByteSource('C:DataCalgaryDataCalgary points.sdf');
    /// $data = $byteSource->GetReader();
    /// $resourceService->SetResourceData($resourceID, 'locations of points of interest', 'File', $data);
    /// 

This example sets resource data and stores it as a stream:

    /// // Assuming that 'Library://Geography/Calgary symbols.SymbolSet' has already been added to the repository
    /// $resourceID = new MgResourceIdentifier('Library://Geography/Trees.SymbolLibrary');
    /// $byteSource = new MgByteSource('C:DataCalgaryDatamarkers.dwf');
    /// $data = $byteSource->GetReader();
    /// $resourceService->SetResourceData($resourceID, 'symbols for points of interest', 'Stream', $data);
    /// 

This example sets the embedded credentials for a resource and stores it as a string. The string data type must be used for embedded credentials. The data name must be MgResourceDataName::UserCredentials.

    /// // Assuming that 'Library://Geography/database connnection.FeatureSource' has already been added to the repository
    /// $resourceID = new MgResourceIdentifier('Library://Geography/database connnection.FeatureSource');
    /// $byteSource = new MgByteSource('C:DataCalgaryDatacredentials.txt');
    /// $data = $byteSource->GetReader();
    /// $dataName = new MgResourceDataName();
    /// $resourceService->SetResourceData($resourceID, MgResourceDataName::UserCredentials, 'String', $data);
    /// 

Exceptions:
MgInvalidRepositoryTypeException 
MgInvalidResourceTypeException if resource is a folder type
MgInvalidResourceDataTypeException if the specified dataType is not in MgResourceDataType
See also:
EnumerateResourceData

GetResourceData

RenameResourceData

DeleteResourceData