Portal Engine Questions on portal engine and web parts.
Version 6.x > Portal Engine > Automatic FileName generation on User Contribution View modes: 
User avatar
Member
Member
Oli Jeffery - 6/25/2012 9:59:59 AM
   
Automatic FileName generation on User Contribution
When I upload a file (doctype CMS.File) using the CMSDesk, it automatically names the Document, based on what the file uploaded is called, with no need for a separate FileName input.

Can this be reproduced via the User Contribution web part? That is, can FileName (and or DocumentName) be automatically generated using from the name of the file uploaded in this web part?

Many thanks, Oli.

User avatar
Member
Member
kentico_edwardh - 6/25/2012 12:01:30 PM
   
RE:Automatic FileName generation on User Contribution
Hello,

You should be able to get the file name of the uploaded document by using the code example below, which can also be found in the following file -~\CMSModules\Content\Controls\Attachments\FileUpload.ascx.cs


// Create new document
string fileName = Path.GetFileNameWithoutExtension(ucFileUpload.FileName);

node = TreeNode.New("CMS.File", tree);
node.DocumentCulture = CMSContext.PreferredCultureCode;
node.DocumentName = fileName;

// Load default values
FormHelper.LoadDefaultValues(node);

node.SetValue("FileDescription", "");
node.SetValue("FileName", fileName);
node.SetValue("FileAttachment", Guid.Empty);


Another approach would be to edit the field in the document type, and set the Document name source field to FileName for the field which is using the direct uploader.

Best Regards,
Edward Hillard