The given path's format is not supported 我有个网站用fileUpLoad上传图片,在装了vs的电脑上上传没问题,但在正常使用人员的电脑上他们操作后台时上传图片报The given path's format is not supported 这个错误,我从没见过这种情况,请问大家这是怎么回事呀,要怎么处理。 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 贴出路径@"";http://social.msdn.microsoft.com/Forums/en/Vsexpressvcs/thread/467bf8e6-1b18-47cb-bde1-458430b1d2de 你上传的话,要用Server.MapPath()取Server的路径 我弹出路径看了变成了:cadminimagea.jpg原本路径:c://admin//image/a.jpg所以程序报路径格式不正确 /// <summary> /// 上传图片方法 /// </summary> /// <param name="ful">上传控件</param> /// <param name="path">上传路径</param> public static bool UpLoadFile(FileUpload ful, string path, out string filename) { bool value = false; filename = ""; try { if (!string.IsNullOrEmpty(ful.PostedFile.FileName.Trim())) { if (ful.PostedFile.ContentLength > 10240000) { value = false; } else { filename = DateTime.Now.ToString("yyMMddhhss") + ful.PostedFile.FileName; string paths =path + filename; ful.PostedFile.SaveAs(paths); value = true; } } return value; } catch (FileLoadException ex) { throw ex; } 这个是我放在add_code里的一个上传图片的方法 既然路径里面有连个//,你就进行替换下啊path = path.Replace("\\\\","\\"); 但客户哪边上传就报 The given path's format is not supported Server.Mappath我在事件里string path是追加了的这个方法里传的就是Server.mappath路径+图片名 //添加产品记录 protected void btnAdd_Click(object sender, EventArgs e) { if (IsValid) { try { string filename = null, maxname = null; string tempPath = @"" + Server.MapPath(path); if (HelperCode.UpLoadFile(this.fulUpLoad, tempPath, out filename) == false || HelperCode.UpLoadFile(this.fulMax, tempPath, out maxname) == false) { this.spMes.InnerHtml = "请检查是否有上传图片并且允许上传最大值为100MB!"; } else if (bll.AddProductById(GetObj(0, filename, maxname)) > 0) { this.spMes.InnerHtml = "增加[" + this.txtName.Text + "]产品成功!页面将在三秒后自动更新."; script(); } else { this.spMes.InnerHtml = "sorry!增加[" + this.txtName.Text + "]产品过程中出现异常!请检查输入数据。."; } } catch (Exception ex) { this.spMes.InnerHtml = "sorry!" + ex + "可能产品编号有重复!"; } } } 怎么会无从查起呢?哪行报错在哪行前面加调试信息。变量赋值没有必要加 @"" string tempPath = Server.MapPath(path); 就 可以了 问题是我本机测试是正常的,有VS工具的电脑测试都是正常的,而放到网上没有装VS的都报错,我在服务器上无法调试呀。 sorry!System.NotSupportedException: The given path's format is not supported. at System.Security.Util.StringExpressionSet.CanonicalizePath(String path, Boolean needFullPath) at System.Security.Util.StringExpressionSet.CreateListFromExpressions(String[] str, Boolean needFullPath) at System.Security.Permissions.FileIOPermission.AddPathList(FileIOPermissionAccess access, AccessControlActions control, String[] pathListOrig, Boolean checkForDuplicates, Boolean needFullPath, Boolean copyPathList) at System.Security.Permissions.FileIOPermission..ctor(FileIOPermissionAccess access, AccessControlActions control, String[] pathList, Boolean checkForDuplicates, Boolean needFullPath) at System.IO.FileStream.Init(String path, FileMode mode, FileAccess access, Int32 rights, Boolean useRights, FileShare share, Int32 bufferSize, FileOptions options, SECURITY_ATTRIBUTES secAttrs, String msgPath, Boolean bFromProxy) at System.IO.FileStream..ctor(String path, FileMode mode, FileAccess access, FileShare share, Int32 bufferSize, FileOptions options, String msgPath, Boolean bFromProxy) at System.IO.FileStream..ctor(String path, FileMode mode) at System.Web.HttpPostedFile.SaveAs(String filename) at HelperCode.UpLoadFile(FileUpload ful, String path, String& filename) at admin_products_Default.btnAdd_Click(Object sender, EventArgs e)可能产品编号有重复! catch (Exception ex) { this.spMes.InnerHtml = "sorry!" + ex + "可能产品编号有重复!"; } 你把调试信息在页面上打出来啊。比如http://xxx,.aspx?debug=1就显示出调试信息,方便自己查看,其他人不知道这个参数windows路径是这样的c:\admin\image\a.jpgLunix路径是这样的c:/admin/image/a.jpg莫非那个机器不是windows操作系统? path = path.Replace("//","/"); 我也遇到了这个问题啊.....在服务器上执行程序导入,结果就报这个错误.... 我本地测试是正确的。本地就上这样的: string fileName = @"D:\UpFiles\" +file_upload.PostedFile.FileName; 如何强制转换为数字 TreeList和GridView联动 数据缓存的问题 membership access版的关于配置文件密码长度的问题,快来看看 |zyciis| 要生成一个临时文件给Ajax调用,但服务器不给创建文件的权限,怎么办 谢谢 关于asp.net中页面提交 推荐实战的书 请教:一个页面返回的问题!急!急!!急!!! 在15寸显示器做的网页为什么在17寸的显示器上显示得的很难看! 谁知道word库文件内置的操作函数的详细介绍,100分相赠,谢谢 急!!ajax注册验证,帮忙看哪里错了,总是返回false 调试时怎么成了路径
@"";
http://social.msdn.microsoft.com/Forums/en/Vsexpressvcs/thread/467bf8e6-1b18-47cb-bde1-458430b1d2de
原本路径:c://admin//image/a.jpg
所以程序报路径格式不正确
/// 上传图片方法
/// </summary>
/// <param name="ful">上传控件</param>
/// <param name="path">上传路径</param>
public static bool UpLoadFile(FileUpload ful, string path, out string filename)
{
bool value = false;
filename = "";
try
{ if (!string.IsNullOrEmpty(ful.PostedFile.FileName.Trim()))
{
if (ful.PostedFile.ContentLength > 10240000)
{
value = false;
}
else
{
filename = DateTime.Now.ToString("yyMMddhhss") + ful.PostedFile.FileName;
string paths =path + filename;
ful.PostedFile.SaveAs(paths);
value = true;
}
}
return value;
}
catch (FileLoadException ex)
{
throw ex;
}
path = path.Replace("\\\\","\\");
这个方法里传的就是Server.mappath路径+图片名
protected void btnAdd_Click(object sender, EventArgs e)
{
if (IsValid)
{
try
{
string filename = null, maxname = null;
string tempPath = @"" + Server.MapPath(path);
if (HelperCode.UpLoadFile(this.fulUpLoad, tempPath, out filename) == false ||
HelperCode.UpLoadFile(this.fulMax, tempPath, out maxname) == false)
{
this.spMes.InnerHtml = "请检查是否有上传图片并且允许上传最大值为100MB!";
}
else if (bll.AddProductById(GetObj(0, filename, maxname)) > 0)
{
this.spMes.InnerHtml = "增加[" + this.txtName.Text + "]产品成功!页面将在三秒后自动更新.";
script();
}
else
{
this.spMes.InnerHtml = "sorry!增加[" + this.txtName.Text + "]产品过程中出现异常!请检查输入数据。.";
}
}
catch (Exception ex)
{
this.spMes.InnerHtml = "sorry!" + ex + "可能产品编号有重复!";
}
}
}
哪行报错在哪行前面加调试信息。变量赋值没有必要加 @""
string tempPath = Server.MapPath(path);
就 可以了
{
this.spMes.InnerHtml = "sorry!" + ex + "可能产品编号有重复!";
}
http://xxx,.aspx?debug=1就显示出调试信息,方便自己查看,其他人不知道这个参数windows路径是这样的
c:\admin\image\a.jpgLunix路径是这样的
c:/admin/image/a.jpg莫非那个机器不是windows操作系统?
本地就上这样的: string fileName = @"D:\UpFiles\" +file_upload.PostedFile.FileName;