Exemplo n.º 1
0
        public JsonResult Rename()
        {
            var            virtualPath   = Request.Form["virtualPath"];
            var            newName       = Request.Form["newName"];
            var            oldName       = Request.Form["oldName"];
            String         decodePath    = UtilityOperations.DecodePath(UtilityOperations.GetServerMapPath(virtualPath), Server);
            String         newDecodePath = decodePath.Replace(oldName, newName);
            String         retJsonMsg    = "";
            FileAttributes attr          = System.IO.File.GetAttributes(decodePath);

            if ((attr & FileAttributes.Directory) == FileAttributes.Directory)
            {
                if (System.IO.Directory.Exists(decodePath))
                {
                    System.IO.Directory.Move(decodePath, decodePath.Replace(oldName, newName));
                    retJsonMsg += " DirRenamed";
                }
            }
            else
            {
                if (System.IO.File.Exists(decodePath))
                {
                    System.IO.File.Move(decodePath, decodePath.Replace(oldName, newName));
                    retJsonMsg += " FileRenamed";
                }
            }
            DocumentsOperations docOps = new DocumentsOperations();

            if (docOps.GetFileByVirtualPath(virtualPath) != null)
            {
                docOps.RenameFile(newName, virtualPath, virtualPath.Replace(oldName, newName));
                retJsonMsg += " DBRenamed";
            }
            return(new JsonResult()
            {
                Data = retJsonMsg
            });
        }
Exemplo n.º 2
0
        public void Rename(string jlist, string path, string newname)
        {
            string decodedPath = DecodePath(path);
            System.Web.Script.Serialization.JavaScriptSerializer serializer = new System.Web.Script.Serialization.JavaScriptSerializer();
            List<string> list = serializer.Deserialize<List<string>>(jlist);
            string itempath = list[0];
            FileAttributes attr = System.IO.File.GetAttributes(itempath);
            if ((attr & FileAttributes.Directory) == FileAttributes.Directory)
            {
                if (Directory.Exists(itempath))
                {
                    Directory.Move(itempath, Path.Combine( decodedPath , newname));
                }
            }
            else
            {
                if (System.IO.File.Exists(itempath))
                {
                    string newItemPath = Path.Combine(decodedPath, newname);
                    string previousVirtualPath = UtilityOperations.GetVirtualPath(itempath);//.Replace("~/", "~//"); ;
                    string newVirtualPath = UtilityOperations.GetVirtualPath(newItemPath);
                    DocumentsOperations documentsOperations = new DocumentsOperations();
                    documentsOperations.RenameFile(newname, previousVirtualPath, newVirtualPath);
                    System.IO.File.Move(itempath, newItemPath);

                }
            }
        }