Try our conversational search powered by Generative AI!

retrieving pdf media not as an encoded string

Vote:
 

Hi guys,

My client can upload Pdf's in the media library. Ofcourse this is saved as a Blob on disk and the name on disk is encoded in for example blob/jkfj2kl39erkjweklfjdklf/dfkjsdfkljsdfkldfj83.pdf

Now we have a functionality that the pdf's can be emailed using a form on a page. Now i can fetch this blob programmatically as so and attach this to an email.

List attachments = new List();
ContentReference cr = new ContentReference(mediaID);
                    var media = contentLoader.Get(cr);
                    if (media != null)
                    {
                        string filePath = string.Empty;
                        var fileBlob = media.BinaryData as FileBlob;
                        if (fileBlob != null)
                        {
                            filePath = fileBlob.FilePath;                           
                            attachments.Add(new Attachment(filePath));
                        }
                    }             

However the pdf name is not nice and descriptive if you receive such a pdf. Are there alternatives on how i can sent the pdf in a more descriptive manner?

#121981
May 22, 2015 15:20
Vote:
 

Instead of:

attachments.Add(new Attachment(filePath));

Try this:

attachments.Add(new Attachment(fileBlob.OpenRead(), media.Name));
#121982
May 22, 2015 15:54
Vote:
 

Arghh.. forgot to check the overloads... thanks Dejan.. once again to the rescue..

#121984
May 22, 2015 16:18
This thread is locked and should be used for reference only. Please use the Episerver CMS 7 and earlier versions forum to open new discussions.
* You are NOT allowed to include any hyperlinks in the post because your account hasn't associated to your company. User profile should be updated.