Hey All,
I had a requirment to show custom error page in my MOSS 2007 site. I tried couple of options like changing the node customErrors "On" & specified URL for DefaultRedirect in Web.config And editing the custom error locations in the properties of the site.
Both of them did not work & i tried the steps mentioned in the following URL.
Click Here
It worked fine :)
Blog from a software professional, Passionate to work in latest cutting edge technologies in order to get better results in business.
Monday, March 31, 2008
Saturday, March 29, 2008
Ajax based Dynamic User Control for Menu from Master Page in MOSS 2007 Site
Hi All,
I had an interesting requirement in one of my previous project. A single control (user control) will display the Menu appropriate to the respective page the user has browsed currently. Moreover, in future if any new page is added to the site by site-administrator. The Menu automatically gets updated & display with the new link added.
For example, the classification in the website is like below.
Home
A Page
A1 Page
A11 Page
A12 Page
A2 Page
A21 Page
B Page
B1 Page
B2 Page
B21 Page
B22 Page
So when the user is in section-A either in page A or page A12 He will be seeing the Menus built for all the links in A Section & in case if he is in Section-B, all the available page in B section are shown to him in menu.
In addition, there are many branches similar to the hierarchy shown above & this functionality is achieved with a single User control, which binds dynamically. The Ajax based dynamic user control for the menu is placed in Master page of the site so that it is available in all the pages & you can view the above-mentioned functionality implemented in
www.kockw.com
The Steps to implement & the source code of the user control is placed in the document URL given below.
Elaborated Description for IE users
Elaborated Description for Firefox users
Any queries regarding implementation are welcome...
Thanks
Fauzi
I had an interesting requirement in one of my previous project. A single control (user control) will display the Menu appropriate to the respective page the user has browsed currently. Moreover, in future if any new page is added to the site by site-administrator. The Menu automatically gets updated & display with the new link added.
For example, the classification in the website is like below.
Home
A Page
A1 Page
A11 Page
A12 Page
A2 Page
A21 Page
B Page
B1 Page
B2 Page
B21 Page
B22 Page
So when the user is in section-A either in page A or page A12 He will be seeing the Menus built for all the links in A Section & in case if he is in Section-B, all the available page in B section are shown to him in menu.
In addition, there are many branches similar to the hierarchy shown above & this functionality is achieved with a single User control, which binds dynamically. The Ajax based dynamic user control for the menu is placed in Master page of the site so that it is available in all the pages & you can view the above-mentioned functionality implemented in
www.kockw.com
The Steps to implement & the source code of the user control is placed in the document URL given below.
Elaborated Description for IE users
Elaborated Description for Firefox users
Any queries regarding implementation are welcome...
Thanks
Fauzi
Thursday, March 13, 2008
C# code talking to Active Directory
For one of my clients work the requirment is like that we have users fill out Infopath forms 2007. So there needs to be a code behind (c#) to validate the user in the domain to find from which group he is from.... doing that it came my mind how will i get all the email Ids from a domain... Yup following is the code the talks to your Active Directory in the domain & gets all the Email IDs available....
Belive me, i am not a spammer.... i just do these things for fun :)
using System.DirectoryServices;
namespace ConsoleApplication1
{
class Program
{
static void Main (string[] args)
{
SAM d = new SAM();
string f = d.GetEmail("*");
}
}
class SAM
{
public string GetEmail(string ntname)
{
DirectorySearcher objsearch = new DirectorySearcher();
string strrootdse = objsearch.SearchRoot.Path;
DirectoryEntry objdirentry = new DirectoryEntry(strrootdse);
objsearch.Filter = "(& (mailnickname=" + ntname.Trim() + ")(objectClass=user))";
objsearch.SearchScope = System.DirectoryServices.SearchScope.Subtree;
objsearch.PropertiesToLoad.Add("mail");
objsearch.PropertyNamesOnly = true;
SearchResultCollection colresults = objsearch.FindAll();
string arl = "";
foreach (SearchResult objresult in colresults)
{
arl = arl + objresult.GetDirectoryEntry().Properties["mail"].Value + ";";
}
if (arl.Length > 0)
arl = arl.Substring(0, arl.Length - 1);
objsearch.Dispose();
return arl;
}
}
}
Belive me, i am not a spammer.... i just do these things for fun :)
using System.DirectoryServices;
namespace ConsoleApplication1
{
class Program
{
static void Main (string[] args)
{
SAM d = new SAM();
string f = d.GetEmail("*");
}
}
class SAM
{
public string GetEmail(string ntname)
{
DirectorySearcher objsearch = new DirectorySearcher();
string strrootdse = objsearch.SearchRoot.Path;
DirectoryEntry objdirentry = new DirectoryEntry(strrootdse);
objsearch.Filter = "(& (mailnickname=" + ntname.Trim() + ")(objectClass=user))";
objsearch.SearchScope = System.DirectoryServices.SearchScope.Subtree;
objsearch.PropertiesToLoad.Add("mail");
objsearch.PropertyNamesOnly = true;
SearchResultCollection colresults = objsearch.FindAll();
string arl = "";
foreach (SearchResult objresult in colresults)
{
arl = arl + objresult.GetDirectoryEntry().Properties["mail"].Value + ";";
}
if (arl.Length > 0)
arl = arl.Substring(0, arl.Length - 1);
objsearch.Dispose();
return arl;
}
}
}
Tuesday, March 11, 2008
Threading Sample in C# 2.0
Here is sample for Threading concept in C# 2.0.
First, Create a web application
The Namespace to be used is System.Threading;
We create two methods Threadjob & Threadjob1.And Inside Page_Load we create objects ts1 & ts for ThreadStart. ThreadStart is a Delegate for System.Threading.Thread. And we create objects
T & T1 for class Thread & Start them. Now to understand its operation place the breakpoints above the commented places in the code given below. Based on the sleep time & number of threads you will see the flow jumping here & there... thats how its works :)
Followign is its code:
******************
using System;
using System.Data;
using System.Configuration;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Threading;
public partial class _Default : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
ThreadStart ts = new ThreadStart(Threadjob);
ThreadStart ts1 = new ThreadStart(Threadjob1);
Thread T = new Thread(ts);
Thread T1 = new Thread(ts1);
T.Start();
T1.Start();
}
}
void Threadjob()
{
for (int l = 0; l <= 10; l++)
Response.Write("\n Method " + l.ToString());
//Have Break point #1 Here...
Thread.Sleep(1500);
}
void Threadjob1()
{
for (int l1 = 0; l1 <= 10; l1++)
Response.Write("\n 2nd Method " + l1.ToString());
//Have Break point #2 Here...
Thread.Sleep(1500);
}
}
**************************************
First, Create a web application
The Namespace to be used is System.Threading;
We create two methods Threadjob & Threadjob1.And Inside Page_Load we create objects ts1 & ts for ThreadStart. ThreadStart is a Delegate for System.Threading.Thread. And we create objects
T & T1 for class Thread & Start them. Now to understand its operation place the breakpoints above the commented places in the code given below. Based on the sleep time & number of threads you will see the flow jumping here & there... thats how its works :)
Followign is its code:
******************
using System;
using System.Data;
using System.Configuration;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Threading;
public partial class _Default : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
ThreadStart ts = new ThreadStart(Threadjob);
ThreadStart ts1 = new ThreadStart(Threadjob1);
Thread T = new Thread(ts);
Thread T1 = new Thread(ts1);
T.Start();
T1.Start();
}
}
void Threadjob()
{
for (int l = 0; l <= 10; l++)
Response.Write("\n Method " + l.ToString());
//Have Break point #1 Here...
Thread.Sleep(1500);
}
void Threadjob1()
{
for (int l1 = 0; l1 <= 10; l1++)
Response.Write("\n 2nd Method " + l1.ToString());
//Have Break point #2 Here...
Thread.Sleep(1500);
}
}
**************************************
Wednesday, March 5, 2008
EXE for Monitoring Backups.... Cool Tool
Hi,
One fine day... Thought let me do somthing Coool @ work... mmmm got a idea.....
At present we have schedule for a daily backup of our MOSS 2007 Sharepoint internet facing site. And my senior team member have asked me to verify it daily. Thought why don't we automate this..... Yup i have created C# console application (Scheduled to run every day after the backup is done.) which will check the date of the backup folder & if matches the current date it will send an acknowledgment mail else if the backup failed it will be an alert for us to investigate.
Following is its code:
****************
using System;
using System.Collections.Generic;
using System.Text;
using System.IO;
using System.Net.Mail;
namespace BackupChecker
{
class Program
{
static void Main(string[] args)
{
if (System.IO.File.Exists("Tivoli\\spbrtoc.xml"))
{
System.IO.FileInfo fo = new FileInfo("Tivoli\\spbrtoc.xml");
SmtpClient smtp = new SmtpClient("mail.YourSMTP.com");
smtp.UseDefaultCredentials = true;
StreamWriter sr = new StreamWriter("Checklog.log",true);
sr.WriteLine("Update on " + System.DateTime.Now.ToString());
sr.Flush();
sr.Close();
try
{
if (fo.LastWriteTime.Date.ToShortDateString() == System.DateTime.Now.ToShortDateString())
{
MailMessage msg = new MailMessage("fazuking@hotmail.com",”mohammedfauzi_vm@yahoo.com,Teammate#1,Teammate#2", "www.MySite.com Backup Done", "The www.MySite.com site backup was done Successfully. This is an Auto generated mail sent on " + System.DateTime.Now.ToLongTimeString());
smtp.Send(msg);
}
else
{
MailMessage msg = new MailMessage("fazuking@hotmail.com",”mohammedfauzi_vm@yahoo.com,Teammate#1,Teammate#2", "www.MySite.com Backup Done", "The www.MySite.com site backup was Un-Successfully. This is an Auto generated mail sent on " + System.DateTime.Now.ToLongTimeString());
smtp.Send(msg);
}
}
catch (Exception ex)
{
StreamWriter sr1 = new StreamWriter("Checklog.log",true);
sr1.NewLine = ("\r\n");
sr1.WriteLine("Error: " + ex.Message + " on " + System.DateTime.Now.ToString());
sr1.Flush();
sr1.Close();
}
}
}
}
}
***************************************
Now things are automated.... Stay Relaxed.... Let think whats next :)
Hope this should be helpful to friends who needs to keep track of specific folders.
Warm Regards
Mohammed Fauzi
One fine day... Thought let me do somthing Coool @ work... mmmm got a idea.....
At present we have schedule for a daily backup of our MOSS 2007 Sharepoint internet facing site. And my senior team member have asked me to verify it daily. Thought why don't we automate this..... Yup i have created C# console application (Scheduled to run every day after the backup is done.) which will check the date of the backup folder & if matches the current date it will send an acknowledgment mail else if the backup failed it will be an alert for us to investigate.
Following is its code:
****************
using System;
using System.Collections.Generic;
using System.Text;
using System.IO;
using System.Net.Mail;
namespace BackupChecker
{
class Program
{
static void Main(string[] args)
{
if (System.IO.File.Exists("Tivoli\\spbrtoc.xml"))
{
System.IO.FileInfo fo = new FileInfo("Tivoli\\spbrtoc.xml");
SmtpClient smtp = new SmtpClient("mail.YourSMTP.com");
smtp.UseDefaultCredentials = true;
StreamWriter sr = new StreamWriter("Checklog.log",true);
sr.WriteLine("Update on " + System.DateTime.Now.ToString());
sr.Flush();
sr.Close();
try
{
if (fo.LastWriteTime.Date.ToShortDateString() == System.DateTime.Now.ToShortDateString())
{
MailMessage msg = new MailMessage("fazuking@hotmail.com",”mohammedfauzi_vm@yahoo.com,Teammate#1,Teammate#2", "www.MySite.com Backup Done", "The www.MySite.com site backup was done Successfully. This is an Auto generated mail sent on " + System.DateTime.Now.ToLongTimeString());
smtp.Send(msg);
}
else
{
MailMessage msg = new MailMessage("fazuking@hotmail.com",”mohammedfauzi_vm@yahoo.com,Teammate#1,Teammate#2", "www.MySite.com Backup Done", "The www.MySite.com site backup was Un-Successfully. This is an Auto generated mail sent on " + System.DateTime.Now.ToLongTimeString());
smtp.Send(msg);
}
}
catch (Exception ex)
{
StreamWriter sr1 = new StreamWriter("Checklog.log",true);
sr1.NewLine = ("\r\n");
sr1.WriteLine("Error: " + ex.Message + " on " + System.DateTime.Now.ToString());
sr1.Flush();
sr1.Close();
}
}
}
}
}
***************************************
Now things are automated.... Stay Relaxed.... Let think whats next :)
Hope this should be helpful to friends who needs to keep track of specific folders.
Warm Regards
Mohammed Fauzi
Subscribe to:
Posts (Atom)