source code bean

05 Oct, 2009

Rename a Folder using EPiServer.Web.Hosting.UnifiedDirectory

Posted by: Peter In: ASP.NET| C#| EPiServer

While reading the EPiServer 5 SDK documentation, i found this:

Rename a Folder

There is no Rename method on the EPiServer.Web.Hosting.UnifiedDirectory class. To rename a folder you need to call the MoveTo method as follows:

  1.  
  2. protected void RenameFolder(string path, string oldName, string name)
  3. {
  4.     if (IsFolder(path))
  5.     {
  6.         UnifiedDirectory directory =
  7.         System.Web.Hosting.HostingEnvironment.VirtualPathProvider.GetDirectory(path) as UnifiedDirectory;
  8.  
  9.         int e = -1;
  10.         while (path.IndexOf(oldName, ++e) > -1) ;
  11.  
  12.         StringBuilder sb = new StringBuilder();
  13.         sb.Append(path.Substring(0, e – 1));
  14.         sb.Append(name);
  15.         sb.Append("/");
  16.  
  17.         directory.MoveTo(sb.ToString());
  18.     }
  19. }
  20.  

What a convenient way of renaming a folder :) Good thing that you don’t have to do it too often.

No Responses to "Rename a Folder using EPiServer.Web.Hosting.UnifiedDirectory"

Comment Form

Categories

Adwords

Twitter Updates


    • Martin: maybe yesterday really webservice used one of customers. MonoMaxMemory 500000000 maybe work, but its combination of problems with webservices. we
    • Peter: I am note quite sure how to set if for all vhosts, or how well MonoMaxMemory works at all. This is from the documentation: "MonoMaxMemory. If MonoR
    • Martin: no today webservice called... and i dont reise maxmemory but limit it to 500MB How can i limit memory SUM of all solutions to 500MB?

    About

    Welcome to source code bean! You will find information on tips and tricks on programming languages, server side stuff, and anything that causes troubles to web development.