我正在使用asyncfileupload
控件,我只想接受图像。我使用了accept属性,但它没有用,并使用OnClientUploadComplete
事件来捕获内容类型并停止在服务器端上传,事件没有触发并导致OnUploadedComplete
也没有触发!而且我不知道如何阻止它在服务器端上传。我试图检查contentType
OnUploadedComplete
事件中的`protected void fileUpload_UploadedComplete(object sender, AjaxControlToolkit.AsyncFileUploadEventArgs e)
{
if (fuImage.HasFile)
{
string contentType = fuImage.ContentType;
if (contentType == "image/jpeg" || contentType == "image/gif"
|| contentType == "image/png")
{
string fileName = Path.GetFileName(e.FileName);
string fileUploadPath = Path.Combine(Server.MapPath("~/images/Resturant"), fileName);
fuImage.SaveAs(fileUploadPath);
var url = "~/images/Resturant/" + fileName;
ScriptManager.RegisterStartupScript(this, this.GetType(), "fileName",
"top.$get(\"" + hdfImagePath.ClientID + "\").value = '" + url + "';", true);
}
else
{
ucMessage1.MessageTitle = "Error Message";
ucMessage1.MessageDetail = "Please Choose a valid image!";
ucMessage1.MessageImage = "X";
ucMessage1.Show();
}
}
}`
,它会触发并转到'其他'但它没有显示它应该显示的消息。有什么建议吗?
C#代码:
<ajaxToolkit:AsyncFileUpload ID="fuImage" runat="server" OnUploadedComplete="fileUpload_UploadedComplete" />
设计
grep -v [a-z] test
答案 0 :(得分:0)
文件成功上传后,UploadedComplete
事件在服务器端触发,这意味着在上传文件扩展名之前无法检查文件扩展名。