它对我有用:https ://stackoverflow.com/a/12472235/2247978
..................................................... ..................................................... .
将 HiddenField 控件添加到窗体中:
<asp:HiddenField runat="server" ID="UploadedPathHiddenField" />
重写 UploadComplete 方法如下:
protected void UploadComplete(object sender, AsyncFileUploadEventArgs e)
{
var fileName = GeneratePrefixFileName() + System.IO.Path.GetFileName(e.FileName);
var relativePath = "~/Image/" + fileName;
var filePath = Server.MapPath(relativePath);
AsyncFileUpload1.SaveAs(filePath);
ScriptManager.RegisterClientScriptBlock(this, this.GetType(), "filePath", "top.$get(\"" + UploadedPathHiddenField.ClientID + "\").value = '" + ResolveClientUrl(relativePath) + "';", true);
}
之后,您可以通过以下方式在 showConfirmation 方法中获取保存图像的路径:
var src = $get("<%= UploadedPathHiddenField.ClientID %>").value;
..................................................... ..................................................... .
protected void BtnUpload_Click(object sender, EventArgs e)
{
UploadMessage.Text = UploadedPathHiddenField.Value;
}