The given path's format is not supported.
问题
编程以来今本没有使用input[type=file]这个控件过,今天突然使用尽然报错了,在本地chrome,firefox等其他的浏览器都是好的,唯独ie报错了。在服务器的时候,尽然chrome也是报错的。
问题原因
出现这个错误的主要原因是,在本地上传图片的时候HttpPostedFileBase对象里面保存的FileName仅仅是文件的名称而已
而部署服务器上的时候上传FileName却是你本地上传的物理路径,也就是本地完整的路劲,如下图
解决问题
所以导致我们在执行如下代码的时候会报错
fileName = imgLogo.FileName; string type = fileName.Substring(fileName.LastIndexOf(".") + ).ToLower();
if (!ValidateImg(type))
{
ErrorModel errorModel = new ErrorModel("imgLogo", "只能上传图片文件!");
ViewBag.errorModel = errorModel;
return View(config);
}
//全路劲,导致这里的server.mappath得到的服务器路劲其实错误了,所以下面的saveas会直接报错
var path = Server.MapPath("~/images/" + fileName); imgLogo.SaveAs(path);
既然知道原因了,那么解决起来也就很简单了,处理一下fileName就好了,代码如下
//只需要在这里截取出文件名称就好了
fileName = imgLogo.FileName.Substring(imgLogo.FileName.LastIndexOf("\\") + 1); ; string type = fileName.Substring(fileName.LastIndexOf(".") + ).ToLower();
if (!ValidateImg(type))
{
ErrorModel errorModel = new ErrorModel("imgLogo", "只能上传图片文件!");
ViewBag.errorModel = errorModel;
return View(config);
}
//全路劲,导致这里的server.mappath得到的服务器路劲其实错误了,所以下面的saveas会直接
var path = Server.MapPath("~/images/" + fileName); imgLogo.SaveAs(path);
The given path's format is not supported.的更多相关文章
- IE报错:The given path's format is not supported
在使用FileUpload控件进行上传EXCEL文件时,本地调试上传无问题,但是发布之后报地址无效错误 一.出现这个错误的主要原因是,在本地上传图片的时候HttpPostedFileBase对象里面保 ...
- This file's format is not supported or you don't specify a correct format. 解决办法
string path = @"c:\请假统计表.xlsx"; Workbook workBook = new Workbook(); workBook.Open(path); A ...
- RSA key format is not supported
对接支付宝时,提示RSA错误 : 请仔细检查 : 创建支付对象时,关键字参数的名字 如果公私钥是以拼接路径的方式传递给AliPay,正确的关键字参数的名字应该如下 :
- os.getcwd()、sys.path[0]、sys.argv[0]和__file__的区别,终于弄清楚了
os.getcwd().sys.path[0].sys.argv[0]和__file__的区别 要分清这几个的区别与使用条件,实际测试一下是最准确的. 设计测试方法: 一个主模块用来运行,一个子模块用 ...
- String.format和MessageFormat.format的对比用法
1.MessageFormat.format import java.text.MessageFormat; /** * Created by SYJ on 2017/9/13. */ public ...
- Hadoop官方文档翻译——MapReduce Tutorial
MapReduce Tutorial(个人指导) Purpose(目的) Prerequisites(必备条件) Overview(综述) Inputs and Outputs(输入输出) MapRe ...
- 转:SDL2源代码分析
1:初始化(SDL_Init()) SDL简介 有关SDL的简介在<最简单的视音频播放示例7:SDL2播放RGB/YUV>以及<最简单的视音频播放示例9:SDL2播放PCM>中 ...
- OpenStack Keystone安装部署流程
之前介绍了OpenStack Swift的安装部署,采用的都是tempauth认证模式,今天就来介绍一个新的组件,名为Keystone. 1. 简介 本文将详细描述Keystone的安装部署流程,并给 ...
- 《OD学hadoop》第二周0703
hdfs可视化界面: http://beifeng-hadoop-01:50070/dfshealth.html#tab-overview yarn可视化界面: http://beifeng-hado ...
随机推荐
- [Java] 读写字符串数据
package test.stream; import java.io.FileInputStream; import java.io.FileNotFoundException; import ja ...
- 浅谈 Linux 内核开发之网络设备驱动
转自http://www.ibm.com/developerworks/cn/linux/l-cn-networkdriver/ 网络设备介绍 网络设备是计算机体系结构中必不可少的一部分,处理器如果想 ...
- Ext 中xtype一览
基本组件: xtype Class 描述 button Ext.Button 按钮 splitbutton Ext.SplitButton 带下拉菜单的按钮 cycle Ext.CycleButton ...
- weblogic诊断案例-AdminServer平均1-2周崩溃
OS2台:RH5.5 64位 WEBLOGIC VERSION:9.2.3 JDK:1.5 64位 weblogic一个管理服务,4个受管(2台服务器做集群,每台服务器2个受管).应用部署后通过一个月 ...
- abap case when 例子
DATA: gv_1 TYPE c. DATA: gv_2 TYPE i. gv_2 = 60. IF gv_2 >= 0 AND gv_2 < 60 . gv_1 = 'A'. ELSE ...
- fatal: Not a git repository (or any of the parent directories): .git
$ git remote add origin https://github.com/heyuanchao/YouxibiClient.gitfatal: Not a git repository ( ...
- (转)一段如何調用Button.Click事件的故事
原文地址:http://helloouc.blog.163.com/blog/static/5530527120091050314590/ 一.前言 由于小朱与BillChung的启发,想写一个故事, ...
- 【LOB】使用USER_LOBS视图获得当前用户包含LOB字段的表
包含LOB类型字段的表往往需要特殊关照,如何快速的获得包含LOB对象的数据库表?使用DBA_LOBS.ALL_LOBS和USER_LOBS视图可以很方便地获得包含BLOB或CLOB字段的表. 简单看一 ...
- Codeforces Round #218 (Div. 2) B. Fox Dividing Cheese
B. Fox Dividing Cheese time limit per test 1 second memory limit per test 256 megabytes input standa ...
- Skill
Skill Yasser is an Egyptian coach; he will be organizing a training camp in Jordan. At the end of ca ...