SoFunction
Updated on 2025-03-07

Copy, move, create c# file (instance code)

}
protected void Button1_Click(object sender, EventArgs e)
{
    if ( == "")
    {
("<script language=javascript>alert('File name error!');location='javascript:(-1)'</script>");
    }
    else
    {
        try
        {
            string path = ("File") + "\\" + + ;
            FileInfo fi = new FileInfo(path);
if (!)//If the file does not exist
            {
();//Create a file
= "Created successfully! File name:" + + ;
                List();
            }
        }
        catch (Exception error)
        {
            (());
        }
    }
}
protected void Button2_Click(object sender, EventArgs e)
{
    try
    {
        string path = ("File/") + Session["txt"];
string path2 = ("File/") + "Copy" + Session["txt"];
        FileInfo fi = new FileInfo(path);
        if ()
        {
(path2);//Copy the file in the specified path folder to the folder and rename the file
        }
= "Copy" + Session["txt"] + "Success!" + "File is:" + ("Copy" + Session["txt"].ToString());
        List();
    }
    catch (Exception error)
    {
= "There was an error in copying the file, the file has been copied!";
    }
}
protected void Button4_Click(object sender, EventArgs e)
{
    string path = ("File/") + ();
    string path2 = ("file2/") + ();
    FileInfo fi = new FileInfo(path);
    FileInfo fi2 = new FileInfo(path2);
    if ()
    {
        if (!)
        {
(path2);//Move the file in the specified folder path to the folder in another path
            List();
        }
        else
        {
("<script language=javascript>alert('The target folder file already exists, and the file cannot be moved and modified!'); location='javascript:(-1)'</script>");
        }
    }