Opening an attachment from created PDF doesn't work

I am creating a PDF and attaching some files to to. When I open the PDF and click on the file, I get this error message:

There was a problem reading this document (135).

This is the code I’m using to attach the file:

Attachment attachment = new Attachment();
attachment.AttachedFileName = “MyFile.xml”;
attachment.AttachedFileType = “text/plain”;
attachment.AttachmentType = AttachmentType.File;
attachment.FileIconType = FileIconType.PaperClip;
section.Paragraphs.Add( attachment );

Am I doing something wrong?

Thanks.

Hi LSI_Josh,

I tested the code above and got an expected pdf document.

Please be sure that you are using the latest version of Aspose.Pdf for avoiding unexpected errors.

[My codes]

Pdf pdf1 = new Pdf();
Aspose.Pdf.Section sec = pdf1.Sections.Add();
Attachment attachment = new Attachment();
attachment.AttachedFileName = @"E:\NeedToTest\PDF\9.26\Settlement Document.xml";
attachment.AttachedFileType = "text/plain";
attachment.AttachmentType = AttachmentType.File;
attachment.FileIconType = FileIconType.PaperClip;
sec.Paragraphs.Add( attachment );
pdf1.Save("AttachmentTest.pdf");

Best regards,

I just installed version 3.1.7.1 and created a test page, and it’s still not working. Here is the exact code behind. The html is default.

using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;

using Aspose.Pdf;

public partial class Test : System.Web.UI.Page
{
protected void Page_Load( object sender, EventArgs e )
{
Pdf pdf = new Pdf();
Section section = pdf.Sections.Add();

Attachment attachment = new Attachment();
attachment.AttachedFileName = @“C:\Workspaces\Order Request\Order Request\Root\LSI.Web.WebPages.OrderRequest\Temp\ad1fb881-7690-4acd-8ac1-d2a55e1e7cd8.xml”;
attachment.AttachedFileType = “text/plain”;
attachment.AttachmentType = AttachmentType.File;
attachment.FileIconType = FileIconType.PaperClip;

section.Paragraphs.Add( attachment );

pdf.Save( “Test.pdf”, SaveType.OpenInAcrobat, Response );
}
}


Do you think it may have something to do with the actual file? I can go to that location and open it up just fine.

Thanks.

Dear sir,

I have reproduced the same error after checking carefully about the codes and result documents. We will try to fix it up and reply to you soon.

Best regards,

Thanks you.

This doesn’t seem to happen when using a windows app, only with a web app.
I created a test windows app that worked as expected.

Do you have a rough estimate on how long it will be for the fix?

Thanks again.

I tested your code in Windows and web app and both have the same error. But when I changed the following line:

attachment.AttachedFileType = "xml";

then it works.

On the web page, I've been using the content-type of the file, rather than just the name of the extenstion. If I just use the extension, it works fine.

I read somewhere, either in intellisense or the document chm file, that it's the content type, or mime type, which I would get directly when a file is uploaded.

You may want to make that more clear on the docs.

One other issue I have is, you need to specifiy the file name, which gets a file when the pdf is created. The files I have are saved with just a guid for the name, and no extension. When the pdf is opened, it says it can't open that type due to security. How I've been able to fix this is, copy the file to a new name with the correct extension, then use that file. This is kind of a pain. Would you guys be able to have a byte array attached directly instead of a file location? Then you could just name the file whatever you like.

Thanks.

I will try to support the feature you want. I think it is not difficult. I hope it can be available next month.

Thanks. I’ll be looking forward to the feature.