问题描述
usingSystem;usingSystem.Data;usingSystem.Configuration;usingSystem.Web;usingSystem.Web.Security;usingSystem.Web.UI;usingSystem.Web.UI.WebControls;usingSystem.Web.UI.WebControls.WebParts;usingSystem.Web.UI.HtmlControls;publicpartialclass_Default:System.Web.UI.Page{protectedvoidPage_Load(objectsender,EventArgse){}voidButton1_Click(objectSource,EventArgse){if(Text1.Value==""){Span1.InnerHtml="Error:youmustenterafilename";return;}if(File1.PostedFile!=null){stringfilepath=Path.Combine(Path.GetTempPath(),Path.GetFileName(Text1.Value));try{File1.PostedFile.SaveAs(filepath);Span1.InnerHtml="Fileuploadedsuccessfullyto<b>"+filepath+"</b>onthewebserver";}catch(Exceptionexc){Span1.InnerHtml="Errorsavingfile<b>"+filepath+"</b><br>"+exc.ToString();}}}}出现的错误错误1“_Default.Button1_Click(object,System.EventArgs,string)”不可访问,因为它受保护级别限制d:MyDocumentsVisualStudio2005WebSitesWebSite6Default.aspx23错误2当前上下文中不存在名称“Path”d:MyDocumentsVisualStudio2005WebSitesWebSite6Default.aspx.cs2831d:...WebSite6
解决方案
解决方案二:
usingSystem;usingSystem.Data;usingSystem.Configuration;usingSystem.Web;usingSystem.Web.Security;usingSystem.Web.UI;usingSystem.Web.UI.WebControls;usingSystem.Web.UI.WebControls.WebParts;usingSystem.Web.UI.HtmlControls;publicpartialclass_Default:System.Web.UI.Page{protectedvoidPage_Load(objectsender,EventArgse){}privatevoidButton1_Click(objectSource,EventArgse){if(Text1.Value==""){Span1.InnerHtml="Error:youmustenterafilename";return;}if(File1.PostedFile!=null){stringfilepath=Request.Path.Combine(Request.Path.GetTempPath(),Request.Path.GetFileName(Text1.Value));try{File1.PostedFile.SaveAs(filepath);Span1.InnerHtml="Fileuploadedsuccessfullyto<b>"+filepath+"</b>onthewebserver";}catch(Exceptionexc){Span1.InnerHtml="Errorsavingfile<b>"+filepath+"</b><br>"+exc.ToString();}}}}试试这个~~