예제 #1
0
 protected void btn_upload_Click(object sender, EventArgs e)
 {
     if (FUL.HasFile)
     {
         uploadLB.Text = "文件名称:" + FUL.FileName;
         string path = Server.MapPath("~/" + "\\upload\\");
         FUL.SaveAs(path + FUL.FileName);
     }
     else
     {
         Response.Write("<script>alert('请选择文件!')</script>");
     }
 }
예제 #2
0
    protected void UploadFile_Click(object sender, EventArgs e)
    {
        string savePath = Server.MapPath(@"ProgImg\");

        // Before attempting to save the file, verify
        // that the FileUpload control contains a file.
        if (FUL.HasFile)
        {
            // Get the name of the file to upload.
            string fileName = Server.HtmlEncode(FUL.FileName);

            // Get the extension of the uploaded file.
            string extension = System.IO.Path.GetExtension(fileName);

            // Allow only files with .doc or .xls extensions
            // to be uploaded.
            if ((extension == ".jpg") || (extension == ".png"))
            {
                // 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.
                FUL.SaveAs(savePath);

                imgProglogo.ImageUrl = @savePath;

                // Notify the user that their file was successfully uploaded.
                lbAlert.Text = "Your file was uploaded successfully.";
            }
            else
            {
                // Notify the user why their file was not uploaded.
                lbAlert.Text = "Your file was not uploaded because " +
                               "it does not have a .doc or .xls extension.";
            }
        }
    }