我正在ASP.NET Framework中开发网站,其中有一个页面,用户需要上传文件以进行注册,它应该是pdf格式,但是当我点击提交按钮时,我会收到错误页面。
下面是堆栈跟踪
Could not find a part of the path 'E:\ASPapps\youth\Resumes\innovation\About Stacks.pdf'.
Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.
Exception Details: System.IO.DirectoryNotFoundException: Could not find a part of the path 'E:\ASPapps\youth\Resumes\innovation\About Stacks.pdf'.
来源错误:
An unhandled exception was generated during the execution of the current web request. Information regarding the origin and location of the exception can be identified using the exception stack trace below.
堆栈追踪:
[DirectoryNotFoundException: Could not find a part of the path 'E:\ASPapps\youth\Resumes\innovation\About Stacks.pdf'.]
System.IO.__Error.WinIOError(Int32 errorCode, String maybeFullPath) +224
System.IO.FileStream.Init(String path, FileMode mode, FileAccess access, Int32 rights, Boolean useRights, FileShare share, Int32 bufferSize, FileOptions options, SECURITY_ATTRIBUTES secAttrs, String msgPath, Boolean bFromProxy, Boolean useLongPath) +1142
System.IO.FileStream..ctor(String path, FileMode mode, FileAccess access, FileShare share) +83
System.Net.Mail.AttachmentBase.SetContentFromFile(String fileName, String mediaType) +76
System.Net.Mail.Attachment..ctor(String fileName, String mediaType) +38
InventeamHP.innovation_Register.SendMail(String emailid, String bccemailid, String body) +715
InventeamHP.innovation_Register.lbtnESubmit_Click(Object sender, EventArgs e) +8078
System.Web.UI.WebControls.LinkButton.OnClick(EventArgs e) +118
System.Web.UI.WebControls.LinkButton.RaisePostBackEvent(String eventArgument) +113
System.Web.UI.WebControls.LinkButton.System.Web.UI.IPostBackEventHandler.RaisePostBackEvent(String eventArgument) +9
System.Web.UI.Page.RaisePostBackEvent(IPostBackEventHandler sourceControl, String eventArgument) +13
System.Web.UI.Page.RaisePostBackEvent(NameValueCollection postData) +176
System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +5563
答案 0 :(得分:0)
尝试使用这样的代码(我不知道你的代码):
ASPX:
<input id="up" runat="server" type="file" />
代码背后:
up.PostedFile.SaveAs(HttpContext.Current.Server.MapPath("/")+"yourFolder\\"+up.PostedFile.FileName);
以及Darin Dimitrov说,请确保您的文件夹存在。