Prgramatically add Custom WebPart to SharePoint Views or aspx page
SPSecurity.RunWithElevatedPrivileges(delegate()
{
using (SPSite site = new SPSite("http://RKU:777/"))
{
using (SPWeb web = site.OpenWeb())
{
SPList list = web.Lists.TryGetList("MyDocs");
SPView myview = list.Views["RKUVIewTest"];
using (SPLimitedWebPartManager wpManager = web.GetLimitedWebPartManager(myview.Url, System.Web.UI.WebControls.WebParts.PersonalizationScope.Shared))
{
SPList list1 = web.Lists.TryGetList("Web Part Gallery");
SPListItemCollection Icoll = list1.Items;
foreach (SPListItem item in Icoll)
{
if (item.Title.Contains("SPGridTest"))
{
SPFile page = web.GetFile(myview.Url);
using (SPLimitedWebPartManager manager = page.GetLimitedWebPartManager(PersonalizationScope.Shared))
{
string errMsg = string.Empty;
SPFile myWebPart = web.GetFile(item.Url);
XmlTextReader read = new XmlTextReader(myWebPart.OpenBinaryStream());
var wp = manager.ImportWebPart(read, out errMsg);
manager.AddWebPart(wp, "Top", 1);
manager.SaveChanges(wp);
}
}
}
}
}
}
});
Tuesday, August 12, 2014
Thursday, July 31, 2014
Enable / Disable Div controls based on RadioButtonList Using JavaScript
Enable / Disable Div controls based on Radio buttons
RadioButtonList Using JavaScript
protected void Page_Load(object sender, EventArgs e)
{
radioBtnSelect.Attributes.Add("onClick", "GetRDBValue();");
}
---------------------------------------------------------------------------------------------------------
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head id="Head1" runat="server">
<title>Untitled Page</title>
<script type="text/javascript" language="javascript">
function GetRDBValue() {
// debugger;
var showdiv1 = document.getElementById('Div1');
var showdiv2 = document.getElementById('Div2');
var radio = document.getElementsByName('radioBtnSelect');
// debugger;
if (radio.length > 0) {
if (radio[0].cells[0].children[0].checked ==
true && radio[0].cells[0].innerText == "One1") {
showdiv1.style.display = "none";
showdiv2.style.display = "none";
}
if (radio[0].cells[1].children[0].checked ==
true && radio[0].cells[1].innerText == "Two2") {
showdiv1.style.display = "block";
showdiv2.style.display = "none";
}
if (radio[0].cells[2].children[0].checked ==
true && radio[0].cells[2].innerText == "Three3") {
showdiv1.style.display = "block";
showdiv2.style.display = "block";
}
}
}
</script>
</head>
<body>
<form id="form1" runat="server">
<asp:RadioButtonList ID="radioBtnSelect" runat="server" RepeatDirection="Horizontal">
<asp:ListItem Text="One1" Value="1"></asp:ListItem>
<asp:ListItem Text="Two2" Value="2"></asp:ListItem>
<asp:ListItem Text="Three3" Value="3"></asp:ListItem>
</asp:RadioButtonList>
<div id="checkdiv" style="">
Hi Welcome check Div</div>
<div>
<div id="Div1" style="display: none">
Hi Welcome Div1</div>
<div>
<div id="Div2" style="display: none">
Hi Welcome Div2</div>
<div>
</div>
</form>
</body>
</html>
Thursday, July 24, 2014
Sample JQuery in SharePoint create List Item, add values to DropDown
Sample JQuery in SharePoint create List Item, add values to DropDown
<script src="../../../_layouts/RKUJqu/jquery.min.js" type="text/javascript"></script>
<SharePoint:ScriptLink ID="ScriptLink1" Name="sp.js" LoadAfterUI="true" Localizable="false" runat="server" ></SharePoint:ScriptLink>
<table>
<tr>
<td>
Sample Jquery and ECMA/Javascript
</td>
</tr>
<tr>
<td>
<label for="txtTitle"> Enter Title</label>
</td>
<td>
<br />
<input id="txtTitle" type="text" value="enter some text"/>
</td>
</tr>
<tr>
<td>
<input id="Submit1" type="submit" value="submit" onclick="createListItem()" />
</td>
</tr>
<tr>
<td>
<select id="ddSelect" name="ddSelect">
</select></td>
</tr>
</table>
<script language="javascript">
$(document).ready(function () {
//alert('Hi');
debugger;
ddfill();
});
function ddfill() {
var clientContext = new SP.ClientContext.get_current();
var oList = clientContext.get_web().get_lists().getByTitle('RKUTest');
var camlQuery = new SP.CamlQuery();
camlQuery.set_viewXml('<View><RowLimit>100</RowLimit></View>');
this.collListItem = oList.getItems(camlQuery);
clientContext.load(collListItem);
clientContext.executeQueryAsync(Function.createDelegate(this, this.addDDL), Function.createDelegate(this, this.onQueryFailed));
}
// function SaveListItem() {
// // alert($("#txtTitle").val());
// var clientContext = null;
// var web = null;
// context = new SP.ClientContext.get_current();
// web = context.get_web();
// this.list = web.get_lists().getByTitle('RKUTest');
// this.oListItem
// }
// var siteUrl = 'http://units.mil.intra/sites/DGHR/h/default.aspx';
function createListItem() {
var clientContext = new SP.ClientContext.get_current();
var oList = clientContext.get_web().get_lists().getByTitle('RKUTest');
var itemCreateInfo = new SP.ListItemCreationInformation();
this.oListItem = oList.addItem(itemCreateInfo);
oListItem.set_item('Title', $("#txtTitle").val());
oListItem.update();
clientContext.load(oListItem);
clientContext.executeQueryAsync(Function.createDelegate(this, this.onQuerySucceeded), Function.createDelegate(this, this.onQueryFailed1));
}
function addDDL() { //onQuerySucceeded1
debugger;
//alert('Item created: ' + oListItem.get_title());
var listItemEnumerator = collListItem.getEnumerator();
while (listItemEnumerator.moveNext()) {
var oListItem = listItemEnumerator.get_current();
debugger;
$('#ddSelect').append("<option>" + oListItem.get_item('Title') + "</option>");
// listItemInfo += '\nID: ' + oListItem.get_id() +
// '\nTitle: ' + oListItem.get_item('Title') +
// '\nBody: ' + oListItem.get_item('Body');
}
}
function onQueryFailed1(sender, args) {
alert('Request failed. ' + args.get_message() + '\n' + args.get_stackTrace());
}
function onQuerySucceeded() {
alert('Item created: ' + oListItem.get_title());
}
function onQueryFailed(sender, args) {
alert('Request failed. ' + args.get_message() + '\n' + args.get_stackTrace());
}
</script>
<script src="../../../_layouts/RKUJqu/jquery.min.js" type="text/javascript"></script>
<SharePoint:ScriptLink ID="ScriptLink1" Name="sp.js" LoadAfterUI="true" Localizable="false" runat="server" ></SharePoint:ScriptLink>
<table>
<tr>
<td>
Sample Jquery and ECMA/Javascript
</td>
</tr>
<tr>
<td>
<label for="txtTitle"> Enter Title</label>
</td>
<td>
<br />
<input id="txtTitle" type="text" value="enter some text"/>
</td>
</tr>
<tr>
<td>
<input id="Submit1" type="submit" value="submit" onclick="createListItem()" />
</td>
</tr>
<tr>
<td>
<select id="ddSelect" name="ddSelect">
</select></td>
</tr>
</table>
<script language="javascript">
$(document).ready(function () {
//alert('Hi');
debugger;
ddfill();
});
function ddfill() {
var clientContext = new SP.ClientContext.get_current();
var oList = clientContext.get_web().get_lists().getByTitle('RKUTest');
var camlQuery = new SP.CamlQuery();
camlQuery.set_viewXml('<View><RowLimit>100</RowLimit></View>');
this.collListItem = oList.getItems(camlQuery);
clientContext.load(collListItem);
clientContext.executeQueryAsync(Function.createDelegate(this, this.addDDL), Function.createDelegate(this, this.onQueryFailed));
}
// function SaveListItem() {
// // alert($("#txtTitle").val());
// var clientContext = null;
// var web = null;
// context = new SP.ClientContext.get_current();
// web = context.get_web();
// this.list = web.get_lists().getByTitle('RKUTest');
// this.oListItem
// }
// var siteUrl = 'http://units.mil.intra/sites/DGHR/h/default.aspx';
function createListItem() {
var clientContext = new SP.ClientContext.get_current();
var oList = clientContext.get_web().get_lists().getByTitle('RKUTest');
var itemCreateInfo = new SP.ListItemCreationInformation();
this.oListItem = oList.addItem(itemCreateInfo);
oListItem.set_item('Title', $("#txtTitle").val());
oListItem.update();
clientContext.load(oListItem);
clientContext.executeQueryAsync(Function.createDelegate(this, this.onQuerySucceeded), Function.createDelegate(this, this.onQueryFailed1));
}
function addDDL() { //onQuerySucceeded1
debugger;
//alert('Item created: ' + oListItem.get_title());
var listItemEnumerator = collListItem.getEnumerator();
while (listItemEnumerator.moveNext()) {
var oListItem = listItemEnumerator.get_current();
debugger;
$('#ddSelect').append("<option>" + oListItem.get_item('Title') + "</option>");
// listItemInfo += '\nID: ' + oListItem.get_id() +
// '\nTitle: ' + oListItem.get_item('Title') +
// '\nBody: ' + oListItem.get_item('Body');
}
}
function onQueryFailed1(sender, args) {
alert('Request failed. ' + args.get_message() + '\n' + args.get_stackTrace());
}
function onQuerySucceeded() {
alert('Item created: ' + oListItem.get_title());
}
function onQueryFailed(sender, args) {
alert('Request failed. ' + args.get_message() + '\n' + args.get_stackTrace());
}
</script>
Tuesday, July 22, 2014
SharePoint Form(NEWFORM,DISPLAYFORM,EDITFORM) related to SPListItem programatically
SharePoint Form(NEWFORM,DISPLAYFORM,EDITFORM) related to SPListItem programatically
foreach (SPListItem listItem in itemCol)
{
// int itemID = item.ID;
//SPListItem listItem = SPList.GetItemById(itemID);
// New form full url
string newFormFullUrl = string.Format("{0}{1}?ID={2}", listItem.Web.Url, listItem.ParentList.Forms[PAGETYPE.PAGE_NEWFORM].ServerRelativeUrl, listItem.ID);
// Edit form full url
string editFormFullUrl = string.Format("{0}{1}?ID={2}", listItem.Web.Url, listItem.ParentList.Forms[PAGETYPE.PAGE_EDITFORM].ServerRelativeUrl, listItem.ID);
// Display form full url
string displayFormFullUrl = string.Format("{0}{1}?ID={2}", listItem.Web.Url, listItem.ParentList.Forms[PAGETYPE.PAGE_DISPLAYFORM].ServerRelativeUrl, listItem.ID);
//Relative Url
string newFormRelativeUrl = string.Format("{0}?ID={1}", listItem.ParentList.Forms[PAGETYPE.PAGE_NEWFORM].ServerRelativeUrl, listItem.ID);
}
foreach (SPListItem listItem in itemCol)
{
// int itemID = item.ID;
//SPListItem listItem = SPList.GetItemById(itemID);
// New form full url
string newFormFullUrl = string.Format("{0}{1}?ID={2}", listItem.Web.Url, listItem.ParentList.Forms[PAGETYPE.PAGE_NEWFORM].ServerRelativeUrl, listItem.ID);
// Edit form full url
string editFormFullUrl = string.Format("{0}{1}?ID={2}", listItem.Web.Url, listItem.ParentList.Forms[PAGETYPE.PAGE_EDITFORM].ServerRelativeUrl, listItem.ID);
// Display form full url
string displayFormFullUrl = string.Format("{0}{1}?ID={2}", listItem.Web.Url, listItem.ParentList.Forms[PAGETYPE.PAGE_DISPLAYFORM].ServerRelativeUrl, listItem.ID);
//Relative Url
string newFormRelativeUrl = string.Format("{0}?ID={1}", listItem.ParentList.Forms[PAGETYPE.PAGE_NEWFORM].ServerRelativeUrl, listItem.ID);
}
Wednesday, July 9, 2014
Login form simple html
<html>
<head id="Head1" runat="server">
<title>Login Page </title>
<style>
body
{
color: #000000;
font: 12px/1.4 arial,FreeSans,Helvetica,sans-serif;
margin: 0;
}
#LoginBox
{
margin: 0 auto;
min-width: 200px;
padding: 1em;
width: 470px;
margin-top: 100px;
}
#LoginBox .Form-Content
{
-moz-border-radius: 0.4em 0.4em 0.4em 0.4em;
background-color: #FFFFFF;
border: 1px solid #BBBBBB;
min-height: 50px;
padding: 1em;
position: relative;
}
#LoginBox .Form-Content h2
{
border-bottom: medium none;
color: #333333;
font-size: 1.6em;
margin: 0 0 1em;
}
#LoginBox .LoginTextField
{
-moz-border-radius: 0.3em 0.3em 0.3em 0.3em;
border: 1px solid #DDDDDD;
margin: 0;
padding: 2px;
width: 160px;
}
#LoginBox .LoginButton
{
-moz-border-radius: 0.3em 0.3em 0.3em 0.3em;
line-height: 1.2;
margin: 10px 10px 0 0;
padding: 0 0.5em;
}
</style>
</head>
<body>
<form id="form1" runat="server">
<div style="clear: both;">
</div>
<div id="LoginBox">
<div class="Form-Content">
<h2>
Login</h2>
<table width="100%" cellpadding="0" cellspacing="1">
<tr>
<td style="width: 80px; white-space: nowrap; line-height: 2.4;">
UserID:
</td>
<td>
<asp:textbox id="UserName" cssclass="LoginTextField" runat="server"></asp:textbox>
</td>
</tr>
<tr>
<td style="width: 80px; white-space: nowrap; line-height: 2.4;">
Password:
</td>
<td>
<asp:textbox id="Password" cssclass="LoginTextField" runat="server" textmode="Password"></asp:textbox>
</td>
</tr>
<tr>
<td>
</td>
<td>
<asp:Label ID="lblError" runat="server"></asp:Label>
</td>
</tr>
<tr>
<td>
<asp:button id="Login" runat="server" cssclass="LoginButton" onclick="Login_Click"
text="Submit" />
</td>
<td>
<%--<asp:button id="Button2" runat="server" cssclass="LoginButton" onclick="Button2_Click"
text="HealthVault Sign in" />
<asp:button id="Button3" runat="server" cssclass="LoginButton" onclick="Button3_Click"
text="Register New User" />--%>
</td>
</tr>
</table>
<p>
</p>
</div>
</div>
</form>
</body>
</html>
Thursday, April 24, 2014
Re-using SharePoint controls
Ref:
http://community.zevenseas.com/Blogs/Robin/Lists/Posts/Post.aspx?ID=96
1.SPDatePickerControl:
2.ButtonSection
3.InputFormRequiredFieldValidator
4.InputFormRangeValidator
ToolBar & ToolBarButton
Button:
<%@ Register TagPrefix="wssuc" TagName="ButtonSection"
src="~/_controltemplates/ButtonSection.ascx" %>
<wssuc:ButtonSection runat="server">
<Template_Buttons>
<asp:Button runat="server" class="ms-ButtonHeightWidth"
OnClick="OnClickOK" Text="<%$Resources:wss,multipages_okbutton_text%>"
id="btnOk" accesskey="<%$Resources:wss,okbutton_accesskey%>"/>
</Template_Buttons>
</wssuc:ButtonSection>
When making use of the LayoutsPageBase in your codebehind, you can define the URL of the Cancel button by using this snippet:
public override string PageToRedirectOnCancel
{
get
{
//return base.PageToRedirectOnCancel;
return "/_layouts/settings.aspx";
}
}
<script type="text/javascript"src="/_layouts/datepicker.js"></script><SharePoint:SPDatePickerControl id="datePickerControl"runat="server"/>
Thursday, March 27, 2014
SharePoint Global Navigation
SharePoint Global Navigation
add it before </head><SharePoint:CssRegistration name="<% $SPURL:~sitecollection/Style Library/raviStyle.css %>" After="corev4.css" runat="server"/>
---------------------------------------------------------------------------------------------------------
.s4-lp, body #s4-topheader2{
background-color:#4fb3d3;
margin-left:0px;
border-top:0px;
border-bottom:0px;
margin-left:0px;
}
.menu-horizontal{
margin-left:10px;
border-right: 1px #81C8DF solid;
background-image:none;
}
.menu-horizontal ul li{
color:#fff!important;
min-height:31px;
line-height:30px;
border:0px;
padding:0px;
margin:0px;
border-left:1px #81C8DF solid;
}
.menu-horizontal ul li a{
color:#fff!important;
font-weight:bold;
border:0px!important;
padding:0px!important;
margin:0px;
height:31px!important;
background-color:#4fb3d3;
padding-right:18px!important;
padding-left:18px!important;
}
.s4-toplinks .s4-tn > .menu-horizontal ul li a:hover {
text-decoration:none!important;
color:#000!important;
height:31px!important;
border:0px;
padding:0px;
margin:0px;
}
.s4-toplinks .s4-tn > .menu-horizontal a.selected {
color: #fff!important;
background-color:#4fb3d3; /*Fallback*/
background: -webkit-gradient(linear, left top, left bottom, from(#036ba8), to(#81C8DF));
background: -moz-linear-gradient(top, #036ba8, #81C8DF);
filter: progid:DXImageTransform.Microsoft.gradient(startColorstr=#036ba8, endColorstr=#81C8DF);
-ms-filter: "progid:DXImageTransform.Microsoft.gradient(startColorstr=#036ba8, endColorstr=#81C8DF)";
line-height:30px;
height:31px;
border:0px;
padding:0px;
margin:0px;
}
.menu-horizontal A.dynamic-children SPAN.additional-background {
background-image:none!important;
}
.s4-tn ul.dynamic {
background-image:none!important;
border:1px solid #f7f7f7;
border-top:0px;
border-bottom:1px solid #ccc;
margin:0px;
padding:0px;
}
.s4-tn li.dynamic {
background-image:none!important;
border-top:1px solid #ccc;
border-right:1px solid #ccc;
border-bottom:0px solid #ccc;
border-left:1px solid #ccc;
}
.s4-tn li.dynamic > .menu-item {
display:block;
padding-left:19px!important;
white-space:nowrap;
font-weight:normal;
background-color:#ffffff!important;
background: -webkit-gradient(linear, left top, left bottom, from(#ffffff), to(#f7f7f7))!important;
background: -moz-linear-gradient(top, #ffffff, #f7f7f7)!important;
filter: progid:DXImageTransform.Microsoft.gradient(startColorstr=#ffffff, endColorstr=#f7f7f7)!important;
-ms-filter: "progid:DXImageTransform.Microsoft.gradient(startColorstr=#ffffff, endColorstr=#f7f7f7)"!important;
color:#333!important;
}
.s4-tn li.dynamic > a:hover {
background-color:#fff;
background: -webkit-gradient(linear, left top, left bottom, from(#ffffff), to(#ffffff))!important;
background: -moz-linear-gradient(top, #ffffff, #ffffff)!important;
filter: progid:DXImageTransform.Microsoft.gradient(startColorstr=#ffffff, endColorstr=#ffffff)!important;
-ms-filter: "progid:DXImageTransform.Microsoft.gradient(startColorstr=#ffffff, endColorstr=#ffffff)"!important;
}
/*----- Some other stuff -------*/
.col-fluid-1, .right-wp-zone-col {
margin-top:20px
}
#s4-leftpanel-content {
padding-top:20px!important;
border-right:0px!important;
border-bottom:0px!important;
margin-right:0px;
margin-left:0px;
background-color:#f7f7f7!important
}
.s4-title{
min-height:70px;
padding:0px;
}
.s4-titlelogo{
padding-left:10px
}
TD.ms-sbscopes {
padding-right:0px
}
.s4-search, .s4-rp{
padding-top:3px!important;
margin-right:0px;
}
.s4-search TABLE {
margin-right:0px
}
.s4-title-inner{
background-color:#a0d9e6; /*Fallback*/
background: -webkit-gradient(linear, left top, left bottom, from(#a0d9e6), to(#f7f7f7));
background: -moz-linear-gradient(top, #a0d9e6, #f7f7f7);
filter: progid:DXImageTransform.Microsoft.gradient(startColorstr=#a0d9e6, endColorstr=#f7f7f7);
-ms-filter: "progid:DXImageTransform.Microsoft.gradient(startColorstr=#a0d9e6, endColorstr=#f7f7f7)";
padding:0px 0px 0px 0px;
margin:0px;
min-height:70px;
}
Subscribe to:
Posts (Atom)