Document samples
Basics
On most methods you'll see parameter named "docId". The value of this parameter can be some valid document UUID or path.
Example of docId:
- Using UUID -> "f123a950-0329-4d62-8328-0ff500fd42db";
- Using path -> "/okm:root/logo.png"
Methods
createDocumentSimple
Description:
Method | Return values | Description |
---|---|---|
createDocumentSimple(String docPath, FileStream fs) |
Document |
Creates a new document and returns as a result an object Document with the properties of the created document. |
Example:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using com.openkm.sdk4csharp;
using com.openkm.sdk4csharp.bean;
using System.IO;
namespace OKMRest
{
public class Program
{
static void Main(string[] args)
{
String host = "http://localhost:8080/OpenKM";
String username = "okmAdmin";
String password = "admin";
OKMWebservice ws = OKMWebservicesFactory.newInstance(host, username, password);
try
{
FileStream fileStream = new FileStream("E:\\logo.png", FileMode.Open);
ws.createDocumentSimple("/okm:root/logo.png", fileStream);
fileStream.Dispose();
} catch (Exception e) {
System.Console.WriteLine(e.ToString());
}
}
}
}
deleteDocument
Description:
Method | Return values | Description |
---|---|---|
deleteDocument(String docId) |
void |
Deletes a document. |
When a document is deleted is automatically moved to /okm:trash/userId folder. |
Example:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using com.openkm.sdk4csharp;
namespace OKMRest
{
public class Program
{
static void Main(string[] args)
{
String host = "http://localhost:8080/OpenKM";
String username = "okmAdmin";
String password = "admin";
OKMWebservice ws = OKMWebservicesFactory.newInstance(host, username, password);
try
{
ws.deleteDocument("/okm:root/logo.png");
} catch (Exception e) {
System.Console.WriteLine(e.ToString());
}
System.Console.ReadKey();
}
}
}
getDocumentProperties
Description:
Method | Return values | Description |
---|---|---|
getDocumentProperties(String docId) |
Document |
Returns the document properties. |
Example:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using com.openkm.sdk4csharp;
namespace OKMRest
{
public class Program
{
static void Main(string[] args)
{
String host = "http://localhost:8080/OpenKM";
String username = "okmAdmin";
String password = "admin";
OKMWebservice ws = OKMWebservicesFactory.newInstance(host, username, password);
try
{
System.Console.WriteLine(ws.getDocumentProperties("/okm:root/logo.png").toString());
} catch (Exception e) {
System.Console.WriteLine(e.ToString());
}
}
}
}
getContent
Description:
Method | Return values | Description |
---|---|---|
getContent(String docId) |
Stream |
Retrieves a document content - binary data - of the actual document version. |
In case you sent the file across a Servlet response we suggest set the content length with:
We've found wrong size problems while using:
|
Example:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using com.openkm.sdk4csharp;
using System.IO;
namespace OKMRest
{
public class Program
{
static void Main(string[] args)
{
String host = "http://localhost:8080/OpenKM";
String username = "okmAdmin";
String password = "admin";
OKMWebservice ws = OKMWebservicesFactory.newInstance(host, username, password);
try
{
Stream s = ws.getContent("/okm:root/logo.png");
FileStream fs = new FileStream(@"D:\Download\logo.png", FileMode.OpenOrCreate);
s.CopyTo(fs);
fs.Close();
s.Close();
} catch (Exception e) {
System.Console.WriteLine(e.ToString());
}
}
}
}
getContentByVersion
Description:
Method | Return values | Description |
---|---|---|
getContentByVersion(String docId,String versionId) |
Stream |
Retrieve document content ( binary data ) of some specific document version. |
In case you sent the file across a Servlet response we suggest set the content length with:
We've found wrong size problems while using:
|
Example:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using com.openkm.sdk4csharp;
using System.IO;
namespace OKMRest
{
public class Program
{
static void Main(string[] args)
{
String host = "http://localhost:8080/OpenKM";
String username = "okmAdmin";
String password = "admin";
OKMWebservice ws = OKMWebservicesFactory.newInstance(host, username, password);
try
{
Stream st = ws.getContentByVersion("/okm:root/logo.png","1.1");
} catch (Exception e) {
System.Console.WriteLine(e.ToString());
}
}
}
}
getDocumentChildren
Description:
Method | Return values | Description |
---|---|---|
getDocumentChildren(String fldId) |
List<Document> |
Returns a list of all documents which their parent is fldId. |
The parameter fldId can be a folder or a record node. |
Example:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using com.openkm.sdk4csharp;
using com.openkm.sdk4csharp.bean;
namespace OKMRest
{
public class Program
{
static void Main(string[] args)
{
String host = "http://localhost:8080/OpenKM";
String username = "okmAdmin";
String password = "admin";
OKMWebservice ws = OKMWebservicesFactory.newInstance(host, username, password);
try
{
foreach (Document doc in ws.getDocumentChildren("/okm:root"))
{
System.Console.WriteLine(doc);
}
} catch (Exception e) {
System.Console.WriteLine(e.ToString());
}
}
}
}
renameDocument
Description:
Method | Return values | Description |
---|---|---|
renameDocument(String docId, String newName) |
document |
Changes the name of a document. |
Example:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using com.openkm.sdk4csharp;
using com.openkm.sdk4csharp.bean;
namespace OKMRest
{
public class Program
{
static void Main(string[] args)
{
String host = "http://localhost:8080/OpenKM";
String username = "okmAdmin";
String password = "admin";
OKMWebservice ws = OKMWebservicesFactory.newInstance(host, username, password);
try
{
Document doc = ws.renameDocument("f123a950-0329-4d62-8328-0ff500fd42db", "logo_rename.png");
} catch (Exception e) {
System.Console.WriteLine(e.ToString());
}
}
}
}
setProperties
Description:
Method | Return values | Description |
---|---|---|
setProperties(Document doc) |
void |
Changes a document properties. |
Variables allowed to be changed:
Only not null and not empty variables will take on consideration. |
Example:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using com.openkm.sdk4csharp;
using com.openkm.sdk4csharp.bean;
namespace OKMRest
{
public class Program
{
static void Main(string[] args)
{
String host = "http://localhost:8080/OpenKM";
String username = "okmAdmin";
String password = "admin";
OKMWebservice ws = OKMWebservicesFactory.newInstance(host, username, password);
try
{
Document doc = ws.getDocumentProperties("f123a950-0329-4d62-8328-0ff500fd42db");
doc.description = "some description";
doc.keywords.Add("test");
ws.setProperties(doc);
} catch (Exception e) {
System.Console.WriteLine(e.ToString());
}
}
}
}
checkout
Description:
Method | Return values | Description |
---|---|---|
checkout(String docId) |
void |
Marks the document for edition. |
Only one user can modify a document at the same time. Before starting edition must do a checkout action that locks the edition process for other users and allows only to the user who has executed the action. |
Example:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using com.openkm.sdk4csharp;
namespace OKMRest
{
public class Program
{
static void Main(string[] args)
{
String host = "http://localhost:8080/OpenKM";
String username = "okmAdmin";
String password = "admin";
OKMWebservice ws = OKMWebservicesFactory.newInstance(host, username, password);
try
{
ws.checkout("/okm:root/logo.png");
// At this point the document is locked for other users except for the user who executed the action
} catch (Exception e) {
System.Console.WriteLine(e.ToString());
}
}
}
}
cancelCheckout
Description:
Method | Return values | Description |
---|---|---|
cancelCheckout(String docId) |
void |
Cancels a document edition. |
This action can only be done by the user who previously executed the checkout action. |
Example:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using com.openkm.sdk4csharp;
namespace OKMRest
{
public class Program
{
static void Main(string[] args)
{
String host = "http://localhost:8080/OpenKM";
String username = "okmAdmin";
String password = "admin";
OKMWebservice ws = OKMWebservicesFactory.newInstance(host, username, password);
try
{
// At this point the document is locked for other users except for the user who executed the action
ws.cancelCheckout("/okm:root/logo.png");
// At this point other users are allowed to execute a checkout and modify the document
} catch (Exception e) {
System.Console.WriteLine(e.ToString());
}
}
}
}
forceCancelCheckout
Description:
Method | Return values | Description |
---|---|---|
forceCancelCheckout(String docId) |
void |
Cancels a document edition. |
This method allows canceling edition on any document. It is not mandatory to execute this action by the same user who previously executed the checkout action. This action can only be done by a superuser ( user with ROLE_ADMIN ). |
Example:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using com.openkm.sdk4csharp;
namespace OKMRest
{
public class Program
{
static void Main(string[] args)
{
String host = "http://localhost:8080/OpenKM";
String username = "okmAdmin";
String password = "admin";
OKMWebservice ws = OKMWebservicesFactory.newInstance(host, username, password);
try
{
// At this point the document is locked for other users except for the user who executed the action
ws.forceCancelCheckout("/okm:root/logo.png");
// At this point other users are allowed to execute a checkout and modify the document
} catch (Exception e) {
System.Console.WriteLine(e.ToString());
}
}
}
}
isCheckedOut
Description:
Method | Return values | Description |
---|---|---|
isCheckedOut(String docId) |
Boolean |
Returns a boolean that indicates if the document is on edition or not. |
Example:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using com.openkm.sdk4csharp;
namespace OKMRest
{
public class Program
{
static void Main(string[] args)
{
String host = "http://localhost:8080/OpenKM";
String username = "okmAdmin";
String password = "admin";
OKMWebservice ws = OKMWebservicesFactory.newInstance(host, username, password);
try
{
System.Console.WriteLine("Is the document checkout:"+ws.isCheckedOut("/okm:root/logo.png"));
} catch (Exception e) {
System.Console.WriteLine(e.ToString());
}
}
}
}
checkin
Description:
Method | Return values | Description |
---|---|---|
checkin(String docId, String comment, FileStream fs) |
Version |
Updates a document with a new version and returns an object with new Version values. |
Only the user who started the edition - checkout - is allowed to update the document. |
Example:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.IO;
using com.openkm.sdk4csharp;
namespace OKMRest
{
public class Program
{
static void Main(string[] args)
{
String host = "http://localhost:8080/OpenKM";
String username = "okmAdmin";
String password = "admin";
OKMWebservice ws = OKMWebservicesFactory.newInstance(host, username, password);
try
{
FileStream fs = new FileStream("E:\\logo.png", FileMode.Open);
ws.checkin("/okm:root/logo.png","optional some comment",fs);
fs.Dispose();
} catch (Exception e) {
System.Console.WriteLine(e.ToString());
}
}
}
}
getDocumentVersionHistory
Description:
Method | Return values | Description |
---|---|---|
getDocumentVersionHistory(String docId) |
List<Version> |
Returns a list of all document versions. |
Example:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using com.openkm.sdk4csharp;
using com.openkm.sdk4csharp.bean;
namespace OKMRest
{
public class Program
{
static void Main(string[] args)
{
String host = "http://localhost:8080/OpenKM";
String username = "okmAdmin";
String password = "admin";
OKMWebservice ws = OKMWebservicesFactory.newInstance(host, username, password);
try
{
foreach (Version version in ws.getVersionHistory("/okm:root/logo.png"))
{
System.Console.WriteLine(version);
}
} catch (Exception e) {
System.Console.WriteLine(e.ToString());
}
}
}
}
lock
Description:
Method | Return values | Description |
---|---|---|
lock(String docId) |
LockInfo |
Locks a document and returns an object with the Lock information. |
Only the user who locked the document is allowed to unlock. A locked document can not be modified by other users. |
Example:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using com.openkm.sdk4csharp;
using com.openkm.sdk4csharp.bean;
namespace OKMRest
{
public class Program
{
static void Main(string[] args)
{
String host = "http://localhost:8080/OpenKM";
String username = "okmAdmin";
String password = "admin";
OKMWebservice ws = OKMWebservicesFactory.newInstance(host, username, password);
try
{
ws.lockDocument("/okm:root/logo.png");
} catch (Exception e) {
System.Console.WriteLine(e.ToString());
}
}
}
}
unlock
Description:
Method | Return values | Description |
---|---|---|
unlock(String docId) |
void |
Unlocks a locked document. |
Only the user who locked the document is allowed to unlock. |
Example:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using com.openkm.sdk4csharp;
namespace OKMRest
{
public class Program
{
static void Main(string[] args)
{
String host = "http://localhost:8080/OpenKM";
String username = "okmAdmin";
String password = "admin";
OKMWebservice ws = OKMWebservicesFactory.newInstance(host, username, password);
try
{
ws.unlock("/okm:root/logo.png");
} catch (Exception e) {
System.Console.WriteLine(e.ToString());
}
}
}
}
forceUnlock
Description:
Method | Return values | Description |
---|---|---|
forceUnlock(String docId) |
void |
Unlocks a locked document. |
This method allows to unlock any locked document. It is not mandatory to execute this action by the same user who previously executed the checkout lock action. This action can only be done by a superuser ( user with ROLE_ADMIN ). |
Example:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using com.openkm.sdk4csharp;
namespace OKMRest
{
public class Program
{
static void Main(string[] args)
{
String host = "http://localhost:8080/OpenKM";
String username = "okmAdmin";
String password = "admin";
OKMWebservice ws = OKMWebservicesFactory.newInstance(host, username, password);
try
{
ws.forceUnlock("/okm:root/logo.png");
} catch (Exception e) {
System.Console.WriteLine(e.ToString());
}
}
}
}
isLocked
Description:
Method | Return values | Description |
---|---|---|
isLocked(String docId) |
Boolean |
Returns a boolean that indicates if the document is locked or not. |
Example:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using com.openkm.sdk4csharp;
namespace OKMRest
{
public class Program
{
static void Main(string[] args)
{
String host = "http://localhost:8080/OpenKM";
String username = "okmAdmin";
String password = "admin";
OKMWebservice ws = OKMWebservicesFactory.newInstance(host, username, password);
try
{
System.Console.WriteLine("Is document locked:" + ws.isLocked("/okm:root/logo.png"));
} catch (Exception e) {
System.Console.WriteLine(e.ToString());
}
}
}
}
getLockInfo
Description:
Method | Return values | Description |
---|---|---|
getLockInfo(String docId) |
LockInfo |
Returns an object with the Lock information |
Example:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using com.openkm.sdk4csharp;
namespace OKMRest
{
public class Program
{
static void Main(string[] args)
{
String host = "http://localhost:8080/OpenKM";
String username = "okmAdmin";
String password = "admin";
OKMWebservice ws = OKMWebservicesFactory.newInstance(host, username, password);
try
{
System.Console.WriteLine(ws.getLockInfo("/okm:root/logo.png"));
} catch (Exception e) {
System.Console.WriteLine(e.ToString());
}
}
}
}
purgeDocument
Description:
Method | Return values | Description |
---|---|---|
purgeDocument(String docId) |
void |
The document is definitely removed from repository. |
Usually, you will purge documents into /okm:trash/userId - the personal trash user locations - but is possible to directly purge any document from the whole repository. When a document is purged it will only be able to be restored from a previous repository backup. The purge action removes the document definitely from the repository. |
Example:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using com.openkm.sdk4csharp;
namespace OKMRest
{
public class Program
{
static void Main(string[] args)
{
String host = "http://localhost:8080/OpenKM";
String username = "okmAdmin";
String password = "admin";
OKMWebservice ws = OKMWebservicesFactory.newInstance(host, username, password);
try
{
ws.purgeDocument("/okm:trash/okmAdmin/logo.png");
} catch (Exception e) {
System.Console.WriteLine(e.ToString());
}
}
}
}
moveDocument
Description:
Method | Return values | Description |
---|---|---|
moveDocument(String docId, String dstId) |
void |
Moves a document into some folder or record. |
The values of the dstId parameter should be a folder or record UUID or path. |
Example:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using com.openkm.sdk4csharp;
namespace OKMRest
{
public class Program
{
static void Main(string[] args)
{
String host = "http://localhost:8080/OpenKM";
String username = "okmAdmin";
String password = "admin";
OKMWebservice ws = OKMWebservicesFactory.newInstance(host, username, password);
try
{
ws.moveDocument("/okm:root/logo.png", "/okm:root/test");
} catch (Exception e) {
System.Console.WriteLine(e.ToString());
}
}
}
}
copyDocument
Description:
Method | Return values | Description |
---|---|---|
copyDocument(String docId, String dstId) |
void |
Copies a document into some folder or record. |
The values of the dstId parameter should be a folder or record UUID or path. When parameter newName value is null, the document will preserve the same name. Only the binary data and the security grants are copied to the destination, the metadata, keywords, etc. of the document are not copied. See "extendedDocumentCopy" method for this feature. |
Example:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using com.openkm.sdk4csharp;
namespace OKMRest
{
public class Program
{
static void Main(string[] args)
{
String host = "http://localhost:8080/OpenKM";
String username = "okmAdmin";
String password = "admin";
OKMWebservice ws = OKMWebservicesFactory.newInstance(host, username, password);
try
{
ws.copyDocument("/okm:root/logo.png", "/okm:root/temp");
} catch (Exception e) {
System.Console.WriteLine(e.ToString());
}
}
}
}
restoreVersion
Description:
Method | Return values | Description |
---|---|---|
restoreVersion(String docId, String versionId) |
void |
Promote a previous document version to the actual version. |
Example:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using com.openkm.sdk4csharp;
namespace OKMRest
{
public class Program
{
static void Main(string[] args)
{
String host = "http://localhost:8080/OpenKM";
String username = "okmAdmin";
String password = "admin";
OKMWebservice ws = OKMWebservicesFactory.newInstance(host, username, password);
try
{
// Actual version is 2.0
ws.restoreVersion("/okm:root/logo.png", "1.0");
// Actual version is 1.0
} catch (Exception e) {
System.Console.WriteLine(e.ToString());
}
}
}
}
purgeVersionHistory
Description:
Method | Return values | Description |
---|---|---|
purgeVersionHistory(String docId) |
void |
Purges all documents version except the actual version. |
This action compact the version history of a document. This action cannot be reverted. |
Example:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using com.openkm.sdk4csharp;
namespace OKMRest
{
public class Program
{
static void Main(string[] args)
{
String host = "http://localhost:8080/OpenKM";
String username = "okmAdmin";
String password = "admin";
OKMWebservice ws = OKMWebservicesFactory.newInstance(host, username, password);
try
{
// Version history has version 1.3,1.2,1.1 and 1.0
ws.purgeVersionHistory("/okm:root/logo.png");
// Version history has only version 1.3
} catch (Exception e) {
System.Console.WriteLine(e.ToString());
}
}
}
}
getVersionHistorySize
Description:
Method | Return values | Description |
---|---|---|
getVersionHistorySize(String docId) |
long |
Returns the sum in bytes of all documents into documents history. |
Example:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using com.openkm.sdk4csharp;
namespace OKMRest
{
public class Program
{
static void Main(string[] args)
{
String host = "http://localhost:8080/OpenKM";
String username = "okmAdmin";
String password = "admin";
OKMWebservice ws = OKMWebservicesFactory.newInstance(host, username, password);
try
{
String[] UNITS = new String[] { "B", "KB", "MB", "GB", "TB", "PB", "EB" };
long bytes = ws.getVersionHistorySize("/okm:root/logo.png");
String value = "";
for (int i = 6; i > 0; i--)
{
double step = Math.Pow(1024, i);
if (bytes > step)
value = String.Format(Locale.ROOT, "%3.1f %s", bytes / step, UNITS[i]);
}
if (value.Equals(""))
{
value = bytes.ToString() + " " + UNITS[0];
}
System.Console.WriteLine(value);
} catch (Exception e) {
System.Console.WriteLine(e.ToString());
}
}
}
}
isLocked
Description:
Method | Return values | Description |
---|---|---|
isLocked(String docId) |
Boolean |
Returns a boolean that indicates if the node is a document or not. |
Example:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using com.openkm.sdk4csharp;
namespace OKMRest
{
public class Program
{
static void Main(string[] args)
{
String host = "http://localhost:8080/OpenKM";
String username = "okmAdmin";
String password = "admin";
OKMWebservice ws = OKMWebservicesFactory.newInstance(host, username, password);
try
{
// Return true
ws.isValidDocument("/okm:root/logo.png");
// Return false
ws.isValidDocument("/okm:root");
} catch (Exception e) {
System.Console.WriteLine(e.ToString());
}
}
}
}
getDocumentPath
Description:
Method | Return values | Description |
---|---|---|
getDocumentPath(String uuid) |
String |
Converts a document UUID to document path. |
Example:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using com.openkm.sdk4csharp;
namespace OKMRest
{
public class Program
{
static void Main(string[] args)
{
String host = "http://localhost:8080/OpenKM";
String username = "okmAdmin";
String password = "admin";
OKMWebservice ws = OKMWebservicesFactory.newInstance(host, username, password);
try
{
System.Console.WriteLine(ws.getDocumentPath("e339f14b-4d3a-489c-91d3-05e4575709d2"));
} catch (Exception e) {
System.Console.WriteLine(e.ToString());
}
}
}
}
isValidDocument
Description:
Method | Return values | Description |
---|---|---|
isValidDocument(String docId) |
Boolean |
Returns a boolean that indicates if the node is a document or not. |
Parameters: |
Example:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using com.openkm.sdk4csharp;
namespace OKMRest
{
public class Program
{
static void Main(string[] args)
{
String host = "http://localhost:8080/OpenKM";
String username = "okmAdmin";
String password = "admin";
OKMWebservice ws = OKMWebservicesFactory.newInstance(host, username, password);
try
{
// Return true
ws.isValidDocument("/okm:root/logo.png");
// Return false
ws.isValidDocument("/okm:root");
} catch (Exception e) {
System.Console.WriteLine(e.ToString());
}
}
}
}
extendedDocumentCopy
Description:
Method | Return values | Description |
---|---|---|
extendedDocumentCopy(String docId, String dstId, String name, boolean categories, boolean keywords, |
void |
Copies a document with associated data into a folder or record. |
The values of the dstId parameter should be a folder or record UUID or path. When parameter newName value is null, the document will preserve the same name. By default, only the binary data and the security grants, the metadata, keywords, etc. of the document are not copied. Additional:
|
Example:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using com.openkm.sdk4csharp;
namespace OKMRest
{
public class Program
{
static void Main(string[] args)
{
String host = "http://localhost:8080/OpenKM";
String username = "okmAdmin";
String password = "admin";
OKMWebservice ws = OKMWebservicesFactory.newInstance(host, username, password);
try
{
ws.extendedDocumnetCopy("/okm:root/logo.png", "/okm:root/tmp", null, true, true, true, true, true);
} catch (Exception e) {
System.Console.WriteLine(e.ToString());
}
}
}
}