Skip to content

Commit e2ae1df

Browse files
authored
adopted documentation on how to create a new file or override an existing file
previous code was outdated and didn't work anymore in newer NC versions (possibly since NC 29) Signed-off-by: Ronny Bremer <rbremer@almanid.com>
1 parent 11d817b commit e2ae1df

File tree

1 file changed

+5
-6
lines changed

1 file changed

+5
-6
lines changed

developer_manual/basics/storage/filesystem.rst

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -81,14 +81,13 @@ All methods return a Folder object on which files and folders can be accessed, o
8181
try {
8282
try {
8383
$file = $userFolder->get('myfile.txt');
84+
85+
// the id can be accessed by $file->getId();
86+
$file->putContent($content);
8487
} catch(\OCP\Files\NotFoundException $e) {
85-
$userFolder->touch('myfile.txt');
86-
$file = $userFolder->get('myfile.txt');
88+
$userFolder->newFile('myfile.txt', $content);
8789
}
8890
89-
// the id can be accessed by $file->getId();
90-
$file->putContent($content);
91-
9291
} catch(\OCP\Files\NotPermittedException $e) {
9392
// you have to create this exception by yourself ;)
9493
throw new StorageException('Cant write to file');
@@ -163,4 +162,4 @@ The recommended way of adding your own mounts to the filesystem from an app is i
163162
and registering the provider using ``OCP\Files\Config\IMountProviderCollection::registerProvider``.
164163

165164
Once registered, your provider will be called every time the filesystem is being setup for a user and your mount provider
166-
can return a list of mounts to add for that user.
165+
can return a list of mounts to add for that user.

0 commit comments

Comments
 (0)