CodeProject Pick: ASP.NET File Manager

Powerful File manager
A Powerful File manager in pure asp.net
First step of any project get my requirements I need a file manager has this features:
- Create new directory
- Create new html/text file
- Edit html/text files
- Upload file
- Upload and unzip files in to destination directory
- Create Archive in server (in zip format)
- Show list of Files/Directory
- Show Attribute of Files
- Delete files
- Delete Directory
- Pure ASP.net (without any configuration)
- Skin able (change with CSS)
- User Friendly
- Security
- Easy to install
Using PFM (Power File Manager)
- The default directory to manage in PFM is “other file” but you can change it in source code (root path).
- If you want to share the PFM with your Users for their directories you can manage root path with your app.
To change skin of PFM you have many customizations
How to Manage Users to Use (Security)
public class MyTableCell:TableCell //Describe new Table Cell
public class MyLinkButton:Label //Describe Link button (text + image)
public class MyImageButton:Label //Describe Image button
Now all things are ready to create a list of files and directories:
string p = Server.MapPath(startpath);
MultiView1.SetActiveView(View2);
string[] fns = Directory.GetFiles(p);
string[] dns = Directory.GetDirectories(p);
if (uplevel.LastIndexOf(“\\”) > 0)
uplevel = uplevel.Substring(0, uplevel.LastIndexOf(“\\“));
Table1.CssClass = “ms-list8-main“;
MyTableCell head = new MyTableCell(“ms-list8-top“, new MyImageButton(“softimages/folder_home.png“, “Default.aspx?goto=listview“, “Root“)
, new MyImageButton(“softimages/back.png“, “Default.aspx?goto=listview&start=” + uplevel, “Back“)
, new MyImageButton(“softimages/top.png“, “Default.aspx?goto=Upload&start=” + startpath, “Upload File“)
, new MyImageButton(“softimages/newfolder.png“, “Default.aspx?goto=newFolder&start=” + startpath, “New Folder“)
, new MyImageButton(“softimages/mimetype/html.png“, “Default.aspx?goto=addnew2&start=” + startpath, “New Text File“)
, new MyImageButton(“softimages/ark.png“, “Default.aspx?goto=zip&start=” + startpath, “Archive“)
, new MyImageButton(“softimages/reloadark.png“, “Default.aspx?goto=ReloadZip&start=” + startpath, “Clear Archive“)
, new MyImageButton(“softimages/delark.png“, “Default.aspx?goto=DeletArch&start=” + startpath, “Delete Archive“));
tr.Cells.AddRange(new TableCell[] {new MyTableCell(“File Name“,”ms-list8-tl“),new MyTableCell(“Size“,”ms-list8-top“)
,new MyTableCell(“Creation Time“,”ms-list8-top“),
new MyTableCell(“Last write time“,”ms-list8-top“) ,new MyTableCell(“Commands“,”ms-list8-top“)});
MyTableCell mtc = new MyTableCell(“
“, “ms-list8-bottom“);
MultiView1.SetActiveView(View2);
At first we clear all table cells
Table1.CssClass = “ms-list8-main”;
So, create new Table Cells for command button bar
MyTableCell head = new MyTableCell(“ms-list8-top”, new MyImageButton(“softimages/folder_home.png”,
“Default.aspx?goto=listview”, “Root”), new MyImageButton(“softimages/back.png”,
“Default.aspx?goto=listview&start=” + uplevel, “Back”),new MyImageButton(“softimages/top.png”,
“Default.aspx?goto=Upload&start=” + startpath, “Upload File”),
new MyImageButton(“softimages/newfolder.png”, “Default.aspx?goto=newFolder&start=” +
startpath,“New Folder”), new MyImageButton(“softimages/mimetype/html.png”,
“Default.aspx?goto=addnew2&start=” + startpath, “New Text File”)
, new MyImageButton(“softimages/ark.png”, “Default.aspx?goto=zip&start=” + startpath, “Archive”)
, new MyImageButton(“softimages/reloadark.png”, “Default.aspx?goto=ReloadZip&start=” +
startpath, “Clear Archive”), new MyImageButton(“softimages/delark.png”,
“Default.aspx?goto=DeletArch&start=” + startpath, “Delete Archive”));
Set column span to 5 to balance the table. After this add head to table row and table
Now we must create new row for title of each cells
tr.Cells.AddRange(new TableCell[] {new MyTableCell(“File Name”,“ms-list8-tl”),new
MyTableCell(“Size”,“ms-list8-top”),new MyTableCell(“Creation Time”,
“ms-list8-top”),new MyTableCell(“Last write time”,“ms-list8-top”)
,new MyTableCell(“Commands”,“ms-list8-top”)});
In this time we have Table with command bar and title bar and can add list of directory’s and files
PrintList(dns, false); // dns is list of directories name
PrintList(fns, true); // fns is list of files name
Print list is a procedure with two parameters to show list in table
private
void PrintList(string[] fns, bool isfiles)
Other source code of create list is very easy and don’t need any more comment.
MultiView1.SetActiveView(View1);
Label4.Text = “Create Text File”;
MultiView1.SetActiveView(View1);
Label4.Text = “Create Text File”;
MultiView1.SetActiveView(View7);
MultiView1.SetActiveView(View8);
This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)
| mohsen ahmadian
|
I am mohsen ahmadian I live in kermanshah(city of iran) I Love Codeproject and C++,java,C#
|
Bottom of Form
About this entry
You’re currently reading “CodeProject Pick: ASP.NET File Manager,” an entry on TECH NOTES
- Published:
- July 3, 2008 / 1:10 am
- Category:
- Code Project Picks
- Tags:
- asp.net, file manager



