2013-07-30 6 views
0

브라우저에서 다운로드 할 Excel 문서를 만들기 위해 EPPlus (멋진 라이브러리의 경우 devs에 소품)를 사용하고 있습니다. Excel 문서를 생성하는 코드에서 Excel 문서에 이미지 파일을 포함 할 몇 줄의 행이 있습니다.C#으로 서버 경로 가져 오기

Image logoImg = Image.FromFile(Server.MapPath("~/Images/bill_logo.png")); 
var logo = ws.Drawings.AddPicture("Logo", logoImg); 

내 시스템에서 로컬로 프로젝트를 실행하면 이미지가 예상대로 표시됩니다. 그러나, 나는 푸른 우리의 테스트 환경에 배포 할 때, 다음과 같은 에러가 발생합니다

System.IO.FileNotFoundException: C:\DWASFiles\Sites\sitename\VirtualDirectory0\site\wwwroot\Images\bill_logo.png 
at System.Drawing.Image.FromFile(String filename, Boolean useEmbeddedColorManagement) 
at System.Drawing.Image.FromFile(String filename) 
at emergePortal.Web.Controllers.BillingController.buildWorksheet(ExcelWorksheet ws, String sheetName, IEnumerable`1 lineItems) in c:\a\src\emergePortal\emergePortal.Web\Controllers\BillingController.cs:line 202 
at emergePortal.Web.Controllers.BillingController.getBill(Int32 billMonth, Int32 billYear) in c:\a\src\emergePortal\emergePortal.Web\Controllers\BillingController.cs:line 106 
at lambda_method(Closure , ControllerBase , Object[]) 
at System.Web.Mvc.ActionMethodDispatcher.Execute(ControllerBase controller, Object[] parameters) 
at System.Web.Mvc.ReflectedActionDescriptor.Execute(ControllerContext controllerContext, IDictionary`2 parameters) 
at System.Web.Mvc.ControllerActionInvoker.InvokeActionMethod(ControllerContext controllerContext, ActionDescriptor actionDescriptor, IDictionary`2 parameters) 
at System.Web.Mvc.Async.AsyncControllerActionInvoker.<>c__DisplayClass42.<BeginInvokeSynchronousActionMethod>b__41() 
at System.Web.Mvc.Async.AsyncResultWrapper.<>c__DisplayClass8`1.<BeginSynchronous>b__7(IAsyncResult _) 
at System.Web.Mvc.Async.AsyncResultWrapper.WrappedAsyncResult`1.End() 
at System.Web.Mvc.Async.AsyncControllerActionInvoker.EndInvokeActionMethod(IAsyncResult asyncResult) 
at System.Web.Mvc.Async.AsyncControllerActionInvoker.<>c__DisplayClass37.<>c__DisplayClass39.<BeginInvokeActionMethodWithFilters>b__33() 
at System.Web.Mvc.Async.AsyncControllerActionInvoker.<>c__DisplayClass4f.<InvokeActionMethodFilterAsynchronously>b__49() 
at System.Web.Mvc.Async.AsyncControllerActionInvoker.<>c__DisplayClass37.<BeginInvokeActionMethodWithFilters>b__36(IAsyncResult asyncResult) 
at System.Web.Mvc.Async.AsyncResultWrapper.WrappedAsyncResult`1.End() 
at System.Web.Mvc.Async.AsyncControllerActionInvoker.EndInvokeActionMethodWithFilters(IAsyncResult asyncResult) 
at System.Web.Mvc.Async.AsyncControllerActionInvoker.<>c__DisplayClass25.<>c__DisplayClass2a.<BeginInvokeAction>b__20() 
at System.Web.Mvc.Async.AsyncControllerActionInvoker.<>c__DisplayClass25.<BeginInvokeAction>b__22(IAsyncResult asyncResult) 

이 환경에서 작동하도록이 이미지 파일을 참조 할 수있는 가장 좋은 방법은 무엇입니까?

+0

설정 읽고 당신의 이미지가 내가 잘못 될 수있다 –

+0

폴더에 쓰기 참조 내가 당신의 문제에 대한이 코드를 사용 생각 처음은 아니지만 Azure에서 권한을 편집 할 수 있다고 생각하지 않습니다. – Trevor

+0

티켓을 Azure로 보낼 수 있습니다. http://www.windowsazure.com/en-us/support/options/ –

답변

0

예외의 주어진 경로가 해당 파일의 올바른 경로입니까? 그렇다면 권리가 있습니까? 그렇지 않은 경우에는 예외입니다. :)

+0

정확한 경로인지 확실하지 않습니다. 저는 Azure에서 프로젝트의 파일 구조에 대한 가시성을 가지고 있지 않습니다. 파일에 대한 권한을 확인합니다. 단지 읽기 권한 만 필요하다고 가정합니다. – Trevor

+0

주위를 검색 한 후 Azure에서 파일 권한을 변경할 수 있다고 생각하지 않습니다. 누군가 나를 교정 할 수 있습니까? http://stackoverflow.com/questions/11016098/folder-permissions-in-azure-web-sites – Trevor

0

하늘을 배포 할 때이 동일한 문제가 발생했습니다. 는 Server.MapPath 내가 어떻게이

이 코드 방법을 시도하십시오이 problem.sorry를 해결 할 것을 잊지 나누었다이 문제를 해결 푸른

에서 작동하지 않습니다됩니다. 나는 '같으면,

// Retrieve an object that points to the local storage resource 
LocalResource localResource = RoleEnvironment.GetLocalResource("localStoreTwo"); 

//Define the file name and path 
string[] paths = { localResource.RootPath, "MyStorageTest.txt"}; 
String filePath = Path.Combine(paths); 

자세한 내용이

Getting Your Physical Application Path in Window Azure

Msdn