I'm going to convert some sites to Umbraco and I intend to create a function that loops through for instance a product table, and put the content into a node in Umbraco. Done by user-control or some seperat .aspx file.
My question is : How do I take an image from the old site - lets say "http://www.website.com/images/myimage.jpg" - and save it in an upload-datatype?
I found this code for saving image - but I guess that won't make Umbraco define where it's archived :(
Dim client As New WebClient
Dim strURL As String = "http://www.website.com/images/myimage.jpg"
Dim strFilename As String = Server.MapPath("myimage.jpg")
client.DownloadFile(strURL, strFilename)
The files you upload with the Upload datatype are stored in /media/<property id of current upload field/file.ext. However, there's no harm in adding them to a /media/products/ folder or something similar if there are no naming conflicts. So once you download the image you can simply set the value of the upload field to the path of your file.
You would do this using the Document API. In C# something like:
Document d = new Document(1234); d.getProperty("yourUploadField").Value = "/media/products/" + yourFileName; d.Publish(); umbraco.library.UpdateDocumentCache(d.id);
Note if you then upload a new file manually in the UI it will then store the new file in the proper /media/.../ location, but again there's no harm either way.
Also, you should look into CMSImport as it can probably help you out here and save you from writing any code :) It can handle importing from DB's and into many fields like upload and media pickers.
Put external image into Upload-datatype
Hi
I'm going to convert some sites to Umbraco and I intend to create a function that loops through for instance a product table, and put the content into a node in Umbraco. Done by user-control or some seperat .aspx file.
My question is : How do I take an image from the old site - lets say "http://www.website.com/images/myimage.jpg" - and save it in an upload-datatype?
I found this code for saving image - but I guess that won't make Umbraco define where it's archived :(
.... Anyone ? :)
Hi Ulrik,
The files you upload with the Upload datatype are stored in /media/<property id of current upload field/file.ext. However, there's no harm in adding them to a /media/products/ folder or something similar if there are no naming conflicts. So once you download the image you can simply set the value of the upload field to the path of your file.
You would do this using the Document API. In C# something like:
Note if you then upload a new file manually in the UI it will then store the new file in the proper /media/.../ location, but again there's no harm either way.
Also, you should look into CMSImport as it can probably help you out here and save you from writing any code :) It can handle importing from DB's and into many fields like upload and media pickers.
-Tom
is working on a reply...