Best Practices
General > Best Practices > Adding Functionality To The Media Library View modes: 
User avatar
Member
Member
olevin-merlenorman - 10/28/2009 5:19:47 PM
   
Adding Functionality To The Media Library
Hi,

1) I need to be able to add a search box just for a specific media library so when they search keywords it will bring back all files that are related to that keyword. I have not been able to figure out how to do this with the smart search.

2) Also I need to be able to add an option when view a file from the media library to email this file to someone else. Is this possible?

Do these changes require editing the Kentico source code or is there another way?

Any help is appreciated. Thanks.

Oran

User avatar
Kentico Developer
Kentico Developer
kentico_helenag - 11/3/2009 7:58:35 AM
   
RE:Adding Functionality To The Media Library
Hi Oran,

1) regrettably, we do not support searching in media library in current version of Kentico CMS. However, we plan to add this feature to one of next versions.

Nowadays, you would need to develop the search functionality for media library by yourself. Data of Media library files are in Media_File table in database.

2) You may use API to send e-mails with attachment. Sample code is:
//new EmailMessage
EmailMessage msg = new EmailMessage();

//set From
msg.From = "userfrom@domain.com"; // use valid e-mail

//set Recipients
msg.Recipients = "userto@domain.cz"; // use valid e-mail

//set Subject
msg.Subject = "attachment test";

//set Body
msg.Body = "body email text";

//new AttachmentManager
AttachmentManager am = new AttachmentManager();

//new attachmentGuid
Guid attachmentGUID = new Guid("0de95d34-67a7-4285-ae65-5ca5bfc7f0b7");

//set attachmentName
String attachmentName = "pdfTest.pdf";

//new MemoryStream
MemoryStream ms = new MemoryStream(am.GetFile(attachmentGUID, CMS.CMSHelper.CMSContext.CurrentSiteName.ToString()));

//new Attachment
Attachment mailAttachment = new Attachment(ms, attachmentName, "application/pdf");

//add attachment to message
msg.Attachments.Add(mailAttachment);

CMS.EmailEngine.EmailSender.SendEmail(msg); // uses global smtp settings
//CMS.EmailEngine.EmailSender.SendEmail(CMS.CMSHelper.CMSContext.CurrentSiteName, msg); //uses local smtp settings

API Reference is here: http://devnet.kentico.com/downloads/kenticocms_api.zip

Best regards,
Helena Grulichova

User avatar
Member
Member
olevin-merlenorman - 11/3/2009 10:56:44 AM
   
RE:Adding Functionality To The Media Library
Thanks for the reply!

I will try out your suggestions.

Oran

User avatar
Member
Member
Jenks - 8/3/2010 12:14:49 AM
   
RE:Adding Functionality To The Media Library
I am getting an exception "Exception Details: System.ArgumentNullException: Buffer cannot be null. Parameter name: buffer"

in the line
MemoryStream ms = new MemoryStream(am.GetFile(attachmentGUID, CMS.CMSHelper.CMSContext.CurrentSiteName.ToString()));

Am i missing something ?

User avatar
Kentico Developer
Kentico Developer
kentico_helenag - 8/6/2010 7:31:08 AM
   
RE:Adding Functionality To The Media Library
Hello,

could you please debug the solution? Especially, if it founds the file for the attachment?

Best regards,
Helena Grulichova