Thursday, October 20, 2011

Site definitions vs. Web templates and List def vsList Template

SharePoint 2010: What is Sandbox Solution?

Many of the SharePoint are working on the SharePoint for a long time. Many of then also started working in the SharePoint 2010. Their are many things that SharePoint 2010 made easier then from SharePoint 2007/Moss. Many improvements are given to the SharePoint to that it can build a better solution.

If you have been reading about exciting new features of SharePoint 2010 you probably heard about something called SandBox Solutions. What is the Sandbox solution?

SharePoint is a rich development platform with a large community actively developing solutions. The challenge, however, has always been the balance between creating solutions and deploying them in a way that you can trust will not damage or impair the SharePoint farm. Sandboxed solutions, new in SharePoint 2010, address this by allowing site collection administrators to deploy solutions that are safe to run. Sandboxed solutions are restricted to running under a subset of the SharePoint API and the framework can monitor these solutions and shut down any that risk the stability of the farm.

SandBox Solutions support the following SharePoint item types:

* List definitions
* List instances
* Content Types/Fields
* Navigation
* Web Parts derived from WebPart
* Event receivers
* Custom Workflow Actions
* Workflows

Development

For developing a sandbox solution you have to just create a new blank SharePoint Solution in Visual Studio 2010. Go to properties of the solution and change the solution type to true.

The structure of a sandboxed solution is very similar to a farm solution, which generally runs with full-trust permissions. The main differences lie in how a sandboxed solution is deployed and in the process that hosts the solution (which determines whether a solution is a sandboxed solution or a farm solution). This means that the same sandboxed solution can run with full trust when it’s deployed at the farm level and with partial trust when it’s deployed at the site collection level







SharePoint 2010 : Creating a Web/Site template

What Are Web Templates in general?


We can a web site template is a pre-designed web page or simply a web page without or with basic contents. Right?


What is web template in the SharePoint term?

Web templates on the other hand, are stored in the database, and are created using an existing site, with or without its specific content, as a model. This provides a means for reusing sites that you have customized.


In SharePoint 2007/2010 the meaning is same for both the version. But creating a web template is now different in the both version, means approach is different.
Like in MOSS we can create the web template using the existing site, SPD 2007 for UI and WSP for deployment. But in the SharePoint now you can create your Custom Web template using the SharePoint existing site. Well, for the custom template first you have to design and implement all the requirement on the existing site, and save the template in the Site templates. But here is the slightly change, we can create two types of the site template solution,

Farm

Sandbox

In VS 2010 their is a new template for the creating the solution from existing WSP is Import SharePoint Solution Package.





Now you can import your WSP in this solution and you can write your custom code or now you can modify UI etc. It will give great help when you are creating a sandbox solution and does not want to write a code. then just deploy all the solution on existing site and use that site WSP to import in this solution. Extract your required solution from it and implement in the your solution.

Web Templates



SharePoint 2010 and web templates



Site definitions vs. Web templates




webtemplate-training-materials




List def
http://johanolivier.blogspot.com/2010/05/developing-list-definition-in.html
http://johanolivier.blogspot.com/2010/08/sharepoint-2010-provider-consumer-web.html



Save as Site Template {Publishing Sites}
http://www.shareesblog.com/?cat=12
# Go to Site Actions, Site Settings
# In the Look and Feel section, click Save Site as Template. Note: if your site has the Publishing feature turned on or is

based on a Publishing site template the Save Site as Template link does not appear. Read the Microsoft Knowledge Base article

on how to save Publishing sites (or sites with Publishing turned on)Â as templates. There is a link available in a publishing

site so you have to navigate to url/_layouts/savetmpl.aspx to save as template in a publishing site.
**************

SharePoint 2010 and web templates



Site definitions vs. Web templates


#######################################################

Create Custom List Sharepoint 2010 Code

using System;
using System.ComponentModel;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using Microsoft.SharePoint;
using Microsoft.SharePoint.WebControls;
using System.Data;
using System.Data.SqlClient;

