1
Answer

Access to the path 'C:\inetpub\IDMS\Development\Web.sitemap'

Hazel Mahmud

Hazel Mahmud

8y
463
1
i got problem as image attached when i create dynamic sitemap using XMLTextWriter. can anyone help me to solve the problem.
 
 
 below are my aspx.cs coding...
 
Response.Clear();

Response.ContentType = "text/xml";

using (XmlTextWriter writer = new XmlTextWriter(Server.MapPath("Web.sitemap"), Encoding.UTF8))
{
writer.WriteStartDocument();
writer.WriteRaw("\n");
writer.WriteStartElement("siteMap");
writer.WriteAttributeString("xmlns", "http://schemas.microsoft.com/AspNet/SiteMap-File-1.0");

writer.WriteRaw("\n");
writer.WriteRaw("\t");
writer.WriteStartElement("siteMapNode");
writer.WriteAttributeString("url", "~/index.aspx");
writer.WriteAttributeString("title", "Home");
writer.WriteRaw("\n");
writer.WriteRaw("\t\t");
writer.WriteStartElement("siteMapNode");
writer.WriteAttributeString("url", "~/MainPage/MyProfile.aspx?Value=" + lblsystemID.Text);
writer.WriteAttributeString("title", "Self-Service");
using (SqlConnection con = ClassConn.GetPortalCon())
{

SqlCommand cmd = new SqlCommand("ret_Menu", con);
cmd.CommandType = CommandType.StoredProcedure;

cmd.Parameters.AddWithValue("@userID", nopkj);
cmd.Parameters.AddWithValue("@systemID", lblsystemID.Text);

SqlDataReader sc = cmd.ExecuteReader();

if (sc.HasRows)
{
while (sc.Read())
{

var menuID = sc["menuID"].ToString();

writer.WriteRaw("\n"); writer.WriteRaw("\t\t\t");
writer.WriteStartElement("siteMapNode");
writer.WriteAttributeString("url", sc["menuPath"].ToString());
writer.WriteAttributeString("title", sc["menu_label"].ToString());
writer.WriteAttributeString("description", sc["menu_label"].ToString());
writer.WriteAttributeString("menuID", sc["menuID"].ToString());

using (SqlConnection con1 = ClassConn.GetPortalCon())
{

SqlCommand cmd1 = new SqlCommand("ret_SubMenuSiteMap", con1);
cmd1.CommandType = CommandType.StoredProcedure;
cmd1.Parameters.AddWithValue("@userID", nopkj);
cmd1.Parameters.AddWithValue("@systemID", lblsystemID.Text);
cmd1.Parameters.AddWithValue("@menuID", menuID);

SqlDataReader sc1 = cmd1.ExecuteReader();

if (sc1.HasRows)
{
while (sc1.Read())
{

writer.WriteRaw("\n");
writer.WriteRaw("\t\t\t\t");
writer.WriteStartElement("siteMapNode");
writer.WriteAttributeString("subMenuID", sc1["MenuIDsub"].ToString());
writer.WriteAttributeString("title", sc1["submenu_label"].ToString());
writer.WriteAttributeString("description", sc1["submenu_label"].ToString());
writer.WriteEndElement();
}
}

}
writer.WriteEndElement();

}
}
}
writer.WriteEndElement();
writer.WriteEndDocument();
}


Response.Redirect("index.aspx");
Answers (1)