asp.net网站上传到空间后,.exe 下载不了,但是.doc的却可以下载成功 asp.net网站上传到空间后,.exe 下载不了,但是.doc的却可以下载成功这是怎么回事??? 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 用流输出来下载 DataSet ds = db.GetDataSet(query, new string[] { "@id" }, new object[] { DNTRequest.GetInt("id", 0) }); if (ds != null && ds.Tables[0].Rows.Count > 0) { db.ExecuteUpdate("Update GL_Files Set hits=hits + 1 Where id=@id", new string[] { "@id" }, new object[] { DNTRequest.GetInt("id", 0) }); string url = ds.Tables[0].Rows[0]["url"].ToString(); string filename = ds.Tables[0].Rows[0]["FileTitle"].ToString() + "." + ds.Tables[0].Rows[0]["FileExt"].ToString(); using (FileStream fso = new FileStream(Server.MapPath(url), FileMode.Open, FileAccess.Read, FileShare.Read)) { int len = Convert.ToInt32(fso.Length); byte[] FileObj = new byte[len]; fso.Read(FileObj, 0, len); Response.AddHeader("Content-Disposition", string.Format("attachment; filename={0}", HttpUtility.UrlEncode(filename), System.Text.Encoding.UTF8)); Response.AddHeader("Content-Length", len.ToString()); Response.ContentType = "application/octet-stream"; Response.Charset = "UTF-8"; Response.ContentEncoding = System.Text.Encoding.UTF8; Response.BinaryWrite(FileObj); Response.Flush(); Response.Clear(); fso.Close(); } } #region 二进制下载 private void FN_ResponseFile() { string id = Request["id"].ToString();//获取资源的编号 System.IO.Stream iStream = null; byte[] buffer = new Byte[10000]; int length; long dataToRead; NRBLL.File bf = new Asiastar.NRBLL.File(); Guid guid = new Guid(id); if (bf.FN_SerchPathByFileId(guid).Tables[0].Rows[0]["FilePath"] != null)//判断数据库路径是否存在 { string filepath = bf.FN_SerchPathByFileId(guid).Tables[0].Rows[0]["FilePath"].ToString();//获取资源完整路径 string filename = System.IO.Path.GetFileName(filepath);//获取资源名称 try { string fileName = HttpUtility.UrlEncode(System.Text.Encoding.UTF8.GetBytes(filename));//解码(注意这里2层解码) filename = filename.Replace("+", "%20"); //将“+”替换成“空格” iStream = new System.IO.FileStream(filepath, System.IO.FileMode.Open, System.IO.FileAccess.Read, System.IO.FileShare.Read); dataToRead = iStream.Length; Response.ContentType = "application/octet-stream"; Response.AddHeader("Content-Disposition", "attachment; filename=" + HttpUtility.UrlEncode(filename, System.Text.Encoding.UTF8)); while (dataToRead > 0) { if (Response.IsClientConnected) { length = iStream.Read(buffer, 0, 10000); Response.OutputStream.Write(buffer, 0, length); Response.Flush(); buffer = new Byte[10000]; dataToRead = dataToRead - length; } else { dataToRead = -1; } } } catch (Exception) { Response.Write("找不到该文件!"); } finally { if (iStream != null) { iStream.Close(); } } } else { Response.Write("找不到该文件!"); } } #endregion你数据库保存的是不是完整路径 如果是用我这个 记得想让下载.exe是需要配置IIS的 是服务器设置的问题吧。exe文件,很危险。。 感谢是服务器配置的问题,可能是服务器安装了MAF 还是没解决!.exe,.rar,.zip格式都不能下载,但.doc,.txt可以下载,怎么解决,望高人快出手啊! function IMG1_onclick() { public void DownLoad( ){ string filePath = Server.MapPath( @"\hmj_360.zip");//这里注意了,你得指明要下载文件的路径. 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(); }}这是我的类 <div class="foot1"><img src="images/foot2.gif" border="0" usemap="#Map" id="IMG1" /><map name="Map" id="Map"><area shape="rect" coords="818,156,925,214" href="hmj_360.zip"/></map></div> 这是我的调用! 支持这个,应该是IIS里面的MINE没有配置好 .net 三层架构问题,不知道错误出现在哪儿,急!!! GridView怎么样获得选中的行的一列的值?高手指教!! 附加数据库时总是报错 page_load()不起作用? 当DataGrid 自动创建列时,怎样去控制列的宽度?? 一个小的算法,看看你的脑子是否还灵光 请教一下连结数据库时的几种方法的细节问题。 请教大侠 紧急求教:LABEL控件调用SQL内容在IE无法显示段落问题 在aspx網頁中用樣式表css得不到預想的結果 asp.net 自定义配置文件 出错,高分求救~~~在线等啊~~~~谢谢各位了~ 一个奇怪,很BT的问题
if (ds != null && ds.Tables[0].Rows.Count > 0)
{
db.ExecuteUpdate("Update GL_Files Set hits=hits + 1 Where id=@id", new string[] { "@id" }, new object[] { DNTRequest.GetInt("id", 0) });
string url = ds.Tables[0].Rows[0]["url"].ToString();
string filename = ds.Tables[0].Rows[0]["FileTitle"].ToString() + "." + ds.Tables[0].Rows[0]["FileExt"].ToString();
using (FileStream fso = new FileStream(Server.MapPath(url), FileMode.Open, FileAccess.Read, FileShare.Read))
{
int len = Convert.ToInt32(fso.Length);
byte[] FileObj = new byte[len];
fso.Read(FileObj, 0, len);
Response.AddHeader("Content-Disposition", string.Format("attachment; filename={0}", HttpUtility.UrlEncode(filename), System.Text.Encoding.UTF8));
Response.AddHeader("Content-Length", len.ToString());
Response.ContentType = "application/octet-stream";
Response.Charset = "UTF-8";
Response.ContentEncoding = System.Text.Encoding.UTF8;
Response.BinaryWrite(FileObj);
Response.Flush();
Response.Clear();
fso.Close();
}
}
#region 二进制下载
private void FN_ResponseFile()
{
string id = Request["id"].ToString();//获取资源的编号
System.IO.Stream iStream = null;
byte[] buffer = new Byte[10000];
int length;
long dataToRead;
NRBLL.File bf = new Asiastar.NRBLL.File();
Guid guid = new Guid(id);
if (bf.FN_SerchPathByFileId(guid).Tables[0].Rows[0]["FilePath"] != null)//判断数据库路径是否存在
{
string filepath = bf.FN_SerchPathByFileId(guid).Tables[0].Rows[0]["FilePath"].ToString();//获取资源完整路径
string filename = System.IO.Path.GetFileName(filepath);//获取资源名称 try
{
string fileName = HttpUtility.UrlEncode(System.Text.Encoding.UTF8.GetBytes(filename));//解码(注意这里2层解码)
filename = filename.Replace("+", "%20"); //将“+”替换成“空格”
iStream = new System.IO.FileStream(filepath, System.IO.FileMode.Open, System.IO.FileAccess.Read, System.IO.FileShare.Read);
dataToRead = iStream.Length;
Response.ContentType = "application/octet-stream";
Response.AddHeader("Content-Disposition", "attachment; filename=" + HttpUtility.UrlEncode(filename, System.Text.Encoding.UTF8));
while (dataToRead > 0)
{
if (Response.IsClientConnected)
{
length = iStream.Read(buffer, 0, 10000);
Response.OutputStream.Write(buffer, 0, length); Response.Flush();
buffer = new Byte[10000];
dataToRead = dataToRead - length;
}
else
{
dataToRead = -1;
}
} }
catch (Exception)
{
Response.Write("找不到该文件!");
}
finally
{
if (iStream != null)
{
iStream.Close();
}
}
}
else
{
Response.Write("找不到该文件!");
}
}
#endregion你数据库保存的是不是完整路径 如果是用我这个
public void DownLoad( )
{
string filePath = Server.MapPath( @"\hmj_360.zip");//这里注意了,你得指明要下载文件的路径. 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();
}
}
这是我的类
<map name="Map" id="Map"><area shape="rect" coords="818,156,925,214" href="hmj_360.zip"/>
</map></div> 这是我的调用!
支持这个,应该是IIS里面的MINE没有配置好