namespace SharePointProject4.CustomWebpart
{
[ToolboxItemAttribute(false)]
public class CustomWebpart : WebPart
{
protected override void CreateChildControls()
{

SqlConnection cn = new SqlConnection("Data Source =ex;Failover Partner=tracedb; Initial Catalog

=_MSCRM_CUSTOM;User Id=admin;password=password#");
DataSet ds = new DataSet();
string str = "select opportunityid,SPUrl from dbo.opportunity_spurl";
SqlDataAdapter da = new SqlDataAdapter(str ,cn );
da.Fill(ds);

using (SPSite oSPsite = new SPSite("http://dev:90"))
{
oSPsite.AllowUnsafeUpdates = true;

using (SPWeb oSPWeb = oSPsite.OpenWeb())

oSPWeb.AllowUnsafeUpdates = true;

// /* 1. create list from custom ListTemplate present within ListTemplateGalery */
// SPListTemplateCollection lstTemp = oSPsite.GetCustomListTemplates(oSPWeb);
// SPListTemplate template = lstTemp["custom template name"];
// oSPWeb.Lists.Add("List Name", "Description", template);


// /* 2. create list from sharepoint list content type (e.g. Links) */
// oSPWeb.Lists.Add("List Name", "Description", SPListTemplateType.GanttTasks);

// oSPWeb.AllowUnsafeUpdates = false;
// }

// oSPsite.AllowUnsafeUpdates = false;


// SPSite site = new SPSite("http://dev:90");

// SPWeb web = site.OpenWeb();

// web.AllowUnsafeUpdates = true;

// SPListCollection coll = web.Lists;

// SPListTemplateCollection tmplcoll = web.ListTemplates;


// SPFieldCollection fieldcoll;

// SPListTemplate temp = tmplcoll[0];

//Guid gd = coll.Add("CRMCustomList", "My Sharepoint List", temp);
//coll[gd].Fields.Add("SPUrl", SPFieldType.Text, false);

// //coll[gd].Fields.Add("Test2", SPFieldType.Text, false);
//coll[gd].Fields.Add("OpportunityId", SPFieldType.Number, false);

// coll[gd].Update();

// string defaultquery = coll[gd].Views[0].Query;

// SPViewCollection viewcoll = coll[gd].Views;

// Guid anothergd = coll[gd].Views[0].ID;

// viewcoll.Delete(anothergd);

// System.Collections.Specialized.StringCollection viewfields = new System.Collections.Specialized.StringCollection();

// viewfields.Add("Title");

// viewfields.Add("SPUrl");

// viewfields.Add("OpportunityId");

// coll[gd].Views.Add("All Items", viewfields, defaultquery, 100, true, true);

// coll[gd].Update();


// SPSite site = SPContext.Current.Site;
//site.AllowUnsafeUpdates = true;
//SPWeb web = site.RootWeb;
//web.AllowUnsafeUpdates = true;

//SPListCollection coll = web.Lists;
//SPListTemplateCollection temlcoll = web.ListTemplates;
//SPDocTemplateCollection docTemp = web.DocTemplates;
//SPFieldCollection fieldcoll = web.Fields;

//SPListTemplate temp = temlcoll[0];
////

////SPListTemplateType.CustomGrid is a list template that works like table in ASP.NET or Excel sheet.
//Guid gd = coll.Add("User_Data", "A custom list to store user data", SPListTemplateType.CustomGrid);
//coll[gd].Fields.Add("UserId", SPFieldType.Text, true);
//coll[gd].Fields.Add("Designation", SPFieldType.Text, true);

////a custom field type if you have one
//SPField objAge = coll[gd].Fields.CreateNewField("AgeTextBox1", "User Age1");

//coll[gd].Fields.Add(objAge);

////update the custom list with all those newly created fields
//coll[gd].Update();

//// //create the view for display in the site - both sides must match

//string defaultquery = coll[gd].Views[0].Query;
//SPViewCollection viewcoll = coll[gd].Views;
//Guid anothergd = coll[gd].Views[0].ID;
//viewcoll.Delete(anothergd);

//System.Collections.Specialized.StringCollection viewfields = new System.Collections.Specialized.StringCollection();

////Title field is always needed by SharePoint sites and it is always automatically created by WSS/MOSS even though you

didn't tell it to
//viewfields.Add("Title");
//viewfields.Add("UserId");
//viewfields.Add("Designation");


//coll[gd].Views.Add("View name", viewfields, defaultquery, 100, true, true);
//coll[gd].Update();



//// SPSite site = SPContext.Current.Site;
//// SPWeb web = site.OpenWeb();
//// web.AllowUnsafeUpdates = true; //get the list of list templates from the web
////SPListTemplateCollection customListTemplates = site.GetCustomListTemplates(web); //create the connection library using

the uploaded list template
//// SPListTemplate listTemplate = customListTemplates["listtemplatename"];
//// web.Lists.Add("User_Data", "A custom list to store user data", listTemplate);//A custom list to store user data
//// web.Update();

//SPSite site = SPContext.Current.Site;
//SPWeb web = site.RootWeb;
//web.AllowUnsafeUpdates = true;
//Guid listId = web.Lists.Add("Test Custom List", "The new custom list", SPListTemplateType.GenericList);
//SPList list = web.Lists[listId];
//web.AllowUnsafeUpdates = false;
//site.Dispose();
//web.Dispose();

// using(SPSite mySite = new SPSite(SPContext.Current.Site.Url))

// {

// using(SPWeb spWeb = mySite.OpenWeb())

// {

// SPListTemplateCollection listTemplates = mySite.GetCustomListTemplates(spWeb);



// SPListTemplate listTemplate = listTemplates["GeneralContact"];



//spWeb.Lists.Add("NewContact", "New Contact", listTemplate);




// }

// }





SPSite site = new SPSite("http://dev:90/");

SPWeb web = site.OpenWeb();

web.AllowUnsafeUpdates = true;

SPListCollection coll = web.Lists;

SPListTemplateCollection tmplcoll = web.ListTemplates;



SPFieldCollection fieldcoll;

SPListTemplate temp = tmplcoll[0];

Guid gd = coll.Add("Custom121", "CustomCRM", temp);

coll[gd].Fields.Add("SPUrl", SPFieldType.Text, false);

coll[gd].Fields.Add("OpportunityId", SPFieldType.Text, false);


coll[gd].Update();


coll[gd].Items.Add();


string defaultquery = coll[gd].Views[0].Query;

SPViewCollection viewcoll = coll[gd].Views;

Guid anothergd = coll[gd].Views[0].ID;

viewcoll.Delete(anothergd);



System.Collections.Specialized.StringCollection viewfields = new System.Collections.Specialized.StringCollection();

viewfields.Add("Title");

viewfields.Add("SPUrl");

viewfields.Add("OpportunityId");



coll[gd].Views.Add("All Items", viewfields, defaultquery, 100, true, true);

coll[gd].Update();
//coll[gd].Items[0]["SPUrl"] = "aa";
//coll[gd].Items[0].Update();
//list.items[0]["MyField"] = "text";
//list.items[0].Update();

//SPList List = web.Lists["Custom"];
//string s = ds.Tables[0].Rows[0][1].ToString();
//List.Items.Add(ds.Tables[0].Rows[0][0].ToString());
}
}
}


Sharepoint: Adding choice fields programmatically


As I know I will forget this, and I couldn't find any decent examples on the web to do this, the code below shows how to add

a choice field programmatically to a sharepoint list (with populated choices). Note that the class will need to reference the

Microsoft.Sharepoint namespace.

SPWeb web = new SPSite("http://localhost/sites/demosite").OpenWeb();
web.Lists.Add("Test List", "Test list description", SPListTemplateType.GenericList);


web.Lists["Test List"].Fields.Add("ExampleChoiceField", SPFieldType.Choice, false);


SPFieldMultiChoice choice = (SPFieldMultiChoice)web.Lists["Test List"].Fields["ExampleChoiceField"];
choice.Choices.Add("hello");
choice.Choices.Add("world");
choice.Update();
*************************
Building a SharePoint custom site definition with a project tasks list and a listviewwebpart in Gantt view on the homepage.


Webtemplate1


WebTemplateID issues –.WebTemplateID doesn’t report what you’d think

http://www.sp2010blog.com/Blog/Lists/Posts/Post.aspx?ID=49

Hide View All Site Content from Site Actions Menu SharePoint 2010
http://www.sp2010blog.com/Blog/Lists/Posts/Post.aspx?ID=40

SharePoint 2010 Site Template IDs

http://www.sp2010blog.com/Blog/Lists/Posts/Post.aspx?ID=48

Twitter Web Part - Works with Authentication :)

http://www.sp2010blog.com/Blog/Lists/Posts/Post.aspx?ID=22

No comments:

Blog Archive