|
||||||||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||||||||
|
Announcements
Chapters
Services
Feature Zones
|
Note: This is an unedited contribution. If this article is inappropriate,
needs attention or copies someone else's work without reference then please
Report This Article
IntroductionIn the web application some times you need to manage your files or allow your users to manage their files. In this time you need a file manager and creating a powerful solution is time consuming, but you don't have enough time. This was the story of my work when I needed it. I think if I write a powerful file manager that is simple to use and portable, did my best. RequirementsFirst step of any project get my requirements I need a file manager has this features:
Using PFM (Power File Manager)Using power file manager (in short PFM) is very simple to install. In first step copy files and directories in your web application then copy bin files to your bin directory next add link of PFM in your app. Note:
Now your app has one PFM. Change SkinTo change skin of PFM you have many customizations
Edit/Create Html FilePFM use MCE_tiny Editor to Create/Edit Html File. This is a powerful editor and you can change it with any Html Editor compatible with asp.net but this is not a limitation. How to Manage Users to Use (Security)This is simple on PFM because PFM has simple structure and you can control it by few changes in code for examples if you need change user permission to avoid deleting file, you can hide delete file in command line and so one. This is very simple but PFM on this Article doesn't have any control on user and its sample of PFM. For making it to your interest you should change it. Warning for multi users Use:If you want to use it for multi users you have to change selection method. as a suggestion you can use cookie. Create/Open ArchiveTo create or Open Archive I use "ICSharpCode.SharpZipLib" Library. This API is cool and is simple to work with ZIP Archive (Under GNU). Code representationTable SolutionMy solution to show a list of files use an ASP Table, but if you know about asp table this is very simple .for this attention I wrote three classes to wrap and use easily 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);
if (!Directory.Exists(p))
{
MultiView1.SetActiveView(View2);
return;
}
string[] fns = Directory.GetFiles(p);
string[] dns = Directory.GetDirectories(p);
string uplevel = startpath;
if (uplevel.LastIndexOf("\\") > 0)
uplevel = uplevel.Substring(0, uplevel.LastIndexOf("\\"));
Table1.Rows.Clear();
Table1.CssClass = "ms-list8-main";
TableRow tr = new TableRow();
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"));
head.ColumnSpan = 5;
tr.Cells.Add(head);
Table1.Rows.Add(tr);
tr = new TableRow();
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")});
Table1.Rows.Add(tr);
PrintList(dns, false);
PrintList(fns, true);
tr = new TableRow();
MyTableCell mtc = new MyTableCell(" ", "ms-list8-bottom");
mtc.ColumnSpan = 5;
tr.Cells.Add(mtc);
Table1.Rows.Add(tr);
MultiView1.SetActiveView(View2);
At first we clear all table cells Table1.Rows.Clear();
Table1.CssClass = "ms-list8-main";
Now create new Table row TableRow tr = new TableRow();
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"));
head.ColumnSpan = 5;
Set column span to 5 to balance the table. After this add head to table row and table tr.Cells.Add(head);
Table1.Rows.Add(tr);
Now we must create new row for title of each cells tr = new TableRow();
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")});
Table1.Rows.Add(tr);
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. Multi view Solution
In this project we have many pages to create, delete, rename and etc….
On the other hand we must create project in one page because it must be portable, in this case my idea to solve this problem is using Multiview solution. Query Handling Solution
How to handle views or user commands, when we use multi view? if (!IsPostBack)
{
string w = Request["goto"];
if (w == null)
ViewList();
else
{
switch (w)
{
case "addnew":
MultiView1.SetActiveView(View1);
Label4.Text = "Create Text File";
TextBox1.ReadOnly = false;
Button7.Visible = false;
break;
case "addnew2":
MultiView1.SetActiveView(View1);
Label4.Text = "Create Text File";
TextBox1.ReadOnly = false;
Button7.Visible = true;
break;
case "listview":
ViewList();
break;
case "edit":
editThisfile();
break;
case "ren":
renamethisfile();
break;
case "del":
deleteThisfile();
break;
case "info":
information();
break;
case "link":
showlink();
break;
case "newFolder":
MultiView1.SetActiveView(View7);
break;
case "Upload":
MultiView1.SetActiveView(View8);
break;
case "zip":
CreateZip();
break;
case "AddZip":
AddtoZip();
break;
case "RemoveZip":
RemoveZip();
break;
case "ReloadZip":
ReloadZip();
break;
case "DeletArch":
DeletArch();
break;
default:
break;
}
}
}
Monitoring Errors
If you have a great project you will have huge errors! To solve this problem you must monitoring your errors and save them when users work with your application. Dr. Watson was a person who wrote any events. So now we have a class with this title. catch (Exception ex)
{
DrWatson.SaveError(ex);
}
|
|||||||||||||||||||||||||||||||||||||||||||||||