/// <summary> /// Deletes and de-indexes a page attachment. /// </summary> /// <param name="provider">The provider.</param> /// <param name="pageFullName">The page full name.</param> /// <param name="name">The attachment name.</param> /// <returns><c>true</c> if the attachment was deleted, <c>false</c> otherwise.</returns> public static bool DeletePageAttachment(IFilesStorageProviderV30 provider, string pageFullName, string name) { if (provider == null) { throw new ArgumentNullException("provider"); } if (pageFullName == null) { throw new ArgumentNullException("pageFullName"); } if (pageFullName.Length == 0) { throw new ArgumentException("Page Full Name cannot be empty", "pageFullName"); } if (name == null) { throw new ArgumentNullException("name"); } if (name.Length == 0) { throw new ArgumentException("Name cannot be empty", "name"); } PageInfo pageInfo = Pages.FindPage(pageFullName); if (pageInfo == null) { return(false); } PageContent page = Content.GetPageContent(pageInfo, false); if (page == null) { return(false); } bool done = provider.DeletePageAttachment(pageInfo, name); if (!done) { return(false); } SearchClass.UnindexPageAttachment(name, page); Host.Instance.OnAttachmentActivity(provider.GetType().FullName, name, pageFullName, null, FileActivity.AttachmentDeleted); return(true); }
/// <summary> /// Stores and indexes a page attachment. /// </summary> /// <param name="provider">The provider.</param> /// <param name="pageFullName">The page full name.</param> /// <param name="name">The attachment name.</param> /// <param name="source">The source stream.</param> /// <param name="overwrite"><c>true</c> to overwrite an existing attachment with the same name, <c>false</c> otherwise.</param> /// <returns><c>true</c> if the attachment was stored, <c>false</c> otherwise.</returns> public static bool StorePageAttachment(IFilesStorageProviderV30 provider, string pageFullName, string name, Stream source, bool overwrite) { if (provider == null) { throw new ArgumentNullException("provider"); } if (pageFullName == null) { throw new ArgumentNullException("pageFullName"); } if (pageFullName.Length == 0) { throw new ArgumentException("Page Full Name cannot be empty", "pageFullName"); } if (name == null) { throw new ArgumentNullException("name"); } if (name.Length == 0) { throw new ArgumentException("Name cannot be empty", "name"); } if (source == null) { throw new ArgumentNullException("source"); } PageInfo pageInfo = Pages.FindPage(pageFullName); if (pageInfo == null) { return(false); } PageContent page = Content.GetPageContent(pageInfo, false); if (page == null) { return(false); } bool done = provider.StorePageAttachment(pageInfo, name, source, overwrite); if (!done) { return(false); } if (overwrite) { SearchClass.UnindexPageAttachment(name, page); } // Index the attached file string tempDir = Path.Combine(Environment.GetEnvironmentVariable("TEMP"), Guid.NewGuid().ToString()); if (!Directory.Exists(tempDir)) { Directory.CreateDirectory(tempDir); } string tempFile = Path.Combine(tempDir, name); source.Seek(0, SeekOrigin.Begin); using (FileStream temp = File.Create(tempFile)) { source.CopyTo(temp); } SearchClass.IndexPageAttachment(name, tempFile, page); Directory.Delete(tempDir, true); Host.Instance.OnAttachmentActivity(provider.GetType().FullName, name, pageFullName, null, FileActivity.AttachmentUploaded); return(true); }