/// <summary> /// Attaches a file to a page on the server. /// </summary> /// <param name="attachmentInfo">AttachmentInfo instance containing data about the attachment.</param> private void AttachFile(object attachmentInfo) { AttachmentInfo info = (AttachmentInfo)attachmentInfo; string filePath = info.filePath; string docName = info.pageId; FileInfo fi = new FileInfo(filePath); FileStream fs = new FileStream(filePath, FileMode.Open); byte[] buffer = new byte[fi.Length]; fs.Read(buffer, 0, (int)fi.Length); fs.Close(); Attachment att = new Attachment(docName); att.fileName = Path.GetFileName(filePath); proxy.AddAttachment(token, 0, att, buffer); }
/// <summary> /// Adds a file as an attachment to a wiki page. /// </summary> /// <param name="docName">Wiki page name - SpaceName.PageName</param> /// <param name="filePath">The path to the uploaded file.</param> /// <returns>The result of the operation(Success - true/Failure - false).</returns> public bool AddAttachment(string docName, string filePath) { try { FileInfo fi = new FileInfo(filePath); FileStream fs = new FileStream(filePath, FileMode.Open); byte[] buffer = new byte[fi.Length]; fs.Read(buffer, 0, (int)fi.Length); fs.Close(); Attachment att = new Attachment(docName); att.fileName = Path.GetFileName(filePath); proxy.AddAttachment(token, 0, att, buffer); return true; } catch (IOException ex) { Log.Exception(ex); return false; } }