Answered working with xml in App_data folder

  • Tuesday, August 07, 2012 4:25 PM
     
      Has Code

    Hi,

    I have .xml file in App_data folder and app is hosted in Azure. When I work with content of this file I get this error:

    Could not find a part of the path 'E:\sitesroot\0\App_Data\Options.xml'.

    here is the .aspx.cs example:

    XDocument doc = XDocument.Load(Server.MapPath("~/App_Data/Options.xml"));
                    if (doc.XPathSelectElement("Options/MemberCode").FirstAttribute.Value == "true")
                    {
                        TextBoxMemberCode.Enabled = true;
                    }

    In IIS and localhost it works perfectly but I know that Azure is something different...

    How can I solve this trouble ??

All Replies

  • Tuesday, August 07, 2012 4:37 PM
     
     

    Hi,

    Just a quick check,

    In the properties of the Options.xml, Have you enabled "Copylocal=true"?


    I hope it helps!! If you found this post useful, Please "Mark as answer" or "Vote as Helpful". Thanks! VIJAY.

  • Tuesday, August 07, 2012 4:47 PM
     
     

    I don´t see Copylocal properties in Properties of .xml.

  • Tuesday, August 07, 2012 5:25 PM
     
     

    Sorry my bad,

    Make "Copy to output directory" to "Copy always" it will work


    I hope it helps!! If you found this post useful, Please "Mark as answer" or "Vote as Helpful". Thanks! VIJAY.

  • Tuesday, August 07, 2012 8:55 PM
     
     
    Doesn´t work...the same error...
  • Wednesday, August 08, 2012 2:02 AM
    Moderator
     
     Answered Has Code

    Hi,

    I'd like to suggest you use Remote Desktop to connect Azure VM and see that XML file is existing. As far as i know, azure package is deployed it's not creating the /App_Data/ folder, you can check for this.

    And i dont think this is a good way to put xml file in app root directory:

    1, security reason. it's not a good practice that the worker account has write access to the app directory.

    2, recycling reson. when a certain amount of files (or directories) change or get created, IIS might decide to recycle the app domain.

    The better solution is local storage, try this:

    Service definition:

    <LocalResources>
          <LocalStorage name="cacheStorage" sizeInMB="20480" cleanOnRoleRecycle="false" />
    </LocalResources>
    

    Code:
    string cachePath = RoleEnvironment.GetLocalResource("cacheStorage").RootPath;
    string filePath = Path.Combine(cachePath, filename); 
    

    Hope this helps.

    Please mark the replies as answers if they help or unmark if not. If you have any feedback about my replies, please contact msdnmg@microsoft.com Microsoft One Code Framework