RT,
最近开始搞一个多文件上传的问题,将案例引入到项目中的时候,出现了文件名称乱码的问题?
不知道各位遇到过没有?
1.自己检查了这个项目的编码格式web.config都写写好的,<globalization requestEncoding="gb2312" responseEncoding="gb2312" fileEncoding="gb2312"/>2.页面文件的编码:<%@ Page Language="C#" ResponseEncoding="gb2312" <meta content="text/html; charset=gb2312" http-equiv="Content-Type">
3.将页面文件用TXT打开重新设置了保存时的编码为: UTF-8
共有(ANSI,UTF-8,Unicode,Unicode big endia)4.
这个是案例的项目结构,他将 FileUpload 封装为了一个类库。 public class FlashUpload : Control
{
private const string FLASH_SWF = "FlashUpload.FlashFileUpload.swf"; [Category("Behavior")]
[Description("The page to upload files to.")]
[DefaultValue("")]
public string UploadPage
{
get
{
object o = ViewState["UploadPage"];
if (o == null)
return "";
return o.ToString();
}
set { ViewState["UploadPage"] = value; }
} [Category("Behavior")]
[Description("Query Parameters to pass to the Upload Page.")]
[DefaultValue("")]
public string QueryParameters
{
get
{
object o = ViewState["QueryParameters"];
if (o == null)
return "";
return o.ToString();
}
set { ViewState["QueryParameters"] = value; }
} [Category("Behavior")]
[Description("Javascript function to call when all files are uploaded.")]
[DefaultValue("")]
public string OnUploadComplete
{
get
{
object o = ViewState["OnUploadComplete"];
if (o == null)
return "";
return o.ToString();
}
set { ViewState["OnUploadComplete"] = value; }
} [Category("Behavior")]
[Description("The maximum file size that can be uploaded, in bytes (0 for no limit).")]
public decimal UploadFileSizeLimit
{
get
{
object o = ViewState["UploadFileSizeLimit"];
if (o == null)
return 0;
return (decimal)o;
}
set { ViewState["UploadFileSizeLimit"] = value; }
} [Category("Behavior")]
[Description("The total number of bytes that can be uploaded (0 for no limit).")]
public decimal TotalUploadSizeLimit
{
get
{
object o = ViewState["TotalUploadSizeLimit"];
if (o == null)
return 0;
return (decimal)o;
}
set { ViewState["TotalUploadSizeLimit"] = value; }
} [Category("Behavior")]
[Description("The description of file types that you want uploads restricted to (ex. Images (*.JPG;*.JPEG;*.JPE;*.GIF;*.PNG;))")]
[DefaultValue("")]
public string FileTypeDescription
{
get
{
object o = ViewState["FileTypeDescription"];
if (o == null)
return "";
return o.ToString();
}
set { ViewState["FileTypeDescription"] = value; }
} [Category("Behavior")]
[Description("The file types to restrict uploads to (ex. *.jpg; *.jpeg; *.jpe; *.gif; *.png;)")]
[DefaultValue("")]
public string FileTypes
{
get
{
object o = ViewState["FileTypes"];
if (o == null)
return "";
return o.ToString();
}
set { ViewState["FileTypes"] = value; }
} protected override void OnLoad(EventArgs e)
{
base.OnLoad(e);
Page.Form.Enctype = "multipart/form-data";
} protected override void Render(HtmlTextWriter writer)
{
base.Render(writer);
string url = Page.ClientScript.GetWebResourceUrl(this.GetType(), FLASH_SWF);
string obj = string.Format("<object classid=\"clsid:d27cdb6e-ae6d-11cf-96b8-444553540000\"" +
"codebase=\"http://fpdownload.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=9,0,0,0\"" +
"width=\"575\" height=\"375\" id=\"fileUpload\" align=\"middle\">" +
"<param name=\"allowScriptAccess\" value=\"sameDomain\" />" +
"<param name=\"movie\" value=\"{0}\" />" +
"<param name=\"quality\" value=\"high\" />" +
"<param name=\"wmode\" value=\"transparent\">" +
"<PARAM NAME=FlashVars VALUE='{3}{4}{5}{6}{7}&uploadPage={1}?{2}'>" +
"<embed src=\"{0}\"" +
"FlashVars='{3}{4}{5}{6}{7}&uploadPage={1}?{2}'" +
"quality=\"high\" wmode=\"transparent\" width=\"575\" height=\"375\" " +
"name=\"fileUpload\" align=\"middle\" allowScriptAccess=\"sameDomain\" " +
"type=\"application/x-shockwave-flash\" " +
"pluginspage=\"http://www.macromedia.com/go/getflashplayer\" />" +
"</object>",
url,
ResolveUrl(UploadPage),
HttpContext.Current.Server.UrlEncode(QueryParameters),
string.IsNullOrEmpty(OnUploadComplete) ? "" : "&completeFunction=" + OnUploadComplete,
string.IsNullOrEmpty(FileTypes) ? "" : "&fileTypes=" + HttpContext.Current.Server.UrlEncode(FileTypes),
string.IsNullOrEmpty(FileTypeDescription) ? "" : "&fileTypeDescription=" + HttpContext.Current.Server.UrlEncode(FileTypeDescription),
TotalUploadSizeLimit > 0 ? "&totalUploadSize=" + TotalUploadSizeLimit : "",
UploadFileSizeLimit > 0 ? "&fileSizeLimit=" + UploadFileSizeLimit : ""
);
writer.Write(obj);
}
}
究竟这个乱码问题该怎么解决? 等待高手.....
最近开始搞一个多文件上传的问题,将案例引入到项目中的时候,出现了文件名称乱码的问题?
不知道各位遇到过没有?
1.自己检查了这个项目的编码格式web.config都写写好的,<globalization requestEncoding="gb2312" responseEncoding="gb2312" fileEncoding="gb2312"/>2.页面文件的编码:<%@ Page Language="C#" ResponseEncoding="gb2312" <meta content="text/html; charset=gb2312" http-equiv="Content-Type">
3.将页面文件用TXT打开重新设置了保存时的编码为: UTF-8
共有(ANSI,UTF-8,Unicode,Unicode big endia)4.
这个是案例的项目结构,他将 FileUpload 封装为了一个类库。 public class FlashUpload : Control
{
private const string FLASH_SWF = "FlashUpload.FlashFileUpload.swf"; [Category("Behavior")]
[Description("The page to upload files to.")]
[DefaultValue("")]
public string UploadPage
{
get
{
object o = ViewState["UploadPage"];
if (o == null)
return "";
return o.ToString();
}
set { ViewState["UploadPage"] = value; }
} [Category("Behavior")]
[Description("Query Parameters to pass to the Upload Page.")]
[DefaultValue("")]
public string QueryParameters
{
get
{
object o = ViewState["QueryParameters"];
if (o == null)
return "";
return o.ToString();
}
set { ViewState["QueryParameters"] = value; }
} [Category("Behavior")]
[Description("Javascript function to call when all files are uploaded.")]
[DefaultValue("")]
public string OnUploadComplete
{
get
{
object o = ViewState["OnUploadComplete"];
if (o == null)
return "";
return o.ToString();
}
set { ViewState["OnUploadComplete"] = value; }
} [Category("Behavior")]
[Description("The maximum file size that can be uploaded, in bytes (0 for no limit).")]
public decimal UploadFileSizeLimit
{
get
{
object o = ViewState["UploadFileSizeLimit"];
if (o == null)
return 0;
return (decimal)o;
}
set { ViewState["UploadFileSizeLimit"] = value; }
} [Category("Behavior")]
[Description("The total number of bytes that can be uploaded (0 for no limit).")]
public decimal TotalUploadSizeLimit
{
get
{
object o = ViewState["TotalUploadSizeLimit"];
if (o == null)
return 0;
return (decimal)o;
}
set { ViewState["TotalUploadSizeLimit"] = value; }
} [Category("Behavior")]
[Description("The description of file types that you want uploads restricted to (ex. Images (*.JPG;*.JPEG;*.JPE;*.GIF;*.PNG;))")]
[DefaultValue("")]
public string FileTypeDescription
{
get
{
object o = ViewState["FileTypeDescription"];
if (o == null)
return "";
return o.ToString();
}
set { ViewState["FileTypeDescription"] = value; }
} [Category("Behavior")]
[Description("The file types to restrict uploads to (ex. *.jpg; *.jpeg; *.jpe; *.gif; *.png;)")]
[DefaultValue("")]
public string FileTypes
{
get
{
object o = ViewState["FileTypes"];
if (o == null)
return "";
return o.ToString();
}
set { ViewState["FileTypes"] = value; }
} protected override void OnLoad(EventArgs e)
{
base.OnLoad(e);
Page.Form.Enctype = "multipart/form-data";
} protected override void Render(HtmlTextWriter writer)
{
base.Render(writer);
string url = Page.ClientScript.GetWebResourceUrl(this.GetType(), FLASH_SWF);
string obj = string.Format("<object classid=\"clsid:d27cdb6e-ae6d-11cf-96b8-444553540000\"" +
"codebase=\"http://fpdownload.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=9,0,0,0\"" +
"width=\"575\" height=\"375\" id=\"fileUpload\" align=\"middle\">" +
"<param name=\"allowScriptAccess\" value=\"sameDomain\" />" +
"<param name=\"movie\" value=\"{0}\" />" +
"<param name=\"quality\" value=\"high\" />" +
"<param name=\"wmode\" value=\"transparent\">" +
"<PARAM NAME=FlashVars VALUE='{3}{4}{5}{6}{7}&uploadPage={1}?{2}'>" +
"<embed src=\"{0}\"" +
"FlashVars='{3}{4}{5}{6}{7}&uploadPage={1}?{2}'" +
"quality=\"high\" wmode=\"transparent\" width=\"575\" height=\"375\" " +
"name=\"fileUpload\" align=\"middle\" allowScriptAccess=\"sameDomain\" " +
"type=\"application/x-shockwave-flash\" " +
"pluginspage=\"http://www.macromedia.com/go/getflashplayer\" />" +
"</object>",
url,
ResolveUrl(UploadPage),
HttpContext.Current.Server.UrlEncode(QueryParameters),
string.IsNullOrEmpty(OnUploadComplete) ? "" : "&completeFunction=" + OnUploadComplete,
string.IsNullOrEmpty(FileTypes) ? "" : "&fileTypes=" + HttpContext.Current.Server.UrlEncode(FileTypes),
string.IsNullOrEmpty(FileTypeDescription) ? "" : "&fileTypeDescription=" + HttpContext.Current.Server.UrlEncode(FileTypeDescription),
TotalUploadSizeLimit > 0 ? "&totalUploadSize=" + TotalUploadSizeLimit : "",
UploadFileSizeLimit > 0 ? "&fileSizeLimit=" + UploadFileSizeLimit : ""
);
writer.Write(obj);
}
}
究竟这个乱码问题该怎么解决? 等待高手.....
解决方案 »
- ASP.NET登陆控件问题就32分了!!!!
- 求大神帮助,如何删除datagrid中复选框选中的值
- userControl可不可能只有一个.cs文件
- 如何在cs里动态获取一个gridview的高度?
- 求救:MsgBox
- 用过webdiyer的aspnetpager的进来看看.
- asp.net下怎么通过按扭事件浏览客户端的本地目录?
- 通常开发一个B/S模式下的3层结构的系统,该如何入手呢?开发的流程大概如何呢?
- MVC路由配置问题,用到 .php扩展名
- |M| 求一个浮动DIV的width:100%的CSS写法 因为body用了margin-left: 5px;margin-right: 5px; 显示出来的那个DIV不能100%大小
- 网站支持qq、新浪等帐号登录
- gridview单击行事件 大侠帮帮忙哟!
1.
<globalization requestEncoding="gb2312" responseEncoding="gb2312" fileEncoding="UTF-8"/>2.<meta content="text/html;charset=utf-8" http-equiv="Content-Type">只要设置页面编码为utf-8就可以了,