Sunday, August 28, 2011

Insert a Sharepoint list item from web services


The following code is used to insert an item to a list using SharePoint Web Services.

        /// <summary>
        /// Method to insert picture URL to a list
        /// </summary>
        /// <param name="pictureURL">URL of the picture</param>
        /// <param name="currentlLoginID">Current logged in user</param>
        private void InsertItem(string pictureURL,string currentlLoginID)
        {
 
       /*Declare and initialize a variable for the Lists Web service.*/
            spsService.Lists listService = new spsService.Lists();

            /*Authenticate the current user by passing their default
            credentials to the Web service from the system credential cache.*/
            listService.Credentials = System.Net.CredentialCache.DefaultCredentials;
                 
            listService.Url = "http://spsService/sites/MP/_vti_bin/Lists.asmx";

            System.Xml.XmlNode ndListView = listService.GetListAndView("Team Profiles", "");
            string listName = ndListView.ChildNodes[0].Attributes["Name"].Value;
            string viewName = ndListView.ChildNodes[1].Attributes["Name"].Value;


             XmlDocument xmlDoc = new XmlDocument();
         
            /* Declare an XmlNode object and initialize it with the XML response from the GetListItems method.*/
            System.Xml.XmlNode nodeListItems = listService.GetList(listName);

            string sBatch = string.Empty;        
            string uid = "-1;#" + currentlLoginID;

            //Query to insert data
            sBatch = "<Method ID=\"1\" Cmd=\"New\">";
            sBatch += "<Field Name=\"ID\">New</Field>";
            sBatch += "<Field Name=\"User_Picture\">" + pictureURL + "</Field>";
            sBatch += "<Field Name=\"UID\" >" + uid + "</Field>";
            sBatch += "</Method>";

            XmlElement batch_element = xmlDoc.CreateElement("Batch");
            batch_element.SetAttribute("OnError", "Continue");
            batch_element.SetAttribute("ViewName", viewName);

            batch_element.InnerXml = sBatch;
            listService.UpdateListItems(listName, batch_element);
        }

Wednesday, August 17, 2011

List all SharePoint Databases

Before migrating/moving the SharePoint database, we need to find all the database name.

We may need to find move the following database


Databases for Shared Services Providers (SSPs)
Search databases for SSPs
Content databases
Search database
Central Administration content database
Configuration database

To find all the SP database names, Go to Central Administration >> Operations >> Perform a Backup. This will take you to the page with all database listed.

Monday, August 15, 2011

Cannot find ContentPlaceHolder 'PlaceHolderPageTitle' in the master page '~masterurl/default.master', verify content control's ContentPlaceHolderID attribute in the content page

Error: "An unexpected error has occurred" in almost all the list and document library pages in SharePoint site

Cause: Changed the master page from SharePoint designer by right clicking the master page file and selecting "Set as default master page".

Resolution: By updating the callstack=true in web.config file of the web application, we got more detailed error message

Cannot find ContentPlaceHolder 'PlaceHolderPageTitle' in the master page '~masterurl/default.master', verify content control's ContentPlaceHolderID attribute in the content page


Opened the master page in the SharePoint designer and noticed that the PlaceHolderPageTitle is missing.
So replaced the below line
<Title>Our Company Intranet</Title>
with
<Title ID=onetidTitle><asp:ContentPlaceHolder id=PlaceHolderPageTitle runat="server"/></Title>


and save the master page.