Click or drag to resize

IFolderCreateFileAsync Method

IT Hit WebDAV Classes Reference
Creates new WebDAV file with the specified name in this folder.

Namespace:  ITHit.WebDAV.Server.Class1
Assembly:  ITHit.WebDAV.Server (in ITHit.WebDAV.Server.dll) Version: 13.3.13068
Syntax
Task<IFile> CreateFileAsync(
	string name,
	Stream content,
	string contentType,
	long totalFileSize
)

Parameters

name
Type: SystemString
Name of the file to create.
content
Type: System.IOStream
Stream to read the content of the file from.
contentType
Type: SystemString
Indicates the media type of the file.
totalFileSize
Type: SystemInt64
Size of file as it will be after all parts are uploaded. -1 if unknown (in case of chunked upload).

Return Value

Type: TaskIFile
New file instance created in this call.
Exceptions
ExceptionCondition
LockedExceptionThis folder was locked. Client did not provide the lock token.
NeedPrivilegesExceptionThe user doesn't have enough privileges.
InsufficientStorageExceptionQuota limit is reached.
DavExceptionIn other cases.
Remarks
You must create a file in your repository during this call. After calling this method Engine calls WriteAsync(Stream, String, Int64, Int64).
Examples

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;
}
Examples

The code below is part of 'WebDAVServer.FileSystemSynchronization.AspNetCore' C# & VB samples provided with the SDK.

C#
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;
}
See Also