/// <summary> /// Deletes the attachment from the API. /// </summary> /// <param name="api"></param> /// <returns></returns> public async Task DeleteAsync(ITimelineService api) { await api.PutJsonAsync("TimelineEventAttachment/Delete", new { AttachmentId = Id }); // Delete attachment from disk if it's there. var file = Path.Combine(api.CacheFolder, Name); if (api.FileExists(file)) { api.FileDelete(file); } }
/// <summary> /// Creates a new attachment and uploads the file in a single action, attaching it to the specified event. /// </summary> /// <param name="api">The API to create the attachment on.</param> /// <param name="eventId">The ID of the event the attachment is being attached to.</param> /// <param name="filename">The name of the attachment file on the local web server.</param> /// <param name="fileStream">A stream object containing the file contents.</param> /// <returns>The new attachment</returns> public static async Task <Attachment> CreateAndUploadAsync(ITimelineService api, string eventId, string filename, Stream fileStream) { var attachment = await CreateAsync(api, eventId, filename); string temp = Path.GetTempFileName(); try { await CopyFileFromStream(api, fileStream, temp); await attachment.UploadAsync(api, temp); } finally { if (api.FileExists(temp)) { api.FileDelete(temp); } } return(attachment); }