Created
January 22, 2018 08:14
-
-
Save hermanussen/58da78cfab0db2a4e7d91868cb80d06d to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| /// <summary> | |
| /// Imports an image into the root of the Sitecore media library | |
| /// </summary> | |
| /// <param name="sampleImage"></param> | |
| public static void ImportImage(string sampleImage) | |
| { | |
| FileInfo imageFile = new FileInfo(sampleImage); | |
| Item parentItem = Sitecore.Context.Database.GetItem("/sitecore/media library"); | |
| var mediaCreatorOptions = new MediaCreatorOptions(); | |
| mediaCreatorOptions.Database = Sitecore.Context.Database; | |
| mediaCreatorOptions.Language = Sitecore.Context.Language; | |
| mediaCreatorOptions.Versioned = false; | |
| mediaCreatorOptions.Destination = string.Format("{0}/{1}", parentItem.Paths.FullPath, ItemUtil.ProposeValidItemName(Path.GetFileNameWithoutExtension(sampleImage))); | |
| mediaCreatorOptions.FileBased = Sitecore.Configuration.Settings.Media.UploadAsFiles; | |
| var mc = new MediaCreator(); | |
| mc.CreateFromFile(sampleImage, mediaCreatorOptions); | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment