I have created the following with reference to a tutorial.
Following is my controller
[GuiPlugIn( Area = PlugInArea.AdminMenu, Url = "/ImportMediaAssets", DisplayName = "Import media assets")] public class ImportMediaAssetsController : Controller { public ActionResult Index() { var model = new ImportMediaAssetModel(); return View(model); } public ActionResult BeginUpload(ImportMediaAssetModel postedModel) { var directory = new DirectoryInfo(postedModel.SourcePath); if (postedModel.Destination == ImportMediaAssetModel.GlobalAssetFolder) { CreateAndUploadFilesAndFolders(directory, ContentReference.SiteBlockFolder, postedModel.OverrideExistingItems); } return View(directory); } private void CreateAndUploadFilesAndFolders(DirectoryInfo dir, ContentReference parentLink, bool overrideFiles) { foreach (var childFile in dir.GetFiles()) { if (fileCount >= 1) break; UploadFile(childFile, parentLink, overrideFiles); } foreach (var childDir in dir.GetDirectories()) { var storedFolder = _contentRepository.Service.GetBySegment(parentLink, childDir.Name, LanguageSelector.AutoDetect()) as ContentFolder; if (storedFolder != null) { CreateAndUploadFilesAndFolders(childDir, storedFolder.ContentLink, overrideFiles); } else { var contentFolder = _contentRepository.Service.GetDefault<>ContentAssetFolder>(parentLink); contentFolder.Name = childDir.Name; var contentAssetsFolderReference = _contentRepository.Service.Save(contentFolder, SaveAction.Publish); CreateAndUploadFilesAndFolders(childDir, contentAssetsFolderReference, overrideFiles); } } } private void UploadFile(FileInfo file, ContentReference parentLink, bool overrideFiles) { //Get a suitable MediaData type from extension var extension = GetExtension(file.Name); var mediaType = _contentMediaResolver.Service.GetFirstMatching(extension); var contentType = _contentTypeRepository.Service.Load(mediaType); // Try get existing media var storedMedia = _contentRepository.Service.GetBySegment(parentLink, file.Name, LanguageSelector.AutoDetect()) as IContentMedia; if (!overrideFiles && storedMedia != null) return; //Get a new empty file data var media = _contentRepository.Service.GetDefault<>IContentMedia>(parentLink, contentType.ID); var container = media.BinaryDataContainer; var blob = _blobFactory.Service.CreateBlob(container, extension); using (var fs = new FileStream(file.FullName, FileMode.Open)) { blob.Write(fs); } media.BinaryData = blob; media.Name = file.Name; _contentRepository.Service.Save(media, SaveAction.Publish, AccessLevel.NoAccess); } }And this is my model :>>
public class ImportMediaAssetModel { public string Destination { get; set; } public string SourcePath { get; set; } public bool OverrideExistingItems { get; set; } }Please have a look and tell me how will it work.
From which class is object "_contentRepository" referred
Also what the namespaces for class IContentMedia, ContentAssetFolder etc
I have created the following with reference to a tutorial.
Following is my controller