public function storeDocument($filePath)
    {
        if (empty($this->ID)) {
            user_error("Document must be written to database before it can store documents", E_USER_ERROR);
        }

        // calculate all the path to copy the file to
        $fromFilename = basename($filePath);
        $toFilename = $this->ID. '~' . $fromFilename; //add the docID to the start of the Filename
        $toFolder = DMS::inst()->getStorageFolder($this->ID);
        $toPath = DMS::inst()->getStoragePath() . DIRECTORY_SEPARATOR . $toFolder . DIRECTORY_SEPARATOR . $toFilename;

        DMS::inst()->createStorageFolder(DMS::inst()->getStoragePath() . DIRECTORY_SEPARATOR . $toFolder);

        //copy the file into place
        $fromPath = BASE_PATH . DIRECTORY_SEPARATOR . $filePath;

        //version the existing file (copy it to a new "very specific" filename
        if (DMSDocument_versions::$enable_versions) {
            DMSDocument_versions::create_version($this);
        } else {    //otherwise delete the old document file
            $oldPath = $this->getFullPath();
            if (file_exists($oldPath)) {
                unlink($oldPath);
            }
        }

        copy($fromPath, $toPath);   //this will overwrite the existing file (if present)

        //write the filename of the stored document
        $this->Filename = $toFilename;
        $this->Folder = strval($toFolder);

        $extension = pathinfo($this->Filename, PATHINFO_EXTENSION);

        if (empty($this->Title)) {
            // don't overwrite existing document titles
            $this->Title = basename($filePath, '.'.$extension);
        }

        $this->write();

        return $this;
    }