Copy files and folders between VPP folders
Have made a plugin that copy files and folders between 2 VPP folders that are of different type.
The code is pretty straight forward, and thinks its strange that the buildt in copy / paste from the explorer view from episerver don’t support this.
- [GuiPlugIn(
- Area = PlugInArea.AdminMenu,
- DisplayName = "Kopiere filer",
- Url = "~/Custom/AdminPages/CopyFiles.aspx")]
- public partial class CopyFiles : SystemPageBase
- {
- protected override void OnInit(EventArgs e)
- {
- base.OnInit(e);
- }
- protected void Start_Click(object sender, EventArgs e)
- {
- var source = System.Web.Hosting.HostingEnvironment.VirtualPathProvider.GetDirectory(CopyFrom.Text) as UnifiedDirectory;
- var target = System.Web.Hosting.HostingEnvironment.VirtualPathProvider.GetDirectory(CopyTo.Text) as UnifiedDirectory;
- StatusText.Text = DoCopy(source, target);
- }
- string DoCopy(UnifiedDirectory source, UnifiedDirectory target)
- {
- string result = "<dir><strong>"+source.Name+"</strong>";
- foreach (var fil in source.GetFiles())
- {
- string combined = Path.Combine(target.VirtualPath, fil.Name);
- var newFile = System.Web.Hosting.HostingEnvironment.VirtualPathProvider.GetFile(combined) as UnifiedFile;
- if (newFile == null)
- {
- result += "<div>Copy file " + fil.Name;
- fil.CopyTo(combined);
- newFile = System.Web.Hosting.HostingEnvironment.VirtualPathProvider.GetFile(combined) as UnifiedFile;
- if (fil.Summary != null)
- {
- foreach (var key in fil.Summary.Dictionary.Keys)
- {
- newFile.Summary.Dictionary[key] = fil.Summary.Dictionary[key];
- }
- newFile.Summary.SaveChanges();
- result += " update Summary";
- }
- result += "</div>";
- }
- else
- {
- result += "<div>File " + fil.Name+" exists</div>";
- }
- }
- foreach (var dir in source.GetDirectories())
- {
- string combined = Path.Combine(target.VirtualPath, dir.Name);
- var newDir = System.Web.Hosting.HostingEnvironment.VirtualPathProvider.GetDirectory(combined) as UnifiedDirectory;
- if (newDir == null)
- {
- newDir=target.CreateSubdirectory(dir.Name);
- }
- result += DoCopy(dir, newDir);
- }
- result += "</dir>";
- return result;
- }
- public override EPiServer.Security.AccessLevel RequiredAccess()
- {
- return AccessLevel.Edit;
- }
- public override AccessLevel QueryAccess()
- {
- PageData page = DataFactory.Instance.GetPage(PageReference.StartPage, LanguageSelector.MasterLanguage());
- if (page != null)
- {
- return page.QueryAccess();
- }
- return AccessLevel.Read;
- }
- protected override void OnPreInit(EventArgs e)
- {
- base.OnPreInit(e);
- this.MasterPageFile = ResolveUrlFromUI("MasterPages/EPiServerUI.master");
- }
- }
and have this litle front end file
- <%@ Page Language="C#" AutoEventWireup="true" CodeBehind="CopyFiles.aspx.cs" Inherits="Custom.AdminPages.CopyFiles" %>
- <asp:Content ContentPlaceHolderID="FullRegion" Runat="Server">
- <div>
- CopyFrom:<asp:TextBox id="CopyFrom" runat="server" /><br />
- CopyTo:<asp:TextBox id="CopyTo" runat="server" /><br />
- <asp:Button ID="Button1" Text="Start" runat="server"
- onclick="Start_Click" />
- <hr />
- <hr />
- <asp:Literal ID="StatusText" runat="server" />
- <asp:Literal ID="DebugLit" runat="server" EnableViewState="false" />
- </div>
- </asp:Content>
Comments