文件下载问题!下载WORD文档后,在客户端打开后是一堆乱码,请高手指教,代码如下 Response.ContentType = "application/msword"; 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 给你个文件下载的例子!using System;using System.IO;using System.Runtime.InteropServices;using System.Text;using System.Net; using System.Threading;namespace Sx_Mdi{ /// <summary> /// Summary description for Class1. /// </summary> public class CIniFile { //文件INI名称 public string Path; ////声明读写INI文件的API函数 [DllImport("kernel32")] private static extern long WritePrivateProfileString(string section,string key,string val,string filePath); [DllImport("kernel32")] private static extern int GetPrivateProfileString(string section,string key,string def,StringBuilder retVal,int size,string filePath); //类的构造函数,传递INI文件名 public CIniFile(string inipath) { // // TODO: Add constructor logic here // Path = inipath; } //写INI文件 public void IniWriteValue(string Section,string Key,string Value) { WritePrivateProfileString(Section,Key,Value,this.Path); } //读取INI文件指定 public string IniReadValue(string Section,string Key) { StringBuilder temp = new StringBuilder(255); int i = GetPrivateProfileString(Section,Key,"",temp,255,this.Path); return temp.ToString(); } } public class CDownLoadFile { public string strSrcPath; public string strTargetPath; private WebClient client = new WebClient(); public CDownLoadFile() { strSrcPath = ""; strTargetPath = ""; } public CDownLoadFile(string strSrc,string strTarget) { strSrcPath = strSrc; strTargetPath = strTarget; } public string StartDownload() { string URL = strSrcPath; int n = URL.LastIndexOf('/'); string URLAddress = URL;//.Substring(0,n); string fileName = URL.Substring(n+1,URL.Length-n-1); string Dir = strTargetPath; string Path = Dir+'\\'+fileName; try { WebRequest myre=WebRequest.Create(URLAddress); } catch(WebException exp) { return exp.Message; } try { //"开始下载文件..."; client.DownloadFile(URLAddress,fileName); Stream str = client.OpenRead(URLAddress); StreamReader reader = new StreamReader(str); byte[] mbyte = new byte[1000000]; int allmybyte = (int)mbyte.Length; int startmbyte = 0; //"正在接收数据..."; while(allmybyte>0) { int m = str.Read(mbyte,startmbyte,allmybyte); if(m==0) break; startmbyte+=m; allmybyte-=m; } FileStream fstr = new FileStream(Path,FileMode.OpenOrCreate ,FileAccess.Write); fstr.Write(mbyte,0,startmbyte); str.Close(); fstr.Close(); } catch(WebException exp) { return exp.Message; // ""; } return ""; } }} 请问?byte[] file = (byte[])dbValue中,dbValue如何定义?Response.BinaryWrite(file)作用是什么? 谁用过ckfinder的?用过的童鞋进来一下~~~求教~~~~ Jquery 里面的 ajax获取数据后 填充select 应该怎么写? jquery如何同时操作一个属性的多个值? 附上(动态在datagrid中添加button的实现)...有的问题现在?(猛送分) 急救啊!! 网页中的标题只让他显示10,其它的都用点来显示 C#如何编辑XML文件 如何在两个dropdownlist里分别绑定父记录和子记录? 都是frameworks1.1惹的祸!!(关于舍零的问题) QucikStart下载后咋不会安装呢? 1500多分,问个小问题散分 水晶报表问题,各位大侠救救我!
using System;
using System.IO;
using System.Runtime.InteropServices;
using System.Text;
using System.Net;
using System.Threading;namespace Sx_Mdi
{ /// <summary>
/// Summary description for Class1.
/// </summary>
public class CIniFile
{
//文件INI名称
public string Path;
////声明读写INI文件的API函数
[DllImport("kernel32")]
private static extern long WritePrivateProfileString(string section,string key,string val,string filePath);
[DllImport("kernel32")] private static extern int GetPrivateProfileString(string section,string key,string def,StringBuilder retVal,int size,string filePath); //类的构造函数,传递INI文件名
public CIniFile(string inipath)
{
//
// TODO: Add constructor logic here
//
Path = inipath;
} //写INI文件
public void IniWriteValue(string Section,string Key,string Value)
{
WritePrivateProfileString(Section,Key,Value,this.Path);
} //读取INI文件指定
public string IniReadValue(string Section,string Key)
{
StringBuilder temp = new StringBuilder(255);
int i = GetPrivateProfileString(Section,Key,"",temp,255,this.Path);
return temp.ToString();
}
}
public class CDownLoadFile
{
public string strSrcPath;
public string strTargetPath;
private WebClient client = new WebClient();
public CDownLoadFile()
{
strSrcPath = "";
strTargetPath = "";
}
public CDownLoadFile(string strSrc,string strTarget)
{
strSrcPath = strSrc;
strTargetPath = strTarget;
}
public string StartDownload()
{
string URL = strSrcPath;
int n = URL.LastIndexOf('/');
string URLAddress = URL;//.Substring(0,n);
string fileName = URL.Substring(n+1,URL.Length-n-1);
string Dir = strTargetPath;
string Path = Dir+'\\'+fileName; try
{
WebRequest myre=WebRequest.Create(URLAddress);
}
catch(WebException exp)
{
return exp.Message;
} try
{
//"开始下载文件...";
client.DownloadFile(URLAddress,fileName);
Stream str = client.OpenRead(URLAddress);
StreamReader reader = new StreamReader(str);
byte[] mbyte = new byte[1000000];
int allmybyte = (int)mbyte.Length;
int startmbyte = 0;
//"正在接收数据...";
while(allmybyte>0)
{
int m = str.Read(mbyte,startmbyte,allmybyte);
if(m==0)
break; startmbyte+=m;
allmybyte-=m;
} FileStream fstr = new FileStream(Path,FileMode.OpenOrCreate ,FileAccess.Write);
fstr.Write(mbyte,0,startmbyte);
str.Close();
fstr.Close();
}
catch(WebException exp)
{
return exp.Message;
// "";
} return "";
} }}
byte[] file = (byte[])dbValue中,dbValue如何定义?
Response.BinaryWrite(file)作用是什么?