Namespace: ITHit.WebDAV.Server.Class1
Task<IFile> CreateFileAsync( string name, Stream content, string contentType, long totalFileSize )
Exception | Condition |
---|---|
LockedException | This folder was locked. Client did not provide the lock token. |
NeedPrivilegesException | The user doesn't have enough privileges. |
InsufficientStorageException | Quota limit is reached. |
DavException | In other cases. |
The code below is part of 'WebDAVServer.FileSystemStorage.AspNet' C# & VB samples provided with the SDK.
public async Task<IFile> CreateFileAsync(string name, Stream content, string contentType, long totalFileSize) { await RequireHasTokenAsync(); string fileName = System.IO.Path.Combine(fileSystemInfo.FullName, name); using (FileStream stream = new FileStream(fileName, FileMode.CreateNew)) { } DavFile file = (DavFile)await context.GetHierarchyItemAsync(Path + EncodeUtil.EncodeUrlPart(name)); // write file content await file.WriteInternalAsync(content, contentType, 0, totalFileSize); await context.socketService.NotifyCreatedAsync(System.IO.Path.Combine(Path, EncodeUtil.EncodeUrlPart(name)), GetWebSocketID()); return file; }
The code below is part of 'WebDAVServer.FileSystemSynchronization.AspNetCore' C# & VB samples provided with the SDK.
public async Task<IFile> CreateFileAsync(string name, Stream content, string contentType, long totalFileSize) { await RequireHasTokenAsync(); string fileName = System.IO.Path.Combine(fileSystemInfo.FullName, name); // delete hidden file if (File.Exists(fileName) && File.GetAttributes(fileName).HasFlag(FileAttributes.Hidden)) { File.Delete(fileName); } await using (FileStream stream = new FileStream(fileName, FileMode.CreateNew)) { } DavFile file = (DavFile)await context.GetHierarchyItemAsync(Path + EncodeUtil.EncodeUrlPart(name)); // write file content await file.WriteInternalAsync(content, contentType, 0, totalFileSize); await context.socketService.NotifyCreatedAsync(System.IO.Path.Combine(Path, EncodeUtil.EncodeUrlPart(name)), GetWebSocketID()); return file; }