IContent myDoc = \\get or create ur Doc here
string tempFolder = umbraco.GlobalSettings.FullpathToRoot + "//temp//"; string linkToImage = "http://somewebsite.com/mypic.jpg";
if (!String.IsNullOrEmpty(linkToImage))
{
Uri imageUrl = new Uri(linkToImage);
string filename = Path.GetFileName(imageUrl.PathAndQuery);
webClient.DownloadFile(linkToImage, tempFolder + filename);
FileStream fs = new FileStream(tempFolder + filename, FileMode.Open);
myDoc.SetValue("anzeigeBild", filename, fs);
fs.Close();
Services.ContentService.SaveAndPublishWithStatus(myDoc);
foreach (FileInfo file in new DirectoryInfo(tempFolder).GetFiles()) file.Delete();
}
This worked for me. It was fast enough. Maybe there is a way to do this without saving the file to disk before creating a filestream. I just had to run this once, so this was fine for me.
Save into ImageCropper programmatically
I have links to pictures which need to be saved in an ImageCropper-Field.
Has anyone maybe done this before?
If I insert the Link the ImageCropper just points to it but cant resize it. Can anyone provide samplecode?
Thanks :)
Hellp NDDT,
I am not 100% sure I fully understand your question, what are you trying to achieve here?
When you say link, what type of datatype is this?
With some more details I am sure I can help or someone else with a few more details.
Thanks,
Warren
Its a Link in form of a String and I wanted to save the image (the link leads to) into an imagecropper. It works now.
I just had to create a FileStream-Object of the Image and I was able to just asign it to the property.
OK I am glad you solved your own problem then.
Maybe to help others who search or come across the same problem is to post a code snippet so others can benefit from it too.
Thanks,
Warren
Of Course ;)
This worked for me. It was fast enough. Maybe there is a way to do this without saving the file to disk before creating a filestream. I just had to run this once, so this was fine for me.
is working on a reply...