Net8: Easy file Disk Management Operation II (including file and folder edit create delete move copy rename etc.)

Source: Internet
Author: User

The original Published time: 2008-08-07--from my Baidu article [imported by moving tools]

Using System;
Using System.Data;
Using System.Configuration;
Using System.Collections;
Using System.Web;
Using System.Web.Security;
Using System.Web.UI;
Using System.Web.UI.WebControls;
Using System.Web.UI.WebControls.WebParts;
Using System.Web.UI.HtmlControls;


Using System.IO;
Using System.Text;

public partial class Default5:System.Web.UI.Page
{

Private FileStream FS;
Private StreamWriter SW;
Private DirectoryInfo di;
Private FileInfo fi;
protected void Page_Load (object sender, EventArgs e)
{
String fpath = Server.urldecode (request.querystring["url"]);
String fname = Server.urldecode (request.querystring["fname"]);
string ax = Server.urldecode (request.querystring["ax"]);
session["Fpath"] = Fpath;
session["Lastfpath"] = Directory.getparent (Fpath). FullName;
if (! IsPostBack)
{
Switch (AX)
{
Case "Editfile":
Panel1.visible = true;
Editfile (Fpath, fname);
Break
Case "Editdir":
Panel2.visible = true;
Editdir (fname);
Break
Case "Deletedir":
Panel3.visible = true;
Deletedir (fname);
Break
Case "DeleteFile":
Panel4.visible = true;
DeleteFile (fname);
Break
Case "MoveFile":
Panel5.visible = true;
MoveFile (Fname,fpath);
Break
Case "Movedir":
Panel6.visible = true;
Movedir (Fname,fpath);
Break
Case "CopyFile":
Panel7.visible = true;
CopyFile (Fpath);
Break
Case "Copydir":
Panel8.visible = true;
Copydir (Fpath);
Break
}
}
}
protected void Textbox2_textchanged (object sender, EventArgs e)
{

}

protected void Editfile (String fpath,string fname)
{
Textbox1.text=fname;
TextBox2.Text = File.readalltext (Fpath, Encoding.default);
}


protected void Button1_Click (object sender, EventArgs e)
{

FS = new FileStream (session["Fpath"]. ToString (), FileMode.Create, FileAccess.Write);
SW = new StreamWriter (FS, Encoding.default);
Sw. WriteLine (TextBox2.Text);
Sw. Close ();
Fs. Close ();
}
protected void button2_click (object sender, EventArgs e)
{
Response.Redirect ("default4.aspx?fpath=" +session["Lastfpath"]. ToString ());
}
protected void Button3_Click (object sender, EventArgs e)
{
DI = new DirectoryInfo (session["Fpath"). ToString ());
String NewPath = session["Lastfpath"]. ToString () + "\ \" + TextBox3.Text;
Di. MoveTo (NewPath);
}
protected void Editdir (String fname)
{
Label1.Text = fname;
}
protected void Deletedir (String fname)
{
Label2.Text = fname;
}
protected void DeleteFile (String fname)
{
Label3.text = fname;
}
protected void Button5_click (object sender, EventArgs e)
{
DI = new DirectoryInfo (session["Fpath"). ToString ());
Di. Delete ();
Response.Write ("<script>alert (' successful deletion ') </script>");
Response.Redirect ("default4.aspx?fpath=" + session["Lastfpath"]. ToString ());
}
protected void Button7_click (object sender, EventArgs e)
{
fi = new FileInfo (session["Fpath"). ToString ());
Fi. Delete ();
Response.Write ("<script>alert (' successful deletion ') </script>");
Response.Redirect ("default4.aspx?fpath=" + session["Lastfpath"]. ToString ());
}
protected void MoveFile (String fname,string fpath)
{
Label5.text = fname;
Label4.text = session["Lastfpath"]. ToString ();
Textbox4.text = session["Lastfpath"]. ToString ();
}
protected void Movedir (String fname, String fpath)
{
Label6.text = fname;
Label7.text = session["Lastfpath"]. ToString ();
Textbox5.text = session["Lastfpath"]. ToString ();
}
protected void Button9_click (object sender, EventArgs e)
{
fi = new FileInfo (session["Fpath"). ToString ());
String Newfpath =textbox4.text+ ";
Fi. MoveTo (Newfpath);
Response.Redirect ("default4.aspx?fpath=" +textbox4.text);
}
protected void Button11_click (object sender, EventArgs e)
{
DI = new DirectoryInfo (session["Fpath"). ToString ());
String Newfpath =textbox5.text+ ";
Di. MoveTo (Newfpath);
Response.Redirect ("default4.aspx?fpath=" +textbox5.text);
}
protected void CopyFile (String fpath)
{
Label8.text = Fpath;
Textbox6.text = Fpath;
}

protected void Button13_click (object sender, EventArgs e)
{
fi = new FileInfo (label8.text);
Fi. CopyTo (Textbox6.text);
Response.Redirect ("default4.aspx?fpath=" + TextBox6.Text.Substring (0,textbox6.text.lastindexof ("));
}

protected void Copydir (String fpath)
{
Label9.text = Fpath;
Textbox7.text = Fpath;
}

protected void Button15_click (object sender, EventArgs e)
{
Dircopy (Label9.text,textbox7.text);
Response.Redirect ("Default4.aspx?fpath=" +textbox7.text.substring ("0,textbox7.text.lastindexof ("));
}
protected void Dircopy (String oldpath,string newpath)
{
DI = new DirectoryInfo (OldPath);
foreach (FileSystemInfo fsi in Di. Getfilesysteminfos ())
{
If (FSI is FileInfo)
{
fi = (FileInfo) FSI;
if (! Directory.Exists (NewPath))
{
DirectoryInfo newdir= directory.createdirectory (NewPath);
Fi. CopyTo (newdir.fullname+ ");
}
Else
{
Fi. CopyTo (newpath+ ");
}
}
Else
{
DirectoryInfo child_di= (DirectoryInfo) FSI;
String Olddir=child_di. FullName;
String Dirname=child_di. Fullname.substring (Child_di. Fullname.lastindexof (");
String Newchildpath=path.combine (Newpath,dirname);
if (! Directory.Exists (Olddir))
Directory.CreateDirectory (Olddir);
Dircopy (Olddir,newchildpath);
}

}
}
}

Net8: Easy file Disk Management Operation II (including file and folder edit create delete move copy rename etc.)

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.