IMPORTANT: This version of Sitefinity CMS is out of support and the respective product documentation is no longer maintained and can be outdated. Use the version selector to view a supported product version.
When creating a document, you must perform the following:
Check whether the document already exists.
Before you create the document, you must check whether a document with the same ID already exists.
Create the document.
If the document does not exist, you create a new document with the specified ID.
Specify the parent document library of the document.
Specify to which document library the document belongs.
Set the required properties.
When creating a new document, it is recommended to set at least the following properties:
You can also set any other properties in this step.
Upload the document.
Upload the document data to the database.
Save the document.
Save all changes that you have made to the document.
Publish the document.
Finally, you publish the document using the workflow manager.
The example below shows you how to create a document with predefined ID.
NOTE: The ID argument is assigned to the master version of the document. For more information about the different versions of a document, see Content lifecycle.
The following code creates a document with the specified ID, Title and document data.
Native API
First, you get an instance of the LibrariesManager class. You check whether a document with the same ID already exists. Then, to create the document, you must call the CreateDocument method of the LibrariesManager class. You can create a document with either predefined or auto-generated ID depending on which overload of the method you use. The method returns the master version of the document. Then, you get an instance of the specified parent document library. To associate the document with the document library, you set the document library to the Parent property of the document object. Then, you set the properties of the master version. It is recommended to set at least the following properties: Title, UrlName, LastModified, PublicationDate, DateCreated. Then, to upload the document data, you call the Upload method of the LibrariesManager class and pass the stream of the selected file as parameter. To save the changes, you call the SaveChanges method of the manager. Finally, to publish the document, you call the MessageWorkflow method of the WorkflowManager class and pass the required parameters.
Fluent API
First, you check whether a document with the same ID already exists. Then, you check whether the specified parent document library exists. If it exists you get the singular document library facade of the parent document library. To create the document, you call theCreateDocument method of the 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 document by calling the Do method of the facade. To upload the document data, you call theUploadContent method of the facade and pass the document, the stream of the selected file and its extension as arguments. To check in the document, you call the CheckIn method of the facade. Then, you save the changes. Finally, to publish the document, you call theMessageWorkflow method of the WorkflowManager class and pass the required parameters.
Back To Top
To submit feedback, please update your cookie settings and allow the usage of Functional cookies.
Your feedback about this content is important