To create an image, perform the following:
ID
Title
LastModified
DateCreated
UrlName
MediaFileUrlName
You can also set any other properties.
The example below shows you how to create an image with predefined ID.
NOTE: The ID argument is assigned to the master version of the image. For more information about the different versions of an image, see For developers: Content lifecycle.
EXAMPLE: Create an image with predefined ID. The following code samples create an image with the specified ID, Title, and image data.
Native API
First, you get an instance of the LibrariesManager class. You check whether an image with the same ID already exists. Then, to create the image, you must call the CreateImage method of the LibrariesManager class. You can create an image with either predefined or auto-generated ID depending which overload of the method you use. The method returns the master version of the image. Then, you get an instance of the specified parent album. To associate the image with the album, you set the album to the Parent property of the image object. Then, you set the properties of the master version of the image. We recommend to set at least the following properties: Title, UrlName, LastModified, PublicationDate, DateCreated, and MediaFileUrlName. Then, to upload the image data, you call the Upload method of the LibrariesManager class and pass the master version of the image, the stream of the selected file, and its file extension as parameters. To save the changes, you call the SaveChanges method of the manager. Finally, to publish the image, you call the MessageWorkflow method of the WorkflowManager class and pass the required parameters.
LibrariesManager
CreateImage
Parent
PublicationDate
Upload
SaveChanges
MessageWorkflow
WorkflowManager
Fluent API
First, you check whether an image with the same ID already exists. Then, you check whether the specified parent album exists. If it exists, you get the singular album facade of the parent album. To create the image, you call the CreateImage method of the singular album facade. The ID argument is assigned to the ID property of the master version of the item. You check out the item. Then, you set the properties of the image by calling the Do method of the facade. To upload the image data, you call the UploadContent method of the facade and pass the image, the stream of the selected file and its extension as arguments. To check in the image, you call the CheckInmethod of the facade. Then, you save the changes. Finally, to publish the image in live state, you call the MessageWorkflow method of the WorkflowManager class and pass the required parameters.
Do
UploadContent
CheckInmethod
Increase your Sitefinity skills by signing up for our free trainings. Get Sitefinity-certified at Progress Education Community to boost your credentials.
This free lesson teaches administrators, marketers, and other business professionals how to use the Integration hub service to create automated workflows between Sitefinity and other business systems.
This free lesson teaches administrators the basics about protecting yor Sitefinity instance and its sites from external threats. Configure HTTPS, SSL, allow lists for trusted sites, and cookie security, among others.
The free on-demand video course teaches developers how to use Sitefinity .NET Core and leverage its decoupled architecture and new way of coding against the platform.
To submit feedback, please update your cookie settings and allow the usage of Functional cookies.
Your feedback about this content is important