protected void GrdScannedDoc_RowDataBound(object sender, GridViewRowEventArgs e) { if (e.Row.RowType == DataControlRowType.DataRow) { FileSystemItemCS item = e.Row.DataItem as FileSystemItemCS; if (item.IsFolder) { LinkButton lbFolderItem = e.Row.FindControl("lbFolderItem") as LinkButton; lbFolderItem.Text = string.Format(@"<img src=""{0}"" alt="""" /> {1}", Page.ResolveClientUrl("~/Images/folder.png"), item.Name); } else { Literal ltlFileItem = e.Row.FindControl("ltlFileItem") as Literal; if (this.CurrentFolder.StartsWith("~")) { ltlFileItem.Text = string.Format(@"<a href=""{0}"" target=""_blank"">{1}</a>", Page.ResolveClientUrl(string.Concat(this.CurrentFolder, "/", item.Name).Replace("//", "/")), item.Name); } else { ltlFileItem.Text = item.Name; } } } }
private void PopulateGrid() { var currentDirInfo = new DirectoryInfo(GetFullyQualifiedFolderPath(this.CurrentFolder)); var folders = currentDirInfo.GetDirectories(); var tmpFiles1 = currentDirInfo.GetFiles(); var tmpFiles2 = tmpFiles1.Where(s => s.Extension != ".aspx"); var tmpFiles3 = tmpFiles2.Where(s => s.Extension != ".cs"); var files = tmpFiles3.Where(s => s.Extension != ".config"); var fsItems = new List <FileSystemItemCS>(folders.Length + files.Count()); if (!TwoFoldersAreEquivalent(currentDirInfo.FullName, GetFullyQualifiedFolderPath(this.HomeFolder))) { var parentFolder = new FileSystemItemCS(currentDirInfo.Parent); parentFolder.Name = ".."; fsItems.Add(parentFolder); } foreach (var folder in folders) { fsItems.Add(new FileSystemItemCS(folder)); } foreach (var file in files) { fsItems.Add(new FileSystemItemCS(file)); } gvFiles.DataSource = fsItems; gvFiles.DataBind(); var currentFolderDisplay = this.CurrentFolder; if (currentFolderDisplay.StartsWith("~/") || currentFolderDisplay.StartsWith("~\\")) { currentFolderDisplay = currentFolderDisplay.Substring(2); } }
protected void FillScannedDocGrid() { // Get the list of files & folders in the CurrentFolder DirectoryInfo currentDirInfo = new DirectoryInfo(GetFullyQualifiedFolderPath(this.CurrentFolder)); DirectoryInfo[] folders = currentDirInfo.GetDirectories(); FileInfo[] files = currentDirInfo.GetFiles(); List <FileSystemItemCS> fsItems = new List <FileSystemItemCS>(folders.Length + files.Length); // Add the ".." option, if needed if (!TwoFoldersAreEquivalent(currentDirInfo.FullName, GetFullyQualifiedFolderPath(this.HomeFolder))) { FileSystemItemCS parentFolder = new FileSystemItemCS(currentDirInfo.Parent); parentFolder.Name = ".."; fsItems.Add(parentFolder); } foreach (DirectoryInfo folder in folders) { fsItems.Add(new FileSystemItemCS(folder)); } foreach (FileInfo file in files) { fsItems.Add(new FileSystemItemCS(file)); } GrdScannedDoc.DataSource = fsItems; GrdScannedDoc.DataBind(); string currentFolderDisplay = this.CurrentFolder; if (currentFolderDisplay.StartsWith("~/") || currentFolderDisplay.StartsWith("~\\")) { currentFolderDisplay = currentFolderDisplay.Substring(2); } lblCurrentPath.Text = "Viewing the folder <b>" + currentFolderDisplay + "</b>"; }
protected void GrdScannedDoc_RowDataBound(object sender, GridViewRowEventArgs e) { if (e.Row.RowType == DataControlRowType.DataRow) { FileSystemItemCS item = e.Row.DataItem as FileSystemItemCS; if (item.IsFolder) { LinkButton lbFolderItem = e.Row.FindControl("lbFolderItem") as LinkButton; lbFolderItem.Text = string.Format(@"<img src=""{0}"" alt="""" /> {1}", Page.ResolveClientUrl("~/images/folder.png"), item.Name); } else { Literal ltlFileItem = e.Row.FindControl("ltlFileItem") as Literal; if (this.CurrentFolder.StartsWith("~")) { ltlFileItem.Text = string.Format(@"<a href=""{0}"" target=""_blank"">{1}</a>", Page.ResolveClientUrl(string.Concat(this.CurrentFolder, "/", item.Name).Replace("//", "/")), item.Name); } else { ltlFileItem.Text = item.Name; } } ImageButton btnDelete = (ImageButton)e.Row.FindControl("btnDelete"); if (btnDelete != null) { btnDelete.OnClientClick = item.IsFolder ? "javascript:if (!confirm('Are you sure you want to PERMANENTLY delete this folder and all of it\\'s contents?')) return false;" : "javascript:if (!confirm('Are you sure you want to PERMANENTLY delete this file?')) return false;"; } } }
protected void FillScannedDocGrid() { try { // Get the list of files & folders in the CurrentFolder DirectoryInfo currentDirInfo = new DirectoryInfo(GetFullyQualifiedFolderPath(this.CurrentFolder)); bool currentDirIsHomeFolder = TwoFoldersAreEquivalent(currentDirInfo.FullName, GetFullyQualifiedFolderPath(this.HomeFolder)); if (!currentDirInfo.Exists) // in case the folder has been deleted in another page throw new CustomMessageException("Could not find directory: " + currentDirInfo.Name); DirectoryInfo[] folders = currentDirInfo.GetDirectories(); FileInfo[] files = currentDirInfo.GetFiles(); List<FileSystemItemCS> fsItems = new List<FileSystemItemCS>(folders.Length + files.Length); // Add the ".." option, if needed if (!currentDirIsHomeFolder) { FileSystemItemCS parentFolder = new FileSystemItemCS(currentDirInfo.Parent); parentFolder.Name = ".."; fsItems.Add(parentFolder); } Hashtable medicalServiceTypeHash = MedicalServiceTypeDB.GetMedicareServiceTypeHash(); foreach (DirectoryInfo folder in folders) { FileSystemItemCS fileSystemItemCS = new FileSystemItemCS(folder); if (currentDirIsHomeFolder) fileSystemItemCS.Name = MedicalServiceType.ReplaceMedicareServiceTypeFolders(fileSystemItemCS.Name, medicalServiceTypeHash, true); fsItems.Add(fileSystemItemCS); } foreach (FileInfo file in files) fsItems.Add(new FileSystemItemCS(file)); //GrdScannedDoc.DataSource = fsItems; //GrdScannedDoc.DataBind(); if (fsItems.Count > 0) { GrdScannedDoc.DataSource = fsItems; GrdScannedDoc.DataBind(); } else { fsItems.Add(new FileSystemItemCS()); GrdScannedDoc.DataSource = fsItems; GrdScannedDoc.DataBind(); int TotalColumns = GrdScannedDoc.Rows[0].Cells.Count; GrdScannedDoc.Rows[0].Cells.Clear(); GrdScannedDoc.Rows[0].Cells.Add(new TableCell()); GrdScannedDoc.Rows[0].Cells[0].ColumnSpan = TotalColumns; GrdScannedDoc.Rows[0].Cells[0].Text = "No Files Or Folders Found"; } string currentFolderDisplay = this.CurrentFolder; if (currentFolderDisplay.StartsWith("~/") || currentFolderDisplay.StartsWith("~\\")) currentFolderDisplay = currentFolderDisplay.Substring(2); if (currentFolderDisplay.StartsWith("~/") || currentFolderDisplay.StartsWith("~\\")) currentFolderDisplay = currentFolderDisplay.Substring(2); currentFolderDisplay = currentFolderDisplay.Substring(this.HomeFolder.Length); if (currentFolderDisplay.StartsWith("\\")) currentFolderDisplay = currentFolderDisplay.Substring(1); if (currentFolderDisplay == "") currentFolderDisplay = "[Root Directory]"; currentFolderDisplay = MedicalServiceType.ReplaceMedicareServiceTypeFolders(currentFolderDisplay, medicalServiceTypeHash, true); lblCurrentPath.Text = "Viewing Folder: <b><font color=\"blue\">" + currentFolderDisplay + "</font></b>"; } catch(CustomMessageException cmEx) { SetErrorMessage(cmEx.Message); } catch(Exception ex) { SetErrorMessage("", ex.ToString()); } }
protected void FillScannedDocGrid() { // Get the list of files & folders in the CurrentFolder DirectoryInfo currentDirInfo = new DirectoryInfo(GetFullyQualifiedFolderPath(this.CurrentFolder)); DirectoryInfo[] folders = currentDirInfo.GetDirectories(); FileInfo[] files = currentDirInfo.GetFiles(); List<FileSystemItemCS> fsItems = new List<FileSystemItemCS>(folders.Length + files.Length); // Add the ".." option, if needed if (!TwoFoldersAreEquivalent(currentDirInfo.FullName, GetFullyQualifiedFolderPath(this.HomeFolder))) { FileSystemItemCS parentFolder = new FileSystemItemCS(currentDirInfo.Parent); parentFolder.Name = ".."; fsItems.Add(parentFolder); } foreach (DirectoryInfo folder in folders) fsItems.Add(new FileSystemItemCS(folder)); foreach (FileInfo file in files) fsItems.Add(new FileSystemItemCS(file)); GrdScannedDoc.DataSource = fsItems; GrdScannedDoc.DataBind(); string currentFolderDisplay = this.CurrentFolder; if (currentFolderDisplay.StartsWith("~/") || currentFolderDisplay.StartsWith("~\\")) currentFolderDisplay = currentFolderDisplay.Substring(2); lblCurrentPath.Text = "Viewing the folder <b>" + currentFolderDisplay + "</b>"; }
// http://www.4guysfromrolla.com/articles/090110-1.aspx #region GrdScannedDoc protected void FillScannedDocGrid() { try { // Get the list of files & folders in the CurrentFolder DirectoryInfo currentDirInfo = new DirectoryInfo(GetFullyQualifiedFolderPath(this.CurrentFolder)); bool currentDirIsHomeFolder = TwoFoldersAreEquivalent(currentDirInfo.FullName, GetFullyQualifiedFolderPath(this.HomeFolder)); if (!currentDirInfo.Exists) // in case the folder has been deleted in another page { throw new CustomMessageException("Could not find directory: " + currentDirInfo.Name); } DirectoryInfo[] folders = currentDirInfo.GetDirectories(); FileInfo[] files = currentDirInfo.GetFiles(); List <FileSystemItemCS> fsItems = new List <FileSystemItemCS>(folders.Length + files.Length); // Add the ".." option, if needed if (!currentDirIsHomeFolder) { FileSystemItemCS parentFolder = new FileSystemItemCS(currentDirInfo.Parent); parentFolder.Name = ".."; fsItems.Add(parentFolder); } Hashtable medicalServiceTypeHash = MedicalServiceTypeDB.GetMedicareServiceTypeHash(); foreach (DirectoryInfo folder in folders) { FileSystemItemCS fileSystemItemCS = new FileSystemItemCS(folder); if (currentDirIsHomeFolder) { fileSystemItemCS.Name = MedicalServiceType.ReplaceMedicareServiceTypeFolders(fileSystemItemCS.Name, medicalServiceTypeHash, true); } fsItems.Add(fileSystemItemCS); } foreach (FileInfo file in files) { fsItems.Add(new FileSystemItemCS(file)); } //GrdScannedDoc.DataSource = fsItems; //GrdScannedDoc.DataBind(); if (fsItems.Count > 0) { GrdScannedDoc.DataSource = fsItems; GrdScannedDoc.DataBind(); } else { fsItems.Add(new FileSystemItemCS()); GrdScannedDoc.DataSource = fsItems; GrdScannedDoc.DataBind(); int TotalColumns = GrdScannedDoc.Rows[0].Cells.Count; GrdScannedDoc.Rows[0].Cells.Clear(); GrdScannedDoc.Rows[0].Cells.Add(new TableCell()); GrdScannedDoc.Rows[0].Cells[0].ColumnSpan = TotalColumns; GrdScannedDoc.Rows[0].Cells[0].Text = "No Files Or Folders Found"; } string currentFolderDisplay = this.CurrentFolder; if (currentFolderDisplay.StartsWith("~/") || currentFolderDisplay.StartsWith("~\\")) { currentFolderDisplay = currentFolderDisplay.Substring(2); } if (currentFolderDisplay.StartsWith("~/") || currentFolderDisplay.StartsWith("~\\")) { currentFolderDisplay = currentFolderDisplay.Substring(2); } currentFolderDisplay = currentFolderDisplay.Substring(this.HomeFolder.Length); if (currentFolderDisplay.StartsWith("\\")) { currentFolderDisplay = currentFolderDisplay.Substring(1); } if (currentFolderDisplay == "") { currentFolderDisplay = "[Root Directory]"; } currentFolderDisplay = MedicalServiceType.ReplaceMedicareServiceTypeFolders(currentFolderDisplay, medicalServiceTypeHash, true); lblCurrentPath.Text = "Viewing Folder: <b><font color=\"blue\">" + currentFolderDisplay + "</font></b>"; } catch (CustomMessageException cmEx) { SetErrorMessage(cmEx.Message); } catch (Exception ex) { SetErrorMessage("", ex.ToString()); } }