Link to home
Start Free TrialLog in
Avatar of shwaqar82
shwaqar82

asked on

Access to the path is denied

I have the following code:

Try
            webReqGateway = WebRequest.Create("http://drv.sax.softvoyage.com/cgi-bin/gateway_dest.cgi")
            webReqHotel = WebRequest.Create("http://drv.sax.softvoyage.com/cgi-bin/dest_hotels.cgi")
            webResGateway = webReqGateway.GetResponse
            webResHotel = webReqHotel.GetResponse
            strmGateway = New StreamReader(webResGateway.GetResponseStream)
            xmlGateway = New StreamWriter(Server.MapPath("//XML/Gateway.xml"), False)
            xmlHotel = New StreamWriter(Server.MapPath("//XML/Hotel.xml"), False)
            'Console.WriteLine(strmGateway.ReadLine.ToString)
            xmlGateway.WriteLine(strmGateway.ReadToEnd)
            strmHotel = New StreamReader(webResHotel.GetResponseStream)
            xmlHotel.WriteLine(strmHotel.ReadToEnd)
            xmlGateway.Close()
            xmlHotel.Close()
            Try
                'check for errors in xml and replace invalid characters if needed
                docGateway = LoadXMLDoc(Server.MapPath("//XML/Gateway.xml"))
                docHotel = LoadXMLDoc(Server.MapPath("//XML/Hotel.xml"))
            Catch ex As XmlException
                lnum = ex.LineNumber
                ReplaceSpecialChars(Server.MapPath("//XML/Hotel.xml"), lnum)

                docHotel = LoadXMLDoc(Server.MapPath("//XML/Hotel.xml"))
            End Try
            Response.Write("Xml Created on time " & Date.Now.ToString)
        Catch er As XmlException
            Response.Write("Xml could not be created " & er.Message)
        Catch er As HttpException
            Response.Write("Xml could not be created " & er.Message)
        Catch er As Exception
            Response.Write("Xml could not be created " & er.Message)
        End Try

When i run it. It gives me an error message which says:
Xml could not be created Access to the path 'F:\websites\local\dreamvacations\XML\Hotel.xml' is denied.

xmlGateway = New StreamWriter(Server.MapPath("//Gateway.xml"), False)

The above line works fine and create Gateway.xml on root directory which is a network directory(F:\websites\local\dreamvacations) and the web address for this is: http://192.168.0.29 

Also tried the below line:
xmlGateway = New StreamWriter(Server.MapPath("http://192.168.0.29/XML/Gateway.xml"), False)

Doesn't work. Any help please....:(
ASKER CERTIFIED SOLUTION
Avatar of YZlat
YZlat
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of shwaqar82
shwaqar82

ASKER

wat about 3rd step ...how can i give asp.net  user an access to 'F:\websites\local\dreamvacations\XML\Hotel.xml' .

I think the user has an access to read n write. If not then how it can create xml files to root directory which is :
'F:\websites\local\dreamvacations'. Using the below code:

xmlGateway = New StreamWriter(Server.MapPath("//Gateway.xml"), False)
do i have to create user name and password for asp.net user ..how can i do that...As i unchecked anonymous access
you don't neet to, just right-click on Hotel.xml file and select Properties. Then then go to Security tab and look for something like this in the user list:

ASP.NET Machine Acount

If you find it, select it and see if it has necessary permissions to Hotel.xml file.

If you don't see it, click on Add and Type in ASPNET and click on Check Names. Then click OK. Add the necessary permissions for that user
well i cant get that exactly what ur saying ..but yae hotel.xml has read n write permissions. And this application pops up an authentication window once i change the web.congif and add additinal tag in it .

Please help me out :(
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial