asp.net使用ajax.dll后,如何再写图片上传????急急急!!跪求高手请进!!! 是的,你这种方法注定要失败,据我所知 XmlHttp( AjaxPro封装了的)只能上传文本,但是图片需要以二进制流格式上传 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 codeproject上有用ajax技术上传图片的sample <%@ Page Language="C#" %><!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"><script runat="server"> private string saveDir = @"Uploads\"; protected void UploadButton_Click(object sender, EventArgs e) { if (FileUpload1.HasFile && FileUpload1.FileBytes.Length < 10000 && !CheckForFileName()) { string savePath = Request.PhysicalApplicationPath + saveDir + Server.HtmlEncode(FileName.Text); //Remove comment from the next line to upload file. //FileUpload1.SaveAs(savePath); UploadStatusLabel.Text = "The file was processed successfully."; } else { UploadStatusLabel.Text = "You did not specify a file to upload, or a file name, or the file was too large. Please try again."; } } protected void CheckButton_Click(object sender, EventArgs e) { if (FileName.Text.Length > 0) { string s = CheckForFileName() ? "exists already." : "does not exist."; UploadStatusLabel.Text = "The file name choosen " + s; } else { UploadStatusLabel.Text = "Specify a file name to check."; } } private Boolean CheckForFileName() { System.IO.FileInfo fi = new System.IO.FileInfo(Request.PhysicalApplicationPath + saveDir + Server.HtmlEncode(FileName.Text)); return fi.Exists; }</script><html xmlns="http://www.w3.org/1999/xhtml" ><head id="Head1" runat="server"> <title>PostBackTrigger Example</title></head><body> <form id="form1" runat="server"> <div> <asp:ScriptManager ID="ScriptManager1" runat="server" /> The upload button is defined as a PostBackTrigger.<br/> <asp:UpdatePanel ID="UpdatePanel1" UpdateMode="Conditional" runat="server"> <ContentTemplate> <fieldset> <legend>FileUpload in an UpdatePanel</legend> First, enter a file name to upload your file to: <asp:TextBox ID="FileName" runat="server" /> <asp:Button ID="CheckButton" Text="Check" runat="server" OnClick="CheckButton_Click" /> <br /> Then, browse and find the file to upload: <asp:FileUpload id="FileUpload1" runat="server"> </asp:FileUpload> <br /> <asp:Button id="UploadButton" Text="Upload file" OnClick="UploadButton_Click" runat="server"> </asp:Button> <br /> <asp:Label id="UploadStatusLabel" runat="server" style="color:red;"> </asp:Label> </fieldset> </ContentTemplate> <Triggers> <asp:PostBackTrigger ControlID="UploadButton" /> </Triggers> </asp:UpdatePanel> </div> </form></body></html> MVC3 Create页面中动态增加一行 如何进行数据验证? 插上网线后网页打开极慢,拔掉网线后速度正常。 我太笨了!!看看 吧 请问如何学习asp.net 关于上传网站的问题 iframe runat="server" 怎么自動適應大小? 一个网站多个ASP.NET程序 如何做字幕的滚动效果? 字符串的问题(在线等) 一个想不通的问题,初学者,请多指教^_^ 小弟遇到奇怪的问题了,在线等高手帮忙!! 发布网站后怎么运行不起呢
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"><script runat="server"> private string saveDir = @"Uploads\";
protected void UploadButton_Click(object sender, EventArgs e)
{
if (FileUpload1.HasFile && FileUpload1.FileBytes.Length < 10000 &&
!CheckForFileName())
{
string savePath = Request.PhysicalApplicationPath + saveDir +
Server.HtmlEncode(FileName.Text);
//Remove comment from the next line to upload file.
//FileUpload1.SaveAs(savePath);
UploadStatusLabel.Text = "The file was processed successfully.";
}
else
{
UploadStatusLabel.Text = "You did not specify a file to upload, or a file name, or the file was too large. Please try again.";
}
} protected void CheckButton_Click(object sender, EventArgs e)
{
if (FileName.Text.Length > 0)
{
string s = CheckForFileName() ? "exists already." : "does not exist.";
UploadStatusLabel.Text = "The file name choosen " + s;
}
else
{
UploadStatusLabel.Text = "Specify a file name to check.";
}
}
private Boolean CheckForFileName()
{
System.IO.FileInfo fi = new System.IO.FileInfo(Request.PhysicalApplicationPath +
saveDir + Server.HtmlEncode(FileName.Text));
return fi.Exists;
}</script><html xmlns="http://www.w3.org/1999/xhtml" >
<head id="Head1" runat="server">
<title>PostBackTrigger Example</title>
</head>
<body>
<form id="form1" runat="server">
<div>
<asp:ScriptManager ID="ScriptManager1" runat="server" />
The upload button is defined as a PostBackTrigger.<br/>
<asp:UpdatePanel ID="UpdatePanel1" UpdateMode="Conditional" runat="server">
<ContentTemplate>
<fieldset>
<legend>FileUpload in an UpdatePanel</legend>
First, enter a file name to upload your file to:
<asp:TextBox ID="FileName" runat="server" />
<asp:Button ID="CheckButton" Text="Check" runat="server" OnClick="CheckButton_Click" />
<br />
Then, browse and find the file to upload:
<asp:FileUpload id="FileUpload1"
runat="server">
</asp:FileUpload>
<br />
<asp:Button id="UploadButton"
Text="Upload file"
OnClick="UploadButton_Click"
runat="server">
</asp:Button>
<br />
<asp:Label id="UploadStatusLabel"
runat="server" style="color:red;">
</asp:Label>
</fieldset>
</ContentTemplate>
<Triggers>
<asp:PostBackTrigger ControlID="UploadButton" />
</Triggers>
</asp:UpdatePanel>
</div>
</form>
</body>
</html>