イメージを自分の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, IDictionary2 parameters) +157
2 parameters) +27
System.Web.Mvc.ControllerActionInvoker.InvokeActionMethod(ControllerContext controllerContext, ActionDescriptor actionDescriptor, IDictionary
System.Web.Mvc.Async.AsyncControllerActionInvoker.b__39(IAsyncResult asyncResult, ActionInvocation innerInvokeState) +22
System.Web.Mvc.Async.WrappedAsyncResult2.CallEndDelegate(IAsyncResult asyncResult) +29
1.End() +49
System.Web.Mvc.Async.WrappedAsyncResultBase
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.WrappedAsyncResult1.CallEndDelegate(IAsyncResult asyncResult) +10
1.End() +49
System.Web.Mvc.Async.WrappedAsyncResultBase
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.WrappedAsyncResult1.CallEndDelegate(IAsyncResult asyncResult) +10
1.End() +49
System.Web.Mvc.Async.WrappedAsyncResultBase
System.Web.Mvc.Async.AsyncControllerActionInvoker.EndInvokeAction(IAsyncResult asyncResult) +27
System.Web.Mvc.Controller.b__1d(IAsyncResult asyncResult, ExecuteCoreState innerState) +13
System.Web.Mvc.Async.WrappedAsyncVoid1.CallEndDelegate(IAsyncResult asyncResult) +29
1.End() +49
System.Web.Mvc.Async.WrappedAsyncResultBase
System.Web.Mvc.Controller.EndExecuteCore(IAsyncResult asyncResult) +36 System.Web.Mvc.Controller.b__15(IAsyncResult asyncResult, Controller controller) +12
System.Web.Mvc.Async.WrappedAsyncVoid1.CallEndDelegate(IAsyncResult asyncResult) +22
1.End() +49
System.Web.Mvc.Async.WrappedAsyncResultBase
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.WrappedAsyncVoid1.CallEndDelegate(IAsyncResult asyncResult) +29
1.End() +49
System.Web.Mvc.Async.WrappedAsyncResultBase
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というディレクトリを持っていました。
ご協力いただきまして誠にありがとうございます。
App_DataにTempフォルダがありますか? –
App_Data \ Tempディレクトリ内のイメージに設定されているビルドアクションは何ですか? –
ターゲットディレクトリの権限をチェックしましたか? –