/// <summary> /// Processes a CheckFileInfo request /// </summary> /// <remarks> /// For full documentation on CheckFileInfo, see /// https://wopi.readthedocs.io/projects/wopirest/en/latest/files/CheckFileInfo.html /// </remarks> private void HandleCheckFileInfoRequest(HttpContext context, WopiRequest requestData) { if (!ValidateAccess(requestData, writeAccessRequired: false)) { ReturnInvalidToken(context.Response); return; } if (!File.Exists(requestData.FullPath)) { ReturnFileUnknown(context.Response); return; } try { FileInfo fileInfo = new FileInfo(requestData.FullPath); if (!fileInfo.Exists) { ReturnFileUnknown(context.Response); return; } // For more info on CheckFileInfoResponse fields, see // https://wopi.readthedocs.io/projects/wopirest/en/latest/files/CheckFileInfo.html#response CheckFileInfoResponse responseData = new CheckFileInfoResponse() { // required CheckFileInfo properties BaseFileName = Path.GetFileName(requestData.FullPath), OwnerId = "documentOwnerId", Size = (int)fileInfo.Length, Version = fileInfo.LastWriteTimeUtc.ToString("O" /* ISO 8601 DateTime format string */), // Using the file write time is an arbitrary choice. // optional CheckFileInfo properties BreadcrumbBrandName = "LocalStorage WOPI Host", BreadcrumbFolderName = fileInfo.Directory != null ? fileInfo.Directory.Name : "", BreadcrumbDocName = Path.GetFileNameWithoutExtension(requestData.FullPath), UserFriendlyName = "A WOPI User", SupportsLocks = true, SupportsUpdate = true, UserCanNotWriteRelative = true, /* Because this host does not support PutRelativeFile */ ReadOnly = fileInfo.IsReadOnly, UserCanWrite = !fileInfo.IsReadOnly, }; string jsonString = JsonConvert.SerializeObject(responseData); context.Response.Write(jsonString); ReturnSuccess(context.Response); } catch (UnauthorizedAccessException) { ReturnFileUnknown(context.Response); } }
/// <summary> /// Processes a CheckFileInfo request /// </summary> /// <remarks> /// For full documentation on CheckFileInfo, see https://wopi.readthedocs.org/en/latest/wopi/files/CheckFileInfo.html /// </remarks> private void HandleCheckFileInfoRequest(HttpContext context, WopiRequest requestData) { if (!ValidateAccess(requestData, writeAccessRequired: false)) { ReturnInvalidToken(context.Response); return; } if (!File.Exists(requestData.FullPath)) { ReturnFileUnknown(context.Response); return; } try { FileInfo fileInfo = new FileInfo(requestData.FullPath); if (!fileInfo.Exists) { ReturnFileUnknown(context.Response); return; } // For more info on CheckFileInfoResponse fields, see https://wopi.readthedocs.org/en/latest/wopi/files/CheckFileInfo.html#response CheckFileInfoResponse responseData = new CheckFileInfoResponse() { // required CheckFileInfo properties BaseFileName = Path.GetFileName(requestData.FullPath), OwnerId = "documentOwnerId", Size = (int)fileInfo.Length, Version = fileInfo.LastWriteTimeUtc.ToString("O" /* ISO 8601 DateTime format string */), // Using the file write time is an arbitrary choice. // optional CheckFileInfo properties BreadcrumbBrandName = "LocalStorage WOPI Host", BreadcrumbFolderName = fileInfo.Directory != null ? fileInfo.Directory.Name : "", BreadcrumbDocName = Path.GetFileNameWithoutExtension(requestData.FullPath), UserFriendlyName = "A WOPI User", SupportsLocks = true, SupportsUpdate = true, UserCanNotWriteRelative = true, /* Because this host does not support PutRelativeFile */ ReadOnly = fileInfo.IsReadOnly, UserCanWrite = !fileInfo.IsReadOnly, }; string jsonString = JsonConvert.SerializeObject(responseData); context.Response.Write(jsonString); ReturnSuccess(context.Response); } catch (UnauthorizedAccessException) { ReturnFileUnknown(context.Response); } }