Portal Engine Questions on portal engine and web parts.
Version 4.x > Portal Engine > Custom mediaFileUploader View modes: 
User avatar
Member
Member
Yalın - 12/3/2009 12:40:37 PM
   
Custom mediaFileUploader
I'm customizing the mediaFileUploader to achieve a simplified editor interface.

I've copied the existing files and made a mediaFileUpload_custom webpart.

Files effected...

\CMSWebParts\MediaLibrary\MediaFileUploaderCustom.ascx
\CMSWebParts\MediaLibrary\MediaFileUploaderCustom.ascx.cs
\CMSModules\MediaLibrary\Controls\LiveControls\MediaFileUploaderCustom.ascx
\CMSModules\MediaLibrary\Controls\LiveControls\MediaFileUploaderCustom.ascx.cs

I have been able to make the following customizations...

The control only shows in Edit Mode as opposed to being accessible through the end-user.

The control adds the file uploaded to the library with a subdirectory named after the page.

WHAT I CAN'T Figure out...

To control the naming of the file saved to the database. I'd like it to have 2-3 instances of this control, when some editor uses them, I want the resulting filenames saved in the library to be static instead of being named as the original uploaded file. I can't figure out how to do this.

Thank you.

User avatar
Kentico Consulting
Kentico Consulting
kentico_borisp - 12/4/2009 4:42:20 AM
   
RE:Custom mediaFileUploader
Hello,

If I understand you correctly, you can change the title of the file (the tittle, which is displayed in the media library) by changing the property FileTitle:

CMS.MediaLibrary ► MediaFileInfo ► FileTitle

Best regards,
Boris Pocatko

User avatar
Member
Member
Yalın - 12/4/2009 9:40:35 AM
   
RE:Custom mediaFileUploader
What is the CS Code to do that?

I think the crux takes place here...

\CMSModules\MediaLibrary\Controls\LiveControls\MediaFileUploader[Custom].ascx.cs

if (mli != null)
{
try
{
// Create new Media file
fileUploader.SaveAs(fileUploader.PostedFile.FileName);

MediaFileInfo mfi = new MediaFileInfo(fileUploader.PostedFile, this.LibraryID, CMSContext.CurrentPageInfo.DocumentNamePath);

// Save record to the database
MediaFileInfoProvider.SetMediaFileInfo(mfi);
...

How should I change this code?

Thank you

User avatar
Member
Member
Yalın - 12/7/2009 1:04:00 PM
   
RE:Custom mediaFileUploader
I would like an answer for this question, please?

User avatar
Kentico Consulting
Kentico Consulting
kentico_borisp - 12/8/2009 9:44:54 AM
   
RE:Custom mediaFileUploader
Hello,

I am still confused what you are trying to accomplish.

The file name has to be unique, as there can be only one file with a certain name in one folder. Could you please describe in more detail what do you try to accomplish? The following confuses me:

"I'd like it to have 2-3 instances of this control, when some editor uses them, I want the resulting filenames saved in the library to be static instead of being named as the original uploaded file. I can't figure out how to do this."

Please note that the file name is used for locating the file on the file system, so it needs to be the same as the file name.

FYI: The forums are currently intended for Kentico community. Although we monitor them time to time, we cannot guarantee a timely response. If you need a help with Kentico CMS, please feel free to send your message to support@kentico.com.

Best regards,
Boris Pocatko

User avatar
Member
Member
Yalın - 12/8/2009 11:57:40 AM
   
RE:Custom mediaFileUploader
Thank you for your response.

I will attempt to make it clear, here's a the simplified use case scenario.

Template will include 2 instances of this custom media uploader control which will result in 2 browse buttons to display on the CMS Desk>Page Tab, where the page editor can click either buttons and choose and image file. The first instance should save the file in the specified librar with the name "Left_image.jpg" and the 2nd instance should save the selected image file as "Right_image.jpg" and not as the filename selected, so that further programming could access the correct file, elsewhere in the page.

(I have already figured out how to make the control NOT show in the live page, as the control isn't intended for end users.)

User avatar
Kentico Developer
Kentico Developer
kentico_ondrejv - 12/15/2009 5:57:22 AM
   
RE:Custom mediaFileUploader
Hello,

You can achieve your aim by amending the media file uploader control (in fact, you will need to have 2 different controls/webparts for that) to the page. It will upload selected file, and after that it will move it with another name. You would add following code just after the media file creation (around line 210):

// rename file
string newPath = null;
int slahIndex = mfi.FilePath.LastIndexOf('/');
if (slahIndex > 0)
{
newPath = mfi.FilePath.Remove(slahIndex) + "/newFileName.jpg";
}
else
{
newPath = "newFileName.jpg";
}
// move file under new name
MediaFileInfoProvider.MoveMediaFile(CMSContext.CurrentSiteName, LibraryID, mfi.FilePath, newPath, false);


Please note that the example above is only a draft how it could look like, you might need to add extension checking etc.

Best regards
Ondrej Vasil