File upload in web part field?

ben ben asked on September 23, 2015 17:41

I'm currently trying to allow a user to upload a file to a web part but I don't see any way to do so.

If I set the Data type to text I can have them select a file but that's not exactly what I want.

Looking at this question it seems like I should have an "Upload File" option in the form control dropdown (or in the more items menu) but I don't. Is it possible that I need to install another part of Kentico? I unchecked every module during install besides the Windows services one.

If I open the select form control modal and change the form control type to "uploader" there are no results.

Recent Answers


Brenden Kehren answered on September 23, 2015 18:34

Technically you don't upload documents or files to a web part. You'd upload them to a page type or a control within a webpart. So you might clarify a bit more what you're actual setup is. Are you trying to create a property in the webpart that is a "file upload"?

0 votesVote for this answer Mark as a Correct answer

ben ben answered on September 23, 2015 19:09

Brenden - Yes. My web part has a field/property called "FileUpload" which is where I'm trying to upload the file to.

(Ignore the misspellings in this screenshot. Just an example of the area I'm working in)

Image Text

0 votesVote for this answer Mark as a Correct answer

Joshua Adams answered on September 23, 2015 19:26

What are you going to use the file for? Depending on the reason, it may be better to store the file in the folder structure of the site, and then have the property on the webpart just a file selector or url selector that links to the file. Let us know what you intend on doing with the file and that may help us give you a better answer.

0 votesVote for this answer Mark as a Correct answer

ben ben answered on September 23, 2015 19:30 (last edited on September 23, 2015 19:30)

Joshua -

It's going to be an XML file that then gets processed on the back end. Storing the file as part of the folder structure makes it publicly accessible, right? Assuming you have the URL of course.

I've gotten it to work as an attachment on the page but I'm querying for the XML file by name which I'd prefer not to do.

0 votesVote for this answer Mark as a Correct answer

Brenden Kehren answered on September 23, 2015 20:22

What you could use is a file system selector form control. This will allow you to get the files within the file system. You could then set a default path and simply place files in there. Yes the files would be publicly available if they know the URL. Other option would be to create your own form control which you can then upload a document to the database and store the xml in the database vs. the file system. I don't believe there is one for this already.

1 votesVote for this answer Mark as a Correct answer

Jeroen Fürst answered on September 23, 2015 21:20

Have you considered using a text area field and simply paste the xml content from the file into it? In the code behind you can easily use the xml and do whatever you want with it :) good luck!

2 votesVote for this answer Mark as a Correct answer

Maarten van den Hooven answered on September 23, 2015 21:57

Hi Ben,

It depends a lot of what you want, but if you want to upload an XML and do directly something with it, then I agree with Brenden to build an custom form control.

And is it necesary to upload the XML? Why not directly use it in memory. Like described here in Reading the xml file in server without saving it.

You can also save the file on an temp location and then save the XML in de database like described here : Saving an XML file using Fileupload. Don't forget to remove the temp file.

See here the documentation how to begin : Example - Developing custom form controls

Good luck and if you get stuck you know where to find the answers :-)

If this answer helped you, please vote for my answer :-)

0 votesVote for this answer Mark as a Correct answer

Maarten van den Hooven answered on September 25, 2015 19:29

Hi Ben, Did you found the right answer, or are you still running into a problems. Please let us known.

0 votesVote for this answer Mark as a Correct answer

   Please, sign in to be able to submit a new answer.