public RDirectoryItem GetFolderName(string folderPath) { if (!DriveExist) { throw new DriveDoesNotExistException(); } if (folderPath.Trim() != string.Empty) { string drivepath = Path.Combine(MemberDataAbsPath, folderPath); DirectoryInfo i = new DirectoryInfo(drivepath); RDirectoryItem rdi = new RDirectoryItem(); rdi.ID = Guid.NewGuid(); rdi.CreateDate = i.CreationTime; rdi.LastAccessDate = i.LastAccessTime; rdi.Location = i.FullName.Replace(string.Format("{0}\\", MemberDataAbsPath), string.Empty); rdi.ModifyDate = i.LastWriteTime; rdi.Name = i.Name; rdi.Contains = ""; // string.Format("{0} Folders, {1} Files", i.EnumerateDirectories().Count(), i.EnumerateFileSystemInfos().Count()); rdi.ThumbNail = string.Format("{0}/bootstrap/img/drive/folder-data-icon.png", Utility.SiteURL); return(rdi); } else { return(new RDirectoryItem()); } }
public List <RDirectoryItem> GetCrumbs(string p) { List <RDirectoryItem> list = new List <RDirectoryItem>(); List <string> FolderList = p.Split("/".ToCharArray()).ToList(); StringBuilder temp = new StringBuilder(); foreach (string i in FolderList) { if (i != string.Empty) { temp.Append(i); temp.Append("/"); //< li >< a href = "viewdrive.aspx?folderpath=<%= temp %>" > //<%= i %></ a > < span class="divider">/</span></li> RDirectoryItem rdi = new RDirectoryItem(); rdi.ID = Guid.NewGuid(); rdi.Location = temp.ToString(); rdi.Name = i; rdi.ThumbNail = string.Empty; list.Add(rdi); } } return(list); }
// GET api/<controller> public DriveDTO Get([FromUri] string name = "") { List <String> FolderList = new List <string>(); RDirectoryItem CurrentFolder = new RDirectoryItem(); string FolderPath = string.Empty; Member CurrentUser = db.Members.FirstOrDefault(d => d.Email == User.Identity.Name); DriveManager DM = new DriveManager(CurrentUser, System.Web.Hosting.HostingEnvironment.MapPath(Utility.SiteDriveFolderPath), string.Format("{0}/{1}", Utility.SiteURL, Utility.SiteDriveFolderName)); DM.ItemDeletable = true; if (!string.IsNullOrEmpty(name)) { FolderPath = name; } FolderList = FolderPath.Split('/').ToList <string>(); CurrentFolder = DM.GetFolderName(FolderPath); DriveDTO result = new DriveDTO(); result.Crumbs.AddRange(DM.GetCrumbs(FolderPath)); result.Directories.AddRange(DM.GetDirectoryItemList(FolderPath)); result.Files.AddRange(DM.GetFileItemList(FolderPath)); return(result); }
public List <RDirectoryItem> GetDirectoryItemList(string folderpath) { if (!DriveExist) { throw new DriveDoesNotExistException(); } bool folderDeletable = true; List <RDirectoryItem> list = new List <RDirectoryItem>(); string drivepath = Path.Combine(MemberDataAbsPath, folderpath); folderDeletable = ItemDeletable; if (folderpath == string.Empty) { folderDeletable = false; } DirectoryInfo di = new DirectoryInfo(drivepath); if (di.Exists) { foreach (DirectoryInfo i in di.EnumerateDirectories()) { RDirectoryItem rdi = new RDirectoryItem(); rdi.ID = Guid.NewGuid(); rdi.CreateDate = i.CreationTime; rdi.LastAccessDate = i.LastAccessTime; rdi.Location = i.FullName.Replace(string.Format("{0}\\", MemberDataAbsPath), string.Empty); rdi.ModifyDate = i.LastWriteTime; rdi.Name = i.Name; if (i.EnumerateDirectories().Count() == 0 && i.EnumerateFiles().Count() == 0) { rdi.Deletable = true; } else { rdi.Deletable = false; } rdi.Editable = true; rdi.Contains = string.Format("{0} Folders, {1} Files", i.EnumerateDirectories().Count(), i.EnumerateFiles().Count()); rdi.ThumbNail = string.Empty; list.Add(rdi); } } else { throw new DriveDoesNotExistException(); } return(list); }
protected void Page_Load(object sender, EventArgs e) { try { if (CurrentUser.UserType == (byte)MemberTypeType.Admin) { DM = new DriveManager(CurrentUser, Server.MapPath(Utility.SiteDriveFolderPath), string.Format("{0}/{1}", Utility.SiteURL, Utility.SiteDriveFolderName)); DM.ItemDeletable = true; } else if (CurrentUser.UserType == (byte)MemberTypeType.Author) { DM = new DriveManager(CurrentUser, Server.MapPath(Utility.SiteDriveFolderPath + "/" + CurrentUser.ID.ToString()), string.Format("{0}/{1}/{2}", Utility.SiteURL, Utility.SiteDriveFolderName, CurrentUser.ID.ToString())); DM.ItemDeletable = true; //check if author drive folder exists if not create one. DM.VerifyDrive(); } if (Request.QueryString["folderpath"] != null) { FolderPath = Request.QueryString["folderpath"].ToString().Trim(); } else { FolderPath = string.Empty; } FolderList = FolderPath.Split('/').ToList <string>(); CurrentFolder = DM.GetFolderName(FolderPath); FolderTableRepeater.DataSource = DM.GetDirectoryItemList(FolderPath); FolderTableRepeater.DataBind(); FileItemRepeater.DataSource = DM.GetFileItemList(FolderPath); FileItemRepeater.DataBind(); } catch (Exception ex) { message4.Text = string.Format("Unable to process request. Error - {0}", ex.Message); message4.Visible = true; message4.Indicate = AlertType.Error; } }