try the following, didn't test, so it might not work1. change DataBinder.Eval(Container.DataItem, "filename") toHttpUtility.UrlEncode(DataBinder.Eval(Container.DataItem, "filename").ToString(),System.Text.Encoding.GetEncoding("GB2312"))2. Response.AddHeader("Content-Disposition", "attachment; filename=" + System.Text.Encoding.UTF8.UrlEncode(HttpUtility.UrlDecode(Request.QueryString["filename"],System.Text.Encoding.GetEncoding("GB2312")));
System.Drawing.Image image,newimage; //定义image类的对象
protected string imagePath; //图片路径
protected string imageType; //图片类型
protected string imageName;
protected System.Web.UI.WebControls.RadioButtonList choice; //图片名称
System.Drawing.Image.GetThumbnailImageAbort callb =null; //提供一个回调方法,用于确定Image对象在执行生成缩略图操作时何时提前取消执行,如果此方法确定GetThumbnailImage方法应提前停止执行,则返回true,否则返回false
CODE: [Copy to clipboard]
--------------------------------------------------------------------------------private void btn_upload_Click(object sender, System.EventArgs e)
{
string mPath,img_source,img_small;
string pid = Request.QueryString["pid"];
string typeid = Request.QueryString["typeid"];
string typef = Request.QueryString["typef"]; if(""!= upImage.PostedFile.FileName)
{
imagePath = upImage.PostedFile.FileName;
//取得图片类型
imageType = imagePath.Substring(imagePath.LastIndexOf(".")+1);
//取得图片名称
imageName = DateTime.Now.Year.ToString()+DateTime.Now.Month.ToString()+DateTime.Now.Day.ToString()+DateTime.Now.Hour.ToString()+DateTime.Now.Minute.ToString()+DateTime.Now.Second.ToString()+imagePath.Substring(imagePath.LastIndexOf("\\")+1);
if("jpg"!= imageType && "gif"!= imageType )
{
Response.Write("<script language='javascript'>alert('对不起!请您选择jpg或者gif格式的图片!');</script>");
return;
}
else
{
mPath = Server.MapPath("../../picture"); //建立虚拟路径
upImage.PostedFile.SaveAs(mPath+"\\"+imageName); //保存到虚拟路径
img_source = "picture/" + imageName; //显示原图
image = System.Drawing.Image.FromFile(mPath+"\\"+imageName); //为上传的图片建立引用
newimage = image.GetThumbnailImage(184,148,callb,new System.IntPtr()); //生成缩略图
newimage.Save(Server.MapPath("../../picture")+"\\small"+imageName); //把缩略图保存到指定的虚拟路径
image.Dispose(); //释放image对象占用的资源
newimage.Dispose(); //释放newimage对象的资源
img_small = "picture/" + "small" + imageName; //显示缩略图
string imgid = pub.AddImage(txt_name.Text,img_source,img_small,txt_author.Text,Int32.Parse(pid),Int32.Parse(typeid));
if (imgid != "")
{
string UserChoice = choice.SelectedValue;
switch(UserChoice)
{
case "1":
Response.Redirect ("index.aspx?typeid="+typeid+"&typef="+typef+"&pid="+pid+"");
break;
case "2":
{
txt_name.Text = "";
txt_author.Text = "";
}
break;
}
}
else
{
txtMessage.Text ="不好意思,上传图片失败!"; }
}
}
}
Response.AddHeader("Content-Disposition", "attachment; filename=\"" + YourFileNameHere + "\"");
<ItemTemplate>
<a href='<%#String.Format("../uploadfile/{0}", DataBinder.Eval(Container.DataItem, "filename"))%>' target=_blank><%#String.Format("{0}", DataBinder.Eval(Container.DataItem, "filename"))%></a>
</ItemTemplate>
</asp:TemplateColumn>思归,我写的下载的语句是这样的,请问你写的是什么意思啊?
string filename = Server.MapPath("../uploadfile/" + s);
Response.ContentType = "application/octet-stream";
Response.AddHeader("Content-Disposition", "attachment; filename=\" + Request.QueryString["originfile"] + "\"");
Response.WriteFile(filename);
Response.End();
<ItemTemplate>
<a href='<%#String.Format("download.aspx?file={0}&filename={1}", DataBinder.Eval(Container.DataItem, "filename"), DataBinder.Eval(Container.DataItem, "filename"))%>' target=_blank><%#String.Format("{0}", DataBinder.Eval(Container.DataItem, "filename2"))%></a>
</ItemTemplate>
</asp:TemplateColumn>
---------------------------------------
string s = Request.QueryString["filename"];
string filename = Server.MapPath("../uploadfile/" + s);
Response.ContentType = "application/octet-stream";
Response.AddHeader("Content-Disposition", "attachment; filename=" + Request.QueryString["filename"]);
Response.WriteFile(filename);
Response.End();如果保存的是英文名字就正常保存为英文名字.
但如果保存的是中文名字就是
CABI8RNT.
这样的?
而且每次点击显示的都不同
为什么啊?
行 40: string s = Request.Params["filename"];
行 41: string filename = Server.MapPath("../uploadfile/" + s);如果:
string filename = Server.MapPath("../uploadfile/護具一廠一課細排程.xls");
那么这样是可以下载,但会让繁体数据库里的繁体字(个别繁体字)变成乱码啊
行 41: string filename = Server.MapPath("../uploadfile/" + s);
就可以下载,为什么?<asp:TemplateColumn HeaderText="下載" SortExpression="filename"> <ItemTemplate>
<a href='<%#String.Format("../uploadfile/{0}", DataBinder.Eval(Container.DataItem, "filename"))%>' target=_blank title="下載"><%#String.Format("{0}", DataBinder.Eval(Container.DataItem, "filename"))%></a>
</ItemTemplate>
</asp:TemplateColumn>
为什么这样不会出现乱码呢,我的意思是字体没有问题,不会有简体字.这点你放心.
2. in download.aspx:string s = Request.Params["filename"];
string filename = Server.MapPath("../uploadfile/" + HttpUtility.UrlDecode(s)));...
Response.AddHeader("Content-Disposition", "attachment; filename=" + s);?