文件上传, 打开, 删除操作

  protected void Btn_Up_Click(object sender, EventArgs e)
    {

        // Specify the path on the server to 
        // save the uploaded file to. 
        // String savePath = @"D:/WebSite/FileUpload/UploadedImages/";
        String savePath = @"\192.168.1.188 emp0-T1";

        // Before attempting to perform operations 
        // on the file, verify that the FileUpload  
        // control contains a file. 
        if (FileUpload1.HasFile)
        {
            // Get the name of the file to upload. 
            String fileName = FileUpload1.FileName;

            // Append the name of the file to upload to the path. 
            savePath += fileName;


            // Call the SaveAs method to save the  
            // uploaded file to the specified path. 
            // This example does not perform all 
            // the necessary error checking.                
            // If a file with the same name 
            // already exists in the specified path,   
            // the uploaded file overwrites it. 
            FileUpload1.SaveAs(savePath);

            // Notify the user of the name of the file 
            // was saved under.
 
            //UploadStatusLabel.Text = "Your file was saved as " + fileName;

            //Response.Write("<script>alert('你的文件保存在 '" + fileName + "'!')</script>");
            this.Label1.Text = "你的文件保存在 '" + savePath + "'!";

        }
        else
        {
            // Notify the user that a file was not uploaded. 
            //UploadStatusLabel.Text = "You did not specify a file to upload.";
            ClientScriptManager scriptManager = ((Page)System.Web.HttpContext.Current.Handler).ClientScript;
            scriptManager.RegisterStartupScript(typeof(string), "", "alert('你没有指定文件名上传 ');", true);
        } 


    }

    protected void Btn_Open_Click(object sender, EventArgs e)
    {
        try
        {

            System.Diagnostics.Process.Start(@"\192.168.1.188 emp0-T12.xlsx");
        }
        catch (Exception ex)
        {
            //Response.Write("<script language='javascript'>alert('" + ex.Message.ToString() + "');</script>");
            ClientScriptManager scriptManager = ((Page)System.Web.HttpContext.Current.Handler).ClientScript;
            scriptManager.RegisterStartupScript(typeof(string), "", "alert('" + ex.Message.ToString() + "');", true);
        }

    }

    protected void Btn_Clearn_Click(object sender, EventArgs e)
    {
        //获得图片的服务器路径
        //string delFile = Server.MapPath("~/photo/img1.JPG");
        string delFile =@"\192.168.1.188 emp0-T11.xlsx";

        //删除图片
        File.Delete(delFile);
    }

//*****************************************

        <br />
        <br />
          &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
        <asp:FileUpload ID="FileUpload1" runat="server" />
        &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
        <asp:Label ID="Label1" runat="server" Text="显示:" Width="409px"></asp:Label>
        <br />
        <br />
        &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;
        <asp:Button ID="Btn_Up" runat="server" onclick="Btn_Up_Click"
            Text="Up_test" Width="76px" />
        &nbsp;&nbsp;&nbsp;&nbsp;
        <asp:Button ID="Btn_Clearn" runat="server" onclick="Btn_Clearn_Click"
            Text="Clearn" style="height: 26px" Width="77px" />
        <br />
        &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
        <asp:Button ID="Btn_Open" runat="server" onclick="Btn_Open_Click" Text="Open"
            Width="76px" />
        <br />
        <br /> 

//*****************************************

原文地址:https://www.cnblogs.com/hutie1980/p/4705196.html