日期:2014-05-17 浏览次数:20502 次
System.IO.FileInfo file = new System.IO.FileInfo(fileName); if (file.Exists) { System.IO.FileStream fs = null; fs = System.IO.File.Open(fileName, System.IO.FileMode.Open); byte[] btFile = new byte[fs.Length]; fs.Read(btFile, 0, Convert.ToInt32(fs.Length)); fs.Close(); System.Web.HttpContext.Current.Response.Clear(); System.Web.HttpContext.Current.Response.AddHeader("Content-Disposition", "attachment; filename=" + file.Name); System.Web.HttpContext.Current.Response.AddHeader("Content-Length", file.Length.ToString()); System.Web.HttpContext.Current.Response.ContentType = "audio/mpeg3"; System.Web.HttpContext.Current.Response.BinaryWrite(btFile); } else { System.Web.HttpContext.Current.Response.Write("This file does not exist."); }
------解决方案--------------------
2)用hyperlink转到数据处理页,存储数据,用response.redirect("test.asp");转向链接页面,但也有问题,我的链接页面数据是从别人的数据库以xml形式得到的,如果只传ID,需要重新查找数据,运行很慢;如果所有数据都传过来,链接地址串又会超常,而且有非法字符。
可以考虑用session传值
数据不是很大的话也可以用cookie
------解决方案--------------------
<form id="form1" runat="server"> <asp:ScriptManager ID="ScriptManager1" runat="server" ScriptMode="Debug"> <Services> <asp:ServiceReference Path="WebServiceFoundation.asmx" InlineScript="true" /> </Services> </asp:ScriptManager> <input type="button" value="Get Random" onclick="getRandom()" /> <input type="button" value="Get Range Random" onclick="getRandom(0, 9)" /> <script language="javascript" type="text/javascript"> function getRandom(minValue, maxValue) { if (arguments.length != 2) { Sample.WebServiceFoundation.GetRandom(getRandomSucceeded); } else { Sample.WebServiceFoundation.GetRangeRandom(minValue, maxValue, getRandomSucceeded); } } function getRandomSucceeded(result) { alert(result); } </script> </form>