public static void HandleDoUploadFile(FileTransferChunk command, Networking.Client client) { try { if (CanceledFileTransfers.ContainsKey(command.Id)) { return; } if (command.Chunk.Offset == 0 && File.Exists(command.FilePath)) { NativeMethods.DeleteFile(command.FilePath); // delete existing file } using (var destFile = new FileSplit(command.FilePath, FileAccess.Write)) { destFile.WriteChunk(command.Chunk); } } catch (Exception) { CanceledFileTransfers.Add(command.Id, "error"); client.Send(new FileTransferCancel { Id = command.Id, Reason = "Error writing file" }); } }