当前位置:编程学习 > C#/ASP.NET >>

FileUpload的问题

 protected void Button1_Click(object sender, EventArgs e)
    {
        string strMyFileName, strMyfilepath,strMyfilephicalpath;
        strMyfilepath = ConfigurationManager.AppSettings["FileUploadPath"].ToString();
          strMyFileName = FileUpload1.FileName;
          strMyfilephicalpath = Server.MapPath(strMyfilepath+strMyFileName);
          FileUpload1.SaveAs("strMyfilephicalpath");
          ListBox1.Items.Add(strMyFileName);
WEB.CONFIG:
<configuration>
<appSettings>
    <add  key="FileUploadPath" value="../Uploade" />
    <add  key="FileTypeLimit"  value=".zap,.rar,.doc,.ppt,.txt,.mp3"/>
    <add  key="FileSizeLimit"  value="10240"/>
    <add  key="FolderSizeLimit"  value="102400" />
   </appSettings>
<connectionStrings/>
<system.web>
    <httpRuntime  executionTimeout="60"/>
    
<compilation debug="true"/>

<authentication mode="Windows"/>

</system.web>
</configuration>
调试出现异常:未能映射路径“/UploadePhoto-0019.jpg”。 
说明: 执行当前 Web 请求期间,出现未处理的异常。请检查堆栈跟踪信息,以了解有关该错误以及代码中导致错误的出处的详细信息。 

异常详细信息: System.InvalidOperationException: 未能映射路径“/UploadePhoto-0019.jpg”。

这是什么原因? --------------------编程问答-------------------- 关注, --------------------编程问答-------------------- strMyfilephicalpath = Server.MapPath(strMyfilepath+"\\" +strMyFileName); 
--------------------编程问答--------------------

string strMyFileName, strMyfilepath,strMyfilephicalpath; 
strMyfilepath = ConfigurationManager.AppSettings["FileUploadPath"].ToString(); 
strMyFileName = FileUpload1.FileName; 
strMyfilephicalpath = Server.MapPath(strMyfilepath + "/" + strMyFileName); 
FileUpload1.SaveAs(strMyfilephicalpath); 
ListBox1.Items.Add(strMyFileName); 
--------------------编程问答-------------------- 路径有问题。 --------------------编程问答-------------------- FileUpload1.SaveAs("strMyfilephicalpath"); 参数strMyfilephicalpath已经是string了,还加引号? --------------------编程问答--------------------
引用 5 楼 liujunhappy2005 的回复:
FileUpload1.SaveAs("strMyfilephicalpath"); 参数strMyfilephicalpath已经是string了,还加引号?

正解 --------------------编程问答-------------------- Server.MapPath --------------------编程问答-------------------- 关注
补充:.NET技术 ,  ASP.NET
CopyRight © 2022 站长资源库 编程知识问答 zzzyk.com All Rights Reserved
部分文章来自网络,