Server.MapPath - Physical path given, virtual path expected(附源码)
来源:互联网 发布:家电销量数据 编辑:程序博客网 时间:2024/04/30 07:21
.Net Web Developer的Web Service,接收C#客户端发送的文件,服务器使用了物理绝对路径(Physical path),跟踪调试,Web Service的asmx执行存放文件操作时会弹出"Physical path given, virtual path expected"(需要相对路径)异常。
Web Service握手和收发文件测试图
借助Google搜索引擎,找到同类问题:
Server.MapPath - Physical path given, virtual path expected
http://stackoverflow.com/questions/5039725/server-mappath-physical-path-given-virtual-path-expected借助Server.MapPath进行相对路径文件的存区:
Server.MapPath方法的应用方法
http://www.cnblogs.com/Showshare/archive/2007/04/23/723965.html
使用Server.MapPath调试成功图
附资源链接和代码段
C#怎么通过WebService 上传图片
http://bbs.csdn.net/topics/390550918
使用了三楼大神的一段代码,如下
[WebMethod] public string upfilebyte(byte[] b, ref string FileName) { try { MemoryStream m = new MemoryStream(b); using (FileStream fs = File.Open(Server.MapPath(@"\upfile\" + FileName), FileMode.Create)) { m.WriteTo(fs); m.Close(); fs.Close(); delLastTimeFile(); return "上传成功!"; } } catch (Exception xx) { return xx.Message; } } [WebMethod] public byte[] downfilebyte(ref string FileName)//下载 { try { using (FileStream fs = File.Open(Server.MapPath(@"\upfile\" + FileName), FileMode.Open)) { byte[] b = new byte[fs.Length]; fs.Read(b, 0, Convert.ToInt32(fs.Length)); fs.Close(); FileName = ""; return b; } } catch (Exception xx) { FileName = xx.Message; return null; } }可以发现,c02645大神有使用Server.MapPath,我修改代码过程中走了弯路,学会使用Server.MapPath。
0 0
- Server.MapPath - Physical path given, virtual path expected(附源码)
- Server.MapPath(path)
- server.MapPath(path) 解释
- Server.MapPath(path)的使用
- Server.MapPath(path)的详细说明
- ASP.NET中Request.ApplicationPath、Request.FilePath、Request.Path、.Request.MapPath、Server.MapPath的区别
- ASP.NET中Request.ApplicationPath、Request.FilePath、Request.Path、.Request.MapPath、Server.MapPath的区别
- 在 MapPath 的 Path 参数中不允许字符 '..',解决方法。
- asp 必须为 MapPath 方法指定 Path 参数
- path
- path
- path
- path
- path:
- path
- “path”,
- PATH
- PATH
- js获得控件位置
- printf函数遵守C调用规范,即参数 从右至左 压栈,堆栈由调用者平衡
- 算法
- Java第六周作业
- Linux tcpdump命令详解
- Server.MapPath - Physical path given, virtual path expected(附源码)
- 关于结构体对齐和结构体位域的问题
- android调用远程service(一个apk调用另一个apk的service)
- [中英对照]Steve Jobs教你做战略
- Android中的线程
- android 检查SD卡是否存在
- Best Time to Buy and Sell Stock -- LeetCode
- PointF 源码
- 与传统的又一次对抗:砍掉后视镜