Access to the path is denied

Hi, I just started compile the App upload to my iPhone 6 for testing with the following coding ...

        string strUrl = "http://allianz.mes2u.com/images/pic2.png";
        try
        {
            string localBGPath = "Library/Caches/images/MainMenuBGTmp.png";
            if (!File.Exists (localBGPath)) {
                var webClient = new WebClient ();
                byte[] bb = webClient.DownloadData (strUrl);
                if (File.Exists (localBGPath))
                    File.Delete (localBGPath);
                File.WriteAllBytes (localBGPath, bb);
                webClient.Dispose ();
            }
        }
        catch(Exception e) {
            strErrMessage += "Exception: " + e.Message + ",";
        }

I got the error message : Access to the path is denied ...

Do I need any other setting to access file? please help ...

Thanks for your time.

Posts

  • I have the same problem. Do you have a solution?

  • JasonAwbreyJasonAwbrey USInsider, University, Developer Group Leader mod

    You can only access file paths that are inside of your app's bundle - this is due to iOS sandboxing.

  • vincent.2463vincent.2463 USMember ✭✭

    There are changes in iOS8 ... the application path. I use the following code to get the path.

                NSUrl[] myNSUrl = NSFileManager.DefaultManager.GetUrls (NSSearchPathDirectory.DocumentDirectory, NSSearchPathDomain.User);
    
                GlobalVar.documentsPath = myNSUrl [0].ToString ();
                if (GlobalVar.documentsPath.Substring (0, 7) == "file://") {
                    GlobalVar.documentsPath = GlobalVar.documentsPath.Substring (7);
                }
                if (GlobalVar.documentsPath.Substring (0) != "/") {
                    GlobalVar.documentsPath = "/" + GlobalVar.documentsPath;
                }
    
  • MariahAlbertMariahAlbert USMember

    JasonAwbrey is right, due to sand boxing you can only access file paths that are in your app's bundle.

    Mariah Albert
    iPhone Development Company

  • MariahAlbertMariahAlbert USMember

    JasonAwbrey is right, due to iOS sandboxing, you can only access file paths that are inside of your app's bundle.

    Mariah Albert
    iPhone application Development company

  • MariahAlbertMariahAlbert USMember

    JasonAwbrey is right, due to sand boxing you can only access file paths that are in your app's bundle.

    Mariah Albert
    iPhone Development Company

  • MariahAlbertMariahAlbert USMember

    JasonAwbrey is right, due to iOS sandboxing, you can only access file paths that are inside of your app's bundle.

    Mariah Albert
    iPhone application Development company

Sign In or Register to comment.