Click here to Skip to main content
15,902,938 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
protected void test_Click(object sender, EventArgs e)
{
XmlDocument Reportxml = new XmlDocument();
try
{
// Specify the directory you want to manipulate.
string path = Server.MapPath("Store/Reports");

try
{
// Determine whether the directory exists.
if (!Directory.Exists(path))
{
// Try to create the directory.
DirectoryInfo di = Directory.CreateDirectory(path);
}
}
catch (Exception ex)
{
ScriptManager.RegisterStartupScript(Page, typeof(Page),
"ShowAlert",
string.Format(@"
function _showAlert() {{Sys.Application.remove_load(_showAlert);
radalert('{0}', null, 100, '{1}');}};
Sys.Application.add_load(_showAlert);", "Error occured while creating Reports directory.</br>Reason: " + ex.Message, "BMS Forecast Consolidator"), true);
}

string text = Server.MapPath("Store/Reports/PublishedReport.xml");
string text2 = Server.MapPath("Store/Reports/PublishedReport2.xml");

{
Reportxml.Load(text);


XmlNodeList elements = Reportxml.SelectNodes("//OlapReports/OlapReport");
var currentnode = ocGeneric.OlapManager.CurrentOlapReport.Name;

foreach (XmlElement element in elements)
{
string ReportName = element.GetAttribute("Name");
// int RptName = Int32.Parse(element.GetAttribute("Name"));

string xPathExpression = "/OlapReports/OlapReport[@Name=' " + ReportName + "']";
XmlElement SingleRptNode = (XmlElement)Reportxml.SelectSingleNode(xPathExpression);
string displar = xPathExpression.Trim().Clone().ToString();

// ReportName.Clone().ToString();
// Reportxml.Save("PublishedReport2");
Reportxml.Save("Store/Reports/PublishedReport2.xml");

}
}
ocGeneric.OlapManager.SaveReports(Server.MapPath("Store/Reports/PublishedReport2.xml"));


}

catch (Exception ex)
{
ScriptManager.RegisterStartupScript(Page, typeof(Page),
"ShowAlert",
string.Format(@"
function _showAlert() {{Sys.Application.remove_load(_showAlert);
radalert('{0}', null, 100, '{1}');}};
Sys.Application.add_load(_showAlert);", "Error occured while publising report.</br>Reason: " + ex.Message, "test"), true);
}
}
Posted

1 solution

Use LINQ to XML... find a good article at


LINQ to XML[^]
 
Share this answer
 
Comments
Narayan.mi 8-Nov-11 9:12am    
Thank you, but can we go it through c#. My main problem is to save the selected node in other xml file.
Pandya Anil 10-Nov-11 4:16am    
Linq to XML is within C# only..
follow the link to find how to create a xml document using the LINQ
http://msdn.microsoft.com/en-us/library/bb387075.aspx
Narayan.mi 10-Nov-11 6:31am    
main problem is if you see in my code variable current node is returning value i have to compare it with another node and save that matched node in another xml file. plz help

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900