Quantcast
Channel: Aspose.Pdf Product Family
Viewing all articles
Browse latest Browse all 3131

Not able to delete specific attached file.

$
0
0
Hi.

I am not able to delete specific attached file.

Ex : I have three attachments (File1, File2, File3) , I just want to delete File1.

My code snippet :

public void DeleteAttachments(string File)
        {
            int index = 1;
            bool found = false;
            foreach (FileSpecification fileSpecification in PdfDocument.EmbeddedFiles)
            {
                if (fileSpecification.Name.Equals(File))
                {
                    found = true;                   
                    break;
                }
                index++;
            }

            if (found)
            {
                if (PdfDocument.EmbeddedFiles.Count == 1)  
                {
                    PdfDocument.EmbeddedFiles.Delete();  // delete all attachments  (only one attachments)
                }
                else
                {
                    PdfDocument.EmbeddedFiles.Delete(index); // index does not work.
                }
            }
            else
            {
               throw error (" File not found.");
            }
        }

Any help would be appreciate!!!

Viewing all articles
Browse latest Browse all 3131

Trending Articles