How to copy a media file from one media library to another through api ??

Joy Basak asked on August 3, 2017 08:32

I have two sites lets say A and B .I want to copy a media file from Site A media Library and paste it on Site B's media library.Is there any way to do the same with API.I tried with these method but didn't get any solution.

                 MediaFileInfoProvider.ImportMediaFileInfo();
                 MediaFileInfoProvider.SetMediaFileInfo();

Recent Answers


Zach Perry answered on August 3, 2017 16:23 (last edited on August 3, 2017 16:26)

You would have to do something like this (untested), this moves the media file from one library to another, if you want to copy it, you might have to do MediaFileInfoProvider.CopyMediaFile(); first:

var siteALibrary = MediaLibraryInfoProvider.GetMediaLibraryInfo("Library Name", "Site Name");
        var siteBLibrary = MediaLibraryInfoProvider.GetMediaLibraryInfo("Library Name", "Site Name");

        var mediaFile = MediaFileInfoProvider.GetMediaFileInfo(siteALibrary.LibraryID, "File Path");
        mediaFile.FileLibraryID = siteBLibrary.LibraryID;
        mediaFile.FileSiteID = SiteInfoProvider.GetSiteID("Site B Name");
        mediaFile.Update(); //Not sure if this will update it, might have to do this:
        MediaFileInfoProvider.SetMediaFileInfo(mediaFile);
1 votesVote for this answer Mark as a Correct answer

Peter Mogilnitski answered on August 3, 2017 20:04 (last edited on August 3, 2017 21:04)

Do you want to export only one file or the whole library? If you need to do do it only once you can export the whole library

Site A and Site B are physically on one machine?

0 votesVote for this answer Mark as a Correct answer

   Please, sign in to be able to submit a new answer.