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;
public delegate void UploadSuccessfully(string excelFileName);
public delegate void UploadFail(string excelFileName);
public partial class Tax_TaxRecordUpload : System.Web.UI.UserControl
{
public UploadSuccessfully onUploadSuccessfully;
public UploadFail onUploadFailFail;
protected void Page_Load(object sender, EventArgs e)
{
}
protected void btnUpload_Click(object sender, EventArgs e)
{
string filePath = string.Empty;
try
{
string fileName = Guid.NewGuid().ToString();
filePath = MapPath("~/Tax/Uploaded/" + fileName + ".xls");
this.FURecordFiles.SaveAs(filePath);
if (this.onUploadSuccessfully != null) onUploadSuccessfully(filePath);
// Page.Response.Write("<script>alert('文件上传成功!')</script>");
}
catch (Exception)
{
if (this.onUploadFailFail != null) onUploadFailFail(filePath);
Page.Response.Write(@"<script>alert('文件上传失败!/r/n/r/n请检查你所选择的文件!')</script>");
}
}
}
使用的页面:
this.RecordUpload.onUploadSuccessfully += FileUploadSuccessfully;
protected void UploadFailFail(string excelFileName)
{
try
{
ImportFlag = false;
if (File.Exists(excelFileName))
{
File.Delete(excelFileName);
}
}
catch (Exception)
{ }
}