Friday, June 18, 2010

Menu Control binded with Site Map

Code for Site Map (Add web1.sitemap before start in your project.)

STr=?xml version="1.0" encoding="utf-8" ?
siteMap xmlns="http://schemas.microsoft.com/AspNet/SiteMap-File-1.0"

siteMapNode url="" title="" description=""
siteMapNode url="" title="Itinerary" description="hi"
siteMapNode url="main.aspx" title="Search" description="Search Itinerary" /
/siteMapNode
siteMapNode url="" title="Password" description="About" >
siteMapNode url="ChangePassword.aspx" title="Change Password" description="Change Password" />

siteMapNode>-->
siteMapNode url="" title="Setup" description="Setup" >
siteMapNode url="Settings.aspx" title="Setup and Config" description="Setup and Config" />
/siteMapNode>

siteMapNode url="" title="About" description="About" >
siteMapNode url="about.aspx" title="Product" description="Product" />
siteMapNode url="http://www.amadeus.in" title="Amadeus" description="Amadeus" />
/siteMapNode>
/siteMapNode>
/siteMap>

****in above code Please put Evry row in <> Brackets, then it works

Then Code for code behind in Menu page

private void CreateMenuControl()
{
Menu1.DataSource = GetSiteMApDataSource();
Menu1.DataBind();
}

private SiteMapDataSource GetSiteMApDataSource()
{
XmlSiteMapProvider xmlsiteMAp = new XmlSiteMapProvider();
System.Collections.Specialized.NameValueCollection myCollection =
new System.Collections.Specialized.NameValueCollection(1);

if (Session["UserRole"].ToString().ToUpper() == "ADMIN")
{
myCollection.Add("siteMapFile", "web.sitemap");
}
else if (Session["UserRole"].ToString().ToUpper() == "USER")
{
myCollection.Add("siteMapFile", "Web2.sitemap");
}

xmlsiteMAp.Initialize("provider", myCollection);
xmlsiteMAp.BuildSiteMap();
SiteMapDataSource siteMap = new SiteMapDataSource();
siteMap.ShowStartingNode = false;
myCollection = null;
if (Session["UserRole"].ToString().ToUpper() == "ADMIN")
{
siteMap.SiteMapProvider = "DefaultSiteMapProvider";
}
else if (Session["UserRole"].ToString().ToUpper() == "USER")
{
siteMap.SiteMapProvider = "MySiteMapProvider";
}

return siteMap;
}

Download server file on Client Side using ASP.net 2.0

private void DownloadFileMSI()
{
string fname = Server.MapPath("PNRExtractor") + "\\PNRExtractor.msi";
Response.ContentType = "application/exe";
Response.AddHeader("content-disposition", "attachment; filename=PNRExtractor.msi");

//System.IO.FileStream sourceFile = new System.IO.FileStream(@"" + fname, System.IO.FileMode.OpenOrCreate);
System.IO.FileStream sourceFile = new System.IO.FileStream(@"" + fname, System.IO.FileMode.Open, System.IO.FileAccess.Read, System.IO.FileShare.None);
long FileSize;
FileSize = sourceFile.Length;
byte[] getContent = new byte[(int)FileSize];
sourceFile.Read(getContent, 0, (int)sourceFile.Length);
sourceFile.Close();
Response.BinaryWrite(getContent);
}