2017-02-14 29 views
0

イメージを自分のWebサイトにアップロードしようとしたときに、次のエラーが表示されます。ここでサーバーエラー - 'C: home site wwwroot App_Data Temp 1.png'のパスの一部を見つけることができませんでした。

Server Error in '/' Application.

Could not find a part of the path 'C:\home\site\wwwroot\App_Data\Temp\1.png'.

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 'C:\home\site\wwwroot\App_Data\Temp\1.png'.

Source Error:

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.

Stack Trace:

[DirectoryNotFoundException: Could not find a part of the path 'C:\home\site\wwwroot\App_Data\Temp\1.png'.]
System.IO.__Error.WinIOError(Int32 errorCode, String maybeFullPath) +353 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, Boolean checkHost) +1326 System.IO.FileStream..ctor(String path, FileMode mode, FileAccess access, FileShare share, Int32 bufferSize, FileOptions options, String msgPath, Boolean bFromProxy) +60
System.IO.FileStream..ctor(String path, FileMode mode) +55
System.Web.HttpPostedFile.SaveAs(String filename) +94
System.Web.HttpPostedFileWrapper.SaveAs(String filename) +14
RoomAuditSystem.Controllers.HomeController.Index(HttpPostedFileBase file) +96 lambda_method(Closure , ControllerBase , Object[]) +104 System.Web.Mvc.ActionMethodDispatcher.Execute(ControllerBase controller, Object[] parameters) +14
System.Web.Mvc.ReflectedActionDescriptor.Execute(ControllerContext controllerContext, IDictionary 2 parameters) +157
System.Web.Mvc.ControllerActionInvoker.InvokeActionMethod(ControllerContext controllerContext, ActionDescriptor actionDescriptor, IDictionary
2 parameters) +27
System.Web.Mvc.Async.AsyncControllerActionInvoker.b__39(IAsyncResult asyncResult, ActionInvocation innerInvokeState) +22
System.Web.Mvc.Async.WrappedAsyncResult 2.CallEndDelegate(IAsyncResult asyncResult) +29
System.Web.Mvc.Async.WrappedAsyncResultBase
1.End() +49
System.Web.Mvc.Async.AsyncControllerActionInvoker.EndInvokeActionMethod(IAsyncResult asyncResult) +32
System.Web.Mvc.Async.AsyncInvocationWithFilters.b__3d() +50 System.Web.Mvc.Async.<>c__DisplayClass46.b__3f() +225 System.Web.Mvc.Async.<>c__DisplayClass33.b__32(IAsyncResult asyncResult) +10
System.Web.Mvc.Async.WrappedAsyncResult 1.CallEndDelegate(IAsyncResult asyncResult) +10
System.Web.Mvc.Async.WrappedAsyncResultBase
1.End() +49
System.Web.Mvc.Async.AsyncControllerActionInvoker.EndInvokeActionMethodWithFilters(IAsyncResult asyncResult) +34
System.Web.Mvc.Async.<>c__DisplayClass2b.b__1c() +26 System.Web.Mvc.Async.<>c__DisplayClass21.b__1e(IAsyncResult asyncResult) +100
System.Web.Mvc.Async.WrappedAsyncResult 1.CallEndDelegate(IAsyncResult asyncResult) +10
System.Web.Mvc.Async.WrappedAsyncResultBase
1.End() +49
System.Web.Mvc.Async.AsyncControllerActionInvoker.EndInvokeAction(IAsyncResult asyncResult) +27
System.Web.Mvc.Controller.b__1d(IAsyncResult asyncResult, ExecuteCoreState innerState) +13
System.Web.Mvc.Async.WrappedAsyncVoid 1.CallEndDelegate(IAsyncResult asyncResult) +29
System.Web.Mvc.Async.WrappedAsyncResultBase
1.End() +49
System.Web.Mvc.Controller.EndExecuteCore(IAsyncResult asyncResult) +36 System.Web.Mvc.Controller.b__15(IAsyncResult asyncResult, Controller controller) +12
System.Web.Mvc.Async.WrappedAsyncVoid 1.CallEndDelegate(IAsyncResult asyncResult) +22
System.Web.Mvc.Async.WrappedAsyncResultBase
1.End() +49
System.Web.Mvc.Controller.EndExecute(IAsyncResult asyncResult) +26
System.Web.Mvc.Controller.System.Web.Mvc.Async.IAsyncController.EndExecute(IAsyncResult asyncResult) +10
System.Web.Mvc.MvcHandler.b__5(IAsyncResult asyncResult, ProcessRequestState innerState) +21
System.Web.Mvc.Async.WrappedAsyncVoid 1.CallEndDelegate(IAsyncResult asyncResult) +29
System.Web.Mvc.Async.WrappedAsyncResultBase
1.End() +49
System.Web.Mvc.MvcHandler.EndProcessRequest(IAsyncResult asyncResult) +28 System.Web.Mvc.MvcHandler.System.Web.IHttpAsyncHandler.EndProcessRequest(IAsyncResult result) +9
System.Web.CallHandlerExecutionStep.System.Web.HttpApplication.IExecutionStep.Execute() +9744373 System.Web.HttpApplication.ExecuteStep(IExecutionStep step, Boolean& completedSynchronously) +155

