How to upload images programmatically into a upload property in umbraco 7 back office content page
I want to add a image to upload property in a content page programmatically when submitting, how can i do it using contentservice, i can add values to textstring property using setValue but how to do it for a image? Thanks
Probably a little late, but for anyone else who stumbles on this question looking for an answer.
If you're trying to SetValue of a FileUpload property from the Content Service. Here's how I did it.
This snippet assumes you've already created a new content item with the content service named node. You'll have to add the URL of the file you want to download and the property alias you want to upload the image to.
string imageUrl = "{URL OF FILE YOU WANT SAVED TO UPLOAD}"
if (!string.IsNullOrEmpty(imageUrl))
{
// Stream File from URL
var request = WebRequest.Create(imageUrl);
var webResponse = request.GetResponse();
var responseStream = webResponse.GetResponseStream();
IContentTypeBaseServiceProvider contentTypeBaseServiceProvider = Services.ContentTypeBaseServices;
// Get File Name from Url
int lastIndex = imageUrl.LastIndexOf("/") + 1;
string filename = imageUrl.Substring(lastIndex, imageUrl.Length - lastIndex);
if (responseStream != null)
{
node.SetValue(contentTypeBaseServiceProvider, "{property alias}", filename, responseStream);
}
}
How to upload images programmatically into a upload property in umbraco 7 back office content page
I want to add a image to upload property in a content page programmatically when submitting, how can i do it using contentservice, i can add values to textstring property using setValue but how to do it for a image? Thanks
Here you have a code snippet. It assumes the file is already uploaded to the server
Dave
I think he asked for a solution to set the value of the content "fileUpload" programmatically. I'm looking for it too.
Tried node.SetValue("fileUpload", mediaItem);
didnt work.
Probably a little late, but for anyone else who stumbles on this question looking for an answer.
If you're trying to SetValue of a FileUpload property from the Content Service. Here's how I did it.
This snippet assumes you've already created a new content item with the content service named node. You'll have to add the URL of the file you want to download and the property alias you want to upload the image to.
is working on a reply...