asp.net框架代码下载(aspnet web框架)
admin 发布:2022-12-19 22:49 102
今天给各位分享asp.net框架代码下载的知识,其中也会对aspnet web框架进行解释,如果能碰巧解决你现在面临的问题,别忘了关注本站,现在开始吧!
本文目录一览:
- 1、asp.net如何使用框架
- 2、ASP.NET 中,实现download下载,弹出打开和保存对话框,不限制文件大小,跪求实现代码,谢谢了
- 3、asp.net 如何实现将服务器上的文件下载到本地?
- 4、ASP.NET下载功能代码
- 5、我用的是winxp系统,想装ASP.net但不知道怎样下载那个框架!急于求助!!!
asp.net如何使用框架
在一个页面中设置右边的框架iframe id="Right" name="Right" src="123.aspx"/iframe
点击左边框架的查询按钮,加入javascript代码: parent.document.getElementById("Right").src="123.aspx?"+parameters;
ASP.NET 中,实现download下载,弹出打开和保存对话框,不限制文件大小,跪求实现代码,谢谢了
思路很简单,读取服务器文件路径,然后再保存数据流,下面是实现代码:
(ps:因为要上班,来不及写很多注释,关键的地方加了几句注释哈)
using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using YTLib.Basic;
using YTLib.YTDBC;
using System.IO;
using System.Threading;
namespace siteadmin.admin
{
public partial class downfile : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
string strSQL = "";
YTNDBObject dbo = new YTNDBObject();
dbo.DataName = "Main";
Page.EnableViewState = false;
if(!IsPostBack)
{
string sid=Request["id"];
if(!YTLib.publicOP.IsNumString(sid)||sid==null)
sid="0";
strSQL = "select * from FileSource where ID=@ID";
dbo.PrepareCommand(strSQL);
dbo.SetCmdIntValue("@ID",int.Parse(sid));
DataTable dt=dbo.QueryData().Tables[0];
string sourceName = (string)dt.Rows[0]["FilePath"];
sourceName.Trim();//消除空格
string filesnames = sourceName.Substring(7, sourceName.Length - 8);
int index= sourceName.LastIndexOf(".");
string extend = sourceName.Substring(index+1);//扩展名
string fullPath = "~/uploaded/" + sourceName;
fullPath = Server.MapPath(fullPath);
//读出该资源的下载次数
int downloadtimes = 0;
downloadtimes = int.Parse(dt.Rows[0]["downloadCounts"].ToString());
Page.Response.Clear();
bool success = ResponseFile(Page.Request, Page.Response, filesnames, fullPath, 1024000);
if (!success) Response.Write("script language=\"javascript\"alert(\"Download file error\");window.location.href=\"../Download.aspx\"/script");
else
{
//记录下载次数
downloadtimes++;
string sqlStr = "update FileSource set downloadCounts=" + downloadtimes + " where ID=@IID";
dbo.PrepareCommand(sqlStr);
dbo.SetCmdIntValue("@IID",int.Parse(sid));
dbo.ExecuteNoQuery();
}
Response.Write("script language=\"javascript\"window.location.href=\"../Download.aspx\"/script");
}
}
public static bool ResponseFile(HttpRequest _Request, HttpResponse _Response, string _fileName, string _fullPath, long _speed)
{
try
{
FileStream myFile = new FileStream(_fullPath, FileMode.Open, FileAccess.Read, FileShare.ReadWrite);
BinaryReader br = new BinaryReader(myFile);
try
{
_Response.AddHeader("Accept-Ranges", "bytes");
_Response.Buffer = false;//不缓冲
long fileLength = myFile.Length;
long startBytes = 0;
double pack = 10240;
//10K bytes
int sleep = 200;
//每秒5次 即5*10K bytes每秒 int sleep = (int)Math.Floor(1000 * pack / _speed) + 1;
if (_Request.Headers["Range"] != null)
{
_Response.StatusCode = 206;
string[] range = _Request.Headers["Range"].Split(new char[] { '=', '-' });
startBytes = Convert.ToInt64(range[1]);
}
_Response.AddHeader("Content-Length", (fileLength - startBytes).ToString());
if (startBytes != 0)
{
//Response.AddHeader("Content-Range", string.Format(" bytes {0}-{1}/{2}", startBytes, fileLength-1, fileLength));
}
_Response.AddHeader("Connection", "Keep-Alive");
_Response.ContentType = "application/octet-stream";
_Response.AddHeader("Content-Disposition", "attachment; filename=" + HttpUtility.UrlEncode(_fileName, System.Text.Encoding.UTF8));
br.BaseStream.Seek(startBytes, SeekOrigin.Begin);
int maxCount = (int)Math.Floor((fileLength - startBytes) / pack) + 1;
for (int i = 0; i maxCount; i++)
{
if (_Response.IsClientConnected)
{
_Response.BinaryWrite(br.ReadBytes(int.Parse(pack.ToString())));
Thread.Sleep(sleep);
}
else
{
i = maxCount;
}
}
}
catch
{
return false;
}
finally
{
br.Close();
myFile.Close();
}
}
catch
{
return false;
}
return true;
}
}
}
asp.net 如何实现将服务器上的文件下载到本地?
给你提供一点代码:
string fileURL = this.Server.MapPath("你要下载的文件路径");//文件路径,可用相对路径
FileInfo fileInfo = new FileInfo(fileURL);
Response.Clear();
Response.AddHeader("content-disposition", "attachment;filename=" +
Server.UrlEncode(fileInfo.Name.ToString()));//文件名
Response.AddHeader("content-length", fileInfo.Length.ToString());//文件大小
Response.ContentType = "application/octet-stream";
Response.ContentEncoding = System.Text.Encoding.Default;
Response.WriteFile(fileURL);
ASP.NET下载功能代码
给你写个方法,你直接调用一下就可以了
public void DownLoad( )
{
string filePath = Server.MapPath( @"\UserFile\" );//这里注意了,你得指明要下载文件的路径.
if ( System.IO.File.Exists( filePath ) )
{
FileInfo file = new FileInfo( filePath );
Response.ContentEncoding = System.Text.Encoding.GetEncoding( "UTF-8" ); //解决中文乱码
Response.AddHeader( "Content-Disposition", "attachment; filename=" + Server.UrlEncode( file.Name ) ); //解决中文文件名乱码
Response.AddHeader( "Content-length", file.Length.ToString() );
Response.ContentType = "appliction/octet-stream";
Response.WriteFile( file.FullName );
Response.End();
}
}
希能给你带来帮助
我用的是winxp系统,想装ASP.net但不知道怎样下载那个框架!急于求助!!!
去microsoft 下载中心,搜寻Freamworks的下载。有1.0,2.0,3.0和3.5四个版本。每个版本都有SP更新包。
asp.net框架代码下载的介绍就聊到这里吧,感谢你花时间阅读本站内容,更多关于aspnet web框架、asp.net框架代码下载的信息别忘了在本站进行查找喔。
版权说明:如非注明,本站文章均为 AH站长 原创,转载请注明出处和附带本文链接;
相关推荐
- 05-06aspnet免费代码(ASPNET源码)[20240506更新]
- 05-06.net贴吧源代码的简单介绍[20240506更新]
- 05-06网页代码form什么意思(web中form)[20240506更新]
- 05-06asp跳转代码怎么写(asp网页跳转)[20240506更新]
- 05-05asp代码(ASP代码转换器)[20240505更新]
- 05-05asp.net输出html代码(html5 asp)[20240505更新]
- 05-05人工智能系统源代码(人工智能代码下载)[20240505更新]
- 05-05qq服务器代码下载(服务器怎么下载)[20240505更新]
- 05-05androidone代码下载(安卓app代码)[20240505更新]
- 05-04网页代码下载html(网页代码下载音乐)[20240504更新]
取消回复欢迎 你 发表评论:
- 标签列表
- 最近发表
- 友情链接