これを処理するコードのセクションです:

[HttpPost] 
    public ActionResult Index(HttpPostedFileBase file) 
    { 
     if (file.ContentLength > 0) 
     { 
      var fileName = Path.GetFileName(file.FileName); 
      var path = Path.Combine(Server.MapPath("~/App_Data/Temp"), fileName); 
      file.SaveAs(path); 

      // create a barcode reader instance 
      IBarcodeReader reader = new BarcodeReader(); 
      // load a bitmap 
      Bitmap bitmap = new Bitmap(path); 

      Bitmap resized = new Bitmap(bitmap, new Size(400, 400)); 

      // detect and decode the barcode inside the bitmap 
      var result = reader.Decode(resized); 

      bitmap.Dispose(); 

      // Delete file once we have finished with it 
      if (System.IO.File.Exists(path)) 
      { 
       System.IO.File.Delete(path); 
      } 

      // do something with the result 
      if (result != null) 
      { 
       return RedirectToAction("Create", "Audit", new { roomID = result.Text }); 
       //txtDecoderType.Text = result.BarcodeFormat.ToString(); 
      } 

      // Decode error 
      else 
      { 
       return RedirectToAction("Index"); 
      } 
     } 

     // File error 
     else 
     { 
      return RedirectToAction("Index"); 
     }  
    } 

それは私のローカルマシン上で正常に動作しますが、私はそれをオンラインで公開するときに動作していないようです。私は間違いなく、App_Dataというディレクトリと、自分のサイトのルートにあるTempというディレクトリを持っていました。

ご協力いただきまして誠にありがとうございます。

+0

App_DataにTempフォルダがありますか? –

+0

App_Data \ Tempディレクトリ内のイメージに設定されているビルドアクションは何ですか? –

+0

ターゲットディレクトリの権限をチェックしましたか? –

答えて

3

例外は明示的です。そのパスの一部は存在しません。重要なことに、公開中にApp_Dataは含まれていないため、プロジェクトにローカルに存在するという理由だけで、実際にプロダクションサーバーに存在するというわけではありません。それ以外の場合は、パス全体を確認してください。つまり、Cドライブに直接ディレクトリが必要です(siteディレクトリなどが必要です)。

また、すべてが正しい場合は、この例外を回避する方法はありません。そのパスの一部が正しくないか存在しません。

+0

あなたのご意見ありがとうございます。私は今App_Dataを削除し、アプリケーションのルートにTempを移動し、再び公開しました。 C:\ home \ site \ wwwrootビットは、私がホスティングしている会社によって作られたものだと思いますが、まだ動作していません。 – James

0

これをChrisの説明で修正することができました。フォルダ 'Temp'は、アプリケーション全体と一緒に公開しても、存在しませんでした。私はこのフォルダが空だったので、それは他のものすべてで公開されていなかったと仮定しています。だから私は手動で個々のフォルダを公開して、ちょっと前に - それは動作します!

関連する問題