protected void Button1_Click(object sender, EventArgs e)
{
SPSite roosite = new SPSite(TextBox1.Text);
Label1.Text = "Root collection found at Url " + roosite.Url.ToString() + " <br> is part of Web Application " + roosite.WebApplication.Name;
}
protected void Button2_Click(object sender, EventArgs e)
{
SPSite site = new SPSite("
http://madhanpc:8089");
SPWebCollection sites = site.AllWebs;
string[] names = sites.Names;
foreach (string name in names)
Response.Write(name + "<BR>");
}
protected void Button3_Click(object sender, EventArgs e)
{
SPSite site = new SPSite("
http://madhanpc:8089");
SPWeb web = site.AllWebs[0];
foreach (SPList list in web.Lists)
{
Response.Write(list.Title + " " + list.ItemCount + "<br>");
}
Response.Write(web.Lists.Count);
}
protected void Button4_Click(object sender, EventArgs e)
{
SPSite site = new SPSite("
http://madhanpc:8089");
SPWeb web = site.OpenWeb();
web.AllowUnsafeUpdates = true;
SPWebCollection subsite = web.Webs;
try
{
SPWeb newSubWeb = subsite.Add("Morning123", "Morning", "Morning only", 1033, "STS#1", false, false);
Response.Write("New site created.");
}
catch (Exception ex)
{
Response.Write("Is not created.." + ex.Message);
}
}
protected void Button5_Click(object sender, EventArgs e)
{
//Accessing List Item Values
//Create one site and a task with some items
SPSite rootSite = new SPSite("
Http://madhanpc:8089");
SPWeb web = rootSite.AllWebs["MyTeam"];
//SPList :- Represents a list on a SharePoint Web site.
SPList taskList = web.Lists["tests"];
//SPListItem :- Represents an item or row in a list.
foreach (SPListItem item in taskList.Items)
{
Response.Write("Item Name " + item.Name + "Assigner To " + item["AssignedTo"] + "Due Date " + item["DueDate"] + "<br>");
}
}
protected void Button6_Click(object sender, EventArgs e)
{
SPSite rootSite = new SPSite("
Http://madhanpc:8089/myteam");
SPWeb web = rootSite.OpenWeb();
//Security setting that allows you to add to / modify the site
web.AllowUnsafeUpdates = true;
SPList taskList = web.Lists["Tests"];
//Adding new task
SPListItem newTask = taskList.Items.Add();
newTask["Title"] = "Create WP";
newTask["PercentComplete"] = 0.1;
newTask["Assigned To"] = "15;#MADHANPC\\emp1";
newTask.Update();
Response.Write("items manupulation completed..");
}
protected void Button7_Click(object sender, EventArgs e)
{
SPSite rootSite = new SPSite("
Http://madhanpc:8089/myteam");
SPWeb web = rootSite.OpenWeb();
//Security setting that allows you to add to / modify the site
web.AllowUnsafeUpdates = true;
SPListTemplate sourceTemplate = web.ListTemplates["Tasts"];
Guid newListGuid = web.Lists.Add("Task123", "Tasklist1232", sourceTemplate );
SPList newList = web.Lists[newListGuid];
newList.Description = "Modified Custom Task List";
newList.Update();
Response.Write("Is added succes fully..");
}
protected void Button8_Click(object sender, EventArgs e)
{
//Get all document libraries from abcc site
SPWeb myWeb = new SPSite("
http://madhanpc:8089/myTeam/").OpenWeb();
DropDownList1.DataSource = myWeb.Folders;
DropDownList1.DataBind();
}
protected void Button9_Click(object sender, EventArgs e)
{
SPSite site = new SPSite(@"
http://madhanpc:8089/myteam/");
SPWeb web = site.OpenWeb();
web.AllowUnsafeUpdates = true;
try
{
// Add the document library.
Guid newListID = web.Lists.Add("Doc","Test", SPListTemplateType.DocumentLibrary);
// Set additional properties on the new document library.
SPList newList = web.Lists[newListID];
newList.OnQuickLaunch = true;
newList.EnableVersioning = true;
newList.Update();
}
catch (Exception ex)
{
Label1.Text = ex.Message;
}
}
protected void Button10_Click(object sender, EventArgs e)
{
SPSite site = new SPSite(@"
http://madhanpc:8089/MyTeam/");
SPWeb web = site.OpenWeb();
web.AllowUnsafeUpdates = true;
string path = "";
// here filePath is html file control with runat="server" being used to pick the file browsed by user
string[] fileName = filePath.PostedFile.FileName.Split('\\');
int length = fileName.Length;
// get the name of file from path
string file = fileName[length - 1];
// Get the library object where LibraryName is the name of Document Library.
SPFolder folder = web.GetFolder("Doc");
//
SPFileCollection files = folder.Files;
// Pick up the file in binary stream
Stream fStream = filePath.PostedFile.InputStream;
// Read file in a byte array
byte[] MyData = new byte[fStream.Length];
fStream.Read(MyData, 0, (int)fStream.Length);
fStream.Close();
SPFile fff = files.Add(file, MyData, true);
web.AllowUnsafeUpdates = false;
}
protected void Button11_Click(object sender, EventArgs e)
{
SPSite site = new SPSite(@"
http://madhanpc:8089/MyTeam/");
SPWeb web = site.OpenWeb();
web.AllowUnsafeUpdates = true;
//Get the Document Library and its view
SPList list = web.Lists["Doc"];
SPListItemCollection items = list.Items;
//Now we have to write a code for downloaing information of the document,
//Read all documents and write those files to Local System
foreach (SPListItem item in items)
{
//Write only names
Response.Write(item.Name + "<br>");
}
}