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

大家帮我看看这段程序哪错了?谢谢!!!

 protected void B8_Click(object sender, EventArgs e)
    {
         string path = Request.QueryString["Path"];
if(F12.PostedFile.FileName == "") // no file selected
Response.Write("<script>alert(\'请选择一个文件再上传!');</script>");
else
{

string filename = F12.PostedFile.FileName;
string togo = path + "/" + filename.Remove(0, filename.LastIndexOf("\\") + 1);
F12.PostedFile.SaveAs(Server.MapPath(togo));  

// get size of file with appropriate expression of size
long fileSize = F12.PostedFile.ContentLength;
string fileSizeStr;
if(fileSize > 1000000) fileSizeStr = fileSize/1000000 + " Mb";
else if(fileSize > 1000) fileSizeStr = fileSize/1000 + " Kb";
else fileSizeStr = fileSize + " b";

// notify user of success
Response.Write("<script>alert(\"文件上传成功!\\nName: " + filename.Remove(0, filename.LastIndexOf("\\") + 1) + "\\nSize: " + fileSizeStr + "\"); opener.location.href=opener.location.href; window.self.close();</script>"); //document.parentWindow.location.href=\"contentPane.aspx?Path=" + Server.UrlEncode(Request["Path"]) + "\"; 

}


    }






未能映射路径“/3a4f68aa0a5206911e17a294.jpg”

堆栈跟踪: 


[InvalidOperationException: 未能映射路径“/3a4f68aa0a5206911e17a294.jpg”。]
   System.Web.Hosting.HostingEnvironment.MapPathActual(VirtualPath virtualPath, Boolean permitNull) +8884122
   System.Web.Hosting.HostingEnvironment.MapPathInternal(VirtualPath virtualPath) +42
   System.Web.VirtualPath.MapPathInternal() +4
   System.Web.HttpRequest.MapPath(VirtualPath virtualPath, VirtualPath baseVirtualDir, Boolean allowCrossAppMapping) +107
   System.Web.HttpRequest.MapPath(VirtualPath virtualPath) +37
   System.Web.HttpServerUtility.MapPath(String path) +99
   _Default.B9_Click(Object sender, EventArgs e) in e:\毕业设计\主持人\项目申报.aspx.cs:246
   System.Web.UI.WebControls.Button.OnClick(EventArgs e) +111
   System.Web.UI.WebControls.Button.RaisePostBackEvent(String eventArgument) +110
   System.Web.UI.WebControls.Button.System.Web.UI.IPostBackEventHandler.RaisePostBackEvent(String eventArgument) +10
   System.Web.UI.Page.RaisePostBackEvent(IPostBackEventHandler sourceControl, String eventArgument) +13
   System.Web.UI.Page.RaisePostBackEvent(NameValueCollection postData) +36
   System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +1565

 
--------------------编程问答--------------------

UploadedFile file = UploadedFile.FromHttpPostedFile(Request.Files[0]);

这样子试试吧
补充:.NET技术 ,  ASP.NET
CopyRight © 2012 站长网 编程知识问答 www.zzzyk.com All Rights Reserved
部份技术文章来自网络,