Friday, October 28, 2011

Web Service to Add Items in List


Step -1 : Add Web Reference "http://[WebSiteName from sharepoint server IIS]/_vti_bin/lists.asmx"  into your application by  name "SharepointListWebService"

Step -2 : Add code

SharepointListWebService.Lists AddAlerts = new SharepointListWebService.Lists();
        AddAlerts.Credentials = System.Net.CredentialCache.DefaultCredentials;
        //AddAlerts.Credentials = new System.Net.NetworkCredential("UserName", "passsword");
        //AddAlerts.Url = "http://[WebSiteName from IIS]/_vti_bin/lists.asmx";
        XmlNode node = AddAlerts.GetListAndView("ListName", "");
        string sListID = node.ChildNodes[0].Attributes["Name"].Value;
        string sViewID = node.ChildNodes[1].Attributes["Name"].Value;
        XmlDocument doc = new XmlDocument();
        XmlElement batch = doc.CreateElement("Batch");
        batch.SetAttribute("OnError", "Continue");
        batch.SetAttribute("ListVersion", "1");
        batch.SetAttribute("ViewName", sViewID);
        string item = "<Method ID=\"1\" Cmd=\"New\">" +
                            "<Field Name=\"ID\">New</Field>" +
                            "<Field Name=\"Title\">This is a test from other application</Field>" +
                            "</Method>";
        //    batch.InnerXml = "< Method ID='1' Cmd='New'>" +
        //"<Field Name='ID'>New</Field>" +
        //"<Field Name='Title'>Time</Field>" +
        //"</Method>";
        batch.InnerXml = item;
        AddAlerts.UpdateListItems(sListID, batch);

Step -3 :Enjoy....

Monday, October 24, 2011

Script to Hide Item Action Menu on Allitem.aspx


//Script to Change/Hide the Item action
//Add it just before </asp:Content>



<script type="text/javascript">

_spBodyOnLoadFunctionNames.push("resetAddSendSubMenu()");
function resetAddSendSubMenu(){

//Sent to
AddSendSubMenu = function (m,ctx) {};

//Check In
AddCheckinCheckoutMenuItem = function(m, ctx, currentItemEscapedFileUrl){};

//AddManagePermsMenuItem = function (m, ctx, ctx.listName, currentItemID){};

//Manage Permission
AddManagePermsMenuItem = function(m, ctx, listId, url) {} ;

//View/Edit
AddDocLibMenuItems = function (m,ctx){};


//var AddDocument = document.getElementById("idHomePageNewDocument");
//AddDocument.style.display = "none";


var ttnA = document.getElementsByTagName('A');
for (var j=0; j<ttnA.length; j++)
{
//alert(ttnA[j].id)
  if (ttnA[j].id == 'idHomePageNewDocument')
  {
  //alert(j);
    ttnA[j].style.display="none";//innerHTML='your new text goes here';
    ttnA[j].previousSibling.previousSibling.style.display='none';


  }
}



}
</script>