Please go through the given link for good solution Sharepoint 2010 Web Part Best Practise
Tuesday, 17 July 2012
Monday, 16 July 2012
Add a Web Part Using Object Model
Add a new webpart page MyPage1.aspx on your site(http://localhost/sites/MyNewSite) in 'Shared Document' document library.
Create a Console application and add following references and code.
Assembly References
• Windows SharePoint Services
• System.Web assembly
• MyNewWebPart assembly
Class Library References
• Microsoft.SharePoint
• Microsoft.SharePoint.WebControls;
• Microsoft.SharePoint.WebPartPages;
• System.Web
• MyNewWebPart
Code -
SPSite site = new SPSite("http://localhost/sites/MyNewSite");
SPWeb web = site.RootWeb;
web.AllowUnsafeUpdates = true;
SPLimitedWebPartManager webParts = web.GetLimitedWebPartManager("Shared Documents/MyPage1.aspx", System.Web.UI.WebControls.WebParts.PersonalizationScope.Shared);
//Create an instance of Custom Webpart and add in a Webpart zone
MyNewWebPart.MyWelcomePart wp = new MyWelcomePart();
wp.Title = "My WebPart Using OM";
webParts.AddWebPart(wp, "Left", 0);
webParts.SaveChanges(wp);
//Create an instance of CEWP and add in a Webpart zone
Microsoft.SharePoint.WebPartPages.ContentEditorWebPart cewp = new Microsoft.SharePoint.WebPartPages.ContentEditorWebPart();
XmlDocument xmlDoc = new XmlDocument();
System.Xml.XmlElement xmlElem = xmlDoc.CreateElement("xmlElem");
xmlElem.InnerText = "Hello From CEWP!";
cewp.Content = xmlElem;
cewp.Title = "My CEWP Using OM";
webParts.AddWebPart(cewp, "Left", 0);
webParts.SaveChanges(cewp);
//Create an instance of Page Viewer Webpart and add in a Webpart zone
Microsoft.SharePoint.WebPartPages.PageViewerWebPart pvwp = new Microsoft.SharePoint.WebPartPages.PageViewerWebPart();
pvwp.SourceType = PathPattern.URL;
pvwp.ContentLink = "http://www.google.com";
pvwp.Title = "My PVWP Using OM";
webParts.AddWebPart(pvwp, "Left", 0);
webParts.SaveChanges(pvwp);
web.Update();
web.Dispose();
site.Dispose();
Very useful code that how can we add custom and/or Default web part from here.
Create a Console application and add following references and code.
Assembly References
• Windows SharePoint Services
• System.Web assembly
• MyNewWebPart assembly
Class Library References
• Microsoft.SharePoint
• Microsoft.SharePoint.WebControls;
• Microsoft.SharePoint.WebPartPages;
• System.Web
• MyNewWebPart
Code -
SPSite site = new SPSite("http://localhost/sites/MyNewSite");
SPWeb web = site.RootWeb;
web.AllowUnsafeUpdates = true;
SPLimitedWebPartManager webParts = web.GetLimitedWebPartManager("Shared Documents/MyPage1.aspx", System.Web.UI.WebControls.WebParts.PersonalizationScope.Shared);
//Create an instance of Custom Webpart and add in a Webpart zone
MyNewWebPart.MyWelcomePart wp = new MyWelcomePart();
wp.Title = "My WebPart Using OM";
webParts.AddWebPart(wp, "Left", 0);
webParts.SaveChanges(wp);
//Create an instance of CEWP and add in a Webpart zone
Microsoft.SharePoint.WebPartPages.ContentEditorWebPart cewp = new Microsoft.SharePoint.WebPartPages.ContentEditorWebPart();
XmlDocument xmlDoc = new XmlDocument();
System.Xml.XmlElement xmlElem = xmlDoc.CreateElement("xmlElem");
xmlElem.InnerText = "Hello From CEWP!";
cewp.Content = xmlElem;
cewp.Title = "My CEWP Using OM";
webParts.AddWebPart(cewp, "Left", 0);
webParts.SaveChanges(cewp);
//Create an instance of Page Viewer Webpart and add in a Webpart zone
Microsoft.SharePoint.WebPartPages.PageViewerWebPart pvwp = new Microsoft.SharePoint.WebPartPages.PageViewerWebPart();
pvwp.SourceType = PathPattern.URL;
pvwp.ContentLink = "http://www.google.com";
pvwp.Title = "My PVWP Using OM";
webParts.AddWebPart(pvwp, "Left", 0);
webParts.SaveChanges(pvwp);
web.Update();
web.Dispose();
site.Dispose();
Very useful code that how can we add custom and/or Default web part from here.
Thursday, 12 July 2012
Quick Poll Web Part SharePoint 2010
After surfing google, I have not found a good Quick Poll Webpart for SharePoint 2010 So I have decided to create it. Here are snaps of my Quick Poll: I have created a Handler (deployed in SiteActions group), to add,view,update and/or delete Poll as follows:
Adjacent image showing how to add questions,choices for quick poll. You can add new field for adding more choices.
Adjacent image showing how to view polls,edit them And/Or delete them.
Adjacent image showing how you can try for poll and how it will look.
Adjacent image showing you the poll result
Adjacent image showing that user can poll only once. Note:- All the required list, pages is created automatically. So just deploy and activate solution and you are ready to test. If any body needs,let me know.
Apologizing for delay response. I am working on this to use it in SharePoint 2013 as well as in SharePoint 2010. Once Done, I will upload wsp file at drop box and share the URL here.
Thursday, 5 July 2012
How To Hide SharePoint People Picker Control from SharePoint List Forms
I found some difficulties in hiding SharePoint People Picker control indexed wise.
Suppose I want to hide only 2nd and 3rd people picker control from SharePoint New and Edit List Form.
here is the solution.
$(document).ready(function() {
var Attendees = GetIDOfPeoplePicker(2);
var Attendee = GetIDOfPeoplePicker(3);
$("#"+Attendees+"").closest('Div').closest('span').closest('td').closest('tr').hide();
$("#"+Attendee+"").closest('Div').closest('span').closest('td').closest('tr').hide();
});
function GetIDOfPeoplePicker(iIndex)
{
var sID = "";
var iFound = 0;
var docTags = document.getElementsByTagName("textarea");
for (var i=0; i < docTags.length; i++)
{
if (docTags[i].title == "People Picker")
{
iFound ++;
if (iFound == iIndex)
{
sID = docTags[i].previousSibling.id;
break;
}
}
}
return sID;
}
Update for SharePoint 2013 Client Picker Control:
To disable the input Filed of Client Picker
$("input.sp-peoplepicker-editorInput[id*='<ID part of ClientPicker Contrl>']").prop('disabled', true);
To hide the input Filed of Client Picker
$("a[id*='<ID part of ClientPicker Contrl>']").hide();
Wednesday, 4 July 2012
Difference between Ghostable and GhostableInLibrary in SharePoint
The decision between Ghostable and GhostableInLibrary really is based on the type of file that you are deploying and whether you want users to view and access the document view a list or a library. If you desire users to view the file within a library then you would select the InLibrary option. Both Ghostable /GhostableInLibrary implies that the file will be cached in memory. GhostableInLibrary however specifies that the file be cached as part of a list whose base type is Document Library and that you can work with the file as you would with any other file in the library (check-in, check-out, version history).
Subscribe to:
Posts
(
Atom
)





