Thursday, September 23, 2010

subsites in sharepoint

this code snippet retrieving all sub sites from the root site in Share point Server 2007

SPSite site = new SPSite("http://win-j40e6cmrcl9/personal/administrator/");
string[] subsites = site.AllWebs.Names;
for (int i = 0; i < subsites.Length; i++)
{
SPWeb web = site.AllWebs[i];
Response.Write(web.Name.ToString());

}

Tuesday, September 21, 2010

Site deleting in sharepoint server

Deleting the site from the share point server can be done via STSADM.EXE and through the central administration.

switch command prompt

C:\Program Files\Common Files\microsoft shared\Web Server Extensions\12\BIN\STSADM -o deletesite -url http://localhost/sites/Murugesan




Through Central Administration,

Click on Application Management and Delete Site collection,choose the site name under the web application.


Wednesday, September 15, 2010

Site backup in Moss 2007


Site backup in moss 2007 is not an rocket science anymore.
Download the tool Smigrate.exe from the Microsoft site.
extract under the Bin folder of the 12 hive.

pass the command
sMigrate.exe -w http://localhost/sites/Murugesan -f Murugesan1.fwp -u administrator -pw your password

Yes ! look at the command window for the status of the given command.

Friday, September 10, 2010

Listing all webpages from moss site

Listing the all the webpages from the site in MOSS 2007/sharepoint service
I used to itereate the file names using the Sharepoint Object Model's SPListItems

SPSite mySite = new SPSite("http://localhost/MurugesanSite/");
SPWeb myWeb = mySite.OpenWeb();
SPList NoOfPages= myWeb.Lists[2];
foreach(SPListItem items in NoOfPages.Items)
{
Response.Write(items.File.ToString());
}

}






Monday, September 06, 2010

Calling usercontrol in sharepoint webparts


Create the usual User Control in asp.net and calling into Share point is simple process that reduces the complexity of deploying and developing the web part.
Place the 2 text boxes and label to create simple add two number calculator in your
On click of the button result will be displayed on label.


protected void Button1_Click(object sender, EventArgs e)
{
int a = Convert.ToInt32(TextBox1.Text);
int b = Convert.ToInt32(TextBox2.Text);
Label3.Text = (a + b).ToString();
}


Before using the user control check it on .aspx file by registering the user control in directives.

<%@ Register Src="~/Calculator.ascx" TagName="_userCntrl" TagPrefix="SP" %>

once you tested the user control on .aspx file,now you are ready to place the
user control design page calculator.ascx and source code file calculator.ascx.cs in to share point folder structure

C:\Program Files\Common Files\Microsoft Shared\web server extensions\12\TEMPLATE\LAYOUTS

Now go to visual studio,select the Webpart template,


public class UserControlCalculator : System.Web.UI.WebControls.WebParts.WebPart
{
Control _cntrl;
string ErrorDesc;
public UserControlCalculator()
{
this.ExportMode = WebPartExportMode.All;
}

protected override void CreateChildControls()
{
base.CreateChildControls();
try
{
_cntrl =Page.LoadControl("\\_layouts\\Calculator.ascx");
this.Controls.Add(_cntrl);

}
catch (Exception ex)
{
ErrorDesc = ex.Message.ToString();
}

}
protected override void Render(HtmlTextWriter writer)
{
try
{
_cntrl.RenderControl(writer);
}
catch (Exception ex)

{
writer.Write(ex.Message.ToString());
}
}


}