problem when I publish a Web page and XMl

Veljean
Veljean used Ask the Experts™
on
I have a XML in my solution , the XML is stored in the solution's root.

As long I am in in Visual Studio i can write/edit the XML without problem, but when I publish the page in the IIS i cant edit the XML anymore... I dont know if im using a bad function to retrive the path, Im using:

string path = HttpContext.Current.Server.MapPath(@"~\XMLObjects.xml");

and like I said , it works when is Design mode , but once published not anymore... what i have to do? is something about IIS Configuration?
Comment
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®
Veljean,

Check if that xml has write permission in IIS?

Author

Commented:
Yes, it has Write and Read permissions
Are you able to read the xml atleast ?
Tray896SharePoint Engineer

Commented:
Verify that your application pool identity has NTFS permissions to the content.  You didn't say what version of IIS you were on, but on IIS 6 this would be the IIS_WPG group.  If you're on IIS7.x, then check out this article: http://learn.iis.net/page.aspx/624/application-pool-identities/

Author

Commented:
Hi Tray896, mi IIS version is 5.1, where I can check this?

pramodsk40: Yes i can read the XML

Author

Commented:
it is correct that im trying to open the XML with the sentence : string path = HttpContext.Current.Server.MapPath(@"~\XMLObjects.xml");

I dont know if the published web page is referencing the correct path out of the design mode...

to read the XML im suing javascript, not C#, but for write im using C#

Author

Commented:
I could tack the error:

System.UnauthorizedAccessException: Access to the path 'c:\inetpub\wwwroot\Banamex_23062010\XMLObjects.xml' is denied.

   at System.IO.__Error.WinIOError(Int32 errorCode, String maybeFullPath)

   at 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)

   at System.IO.FileStream..ctor(String path, FileMode mode, FileAccess access, FileShare share, Int32 bufferSize, FileOptions options)

   at _Default.deleteNodeXML(String objBorrado)


I will attach my function if anybody can help me!
  [WebMethod]
     public static string deleteNodeXML(string objBorrado)
     {

         try
         {
         HttpContext.Current.Request.PhysicalApplicationPath;
             string path = HttpContext.Current.Server.MapPath(@"~\XMLObjects.xml");
            
             XmlTextReader filelistReader = new XmlTextReader(path);
             XmlDocument filelistDoc = new XmlDocument();
             filelistDoc.Load(filelistReader);
             filelistReader.Close();

          
             
             XmlElement filelistRoot = filelistDoc.DocumentElement;


             XmlNodeList contentfiles = filelistDoc.SelectNodes("//ObjetoMapTP[@Name='" + objBorrado + "']");

             for (int i = contentfiles.Count - 1; i >= 0; i--)
             {
                 contentfiles[i].ParentNode.RemoveChild(contentfiles[i]);
             }

             StreamWriter directoryWriter = new StreamWriter(File.Create(path));
             try
             {
                 filelistDoc.Save(directoryWriter);
             }
             finally
             {
                 directoryWriter.Close();
                
             }
             return "Xml salvado correctamente!";
         }
         catch (Exception ex)
         {
             string outputBox;
             outputBox = ex.ToString();
             return "Error al cargar XML! :" + outputBox;

         }




     }

Open in new window

Tray896SharePoint Engineer

Commented:
If you're on IIS 5.1 then it is the aspnet local account that needs access.  You'll also need to verify that the IUSR account has access to the content.

Author

Commented:
I found the answer, I just i have to give permission to the ASPNET user, thanks any way

Author

Commented:
oh sorry Tray896 , i didnt see you answer!!! :0 an apologize!!! , that was the correct one , :( i think i cant give the point righ now , im so sorry !!
SharePoint Engineer
Commented:
Answer was given with comment on 7/7 at 11:31 AM.

Author

Commented:
thanks ! ;)

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial