Skip to content

CtxRelPath()

ts
function CtxRelPath(): string;

Returns the event-context relative path — the VFS-relative path of the file that caused the event triggering this script. Returns an empty string "" for events that are not associated with a specific file (e.g. login or logout events).

Why this function exists — and why it matters

IMPORTANT

Always use CtxRelPath() when your script needs to know which file the client is working on. Never rely on Session.GetRelPath() or Session.GetAbsPath() for this purpose.

Syncplify Server! runs event-handler scripts asynchronously and concurrently. By the time a script begins executing, or at any point during its execution, the session's internal "current path" cursor may have already advanced to a different file — because the client has kept working. Session.GetRelPath() and Session.GetAbsPath() reflect the session's live, current-cursor state, not the file that triggered the event.

CtxRelPath() is different. The path is captured at the moment the event fires and frozen into the script's execution context. It never changes while the script runs, regardless of what the client does in the background. This makes it the only reliable way to reference the triggering file.

Concrete example of the race condition

t=0  Client uploads resume.pdf  →  AfterFileUpload fires, script starts running
t=1  Script calls Session.GetRelPath()
t=1  Meanwhile: client has already navigated to /inbox/ and uploaded report.xlsx
     Session.GetRelPath() returns /inbox/report.xlsx  ← WRONG FILE
t=1  CtxRelPath() returns /docs/resume.pdf            ← always correct

Return value

ScenarioReturn value
File-based event (upload, download, rename, delete, …)VFS-relative path, e.g. /docs/resume.pdf
Non-file event (login, logout, …)"" (empty string)

Example

ts
{
  var path = CtxRelPath();
  if (path === "") {
    Log("This event has no associated file path.");
    Exit();
  }
  Log("File that triggered this script: " + path);

  // Safe to use path with VFS operations:
  var vfs = GetCurrentVFS();
  var info = vfs.Stat(path);
  if (info) {
    Log("File size: " + info.Size);
  }
}

See also

  • EventHandler() — returns the name of the event that triggered this script
  • Session.GetRelPath() — session-wide cursor; not suitable for identifying the triggering file
  • Session.GetAbsPath() — session-wide absolute cursor; not suitable for identifying the triggering file