Posts

Showing posts with the label SharePoint2010

SharePoint 2010: Error - Restore-SPSite : No content databases are available for this operation....

Image
While restoring Sites using power shell, once can come across such a kind of error as given below: "Restore-SPSite : No content databases are available for this operation but the site collection is scheduled for deletion in at least one content database.  Either wait for the deletion operation to complete or create a content database, and then try the operation again. To create a content database, click "Content databases" on the Application Management page, select the Web application to use, and then click "Add a content database". That actually means that a site is already  exist with this content database. To resolve this issue. Use the command 'Get-SPDeletedSite' to see all the marked sites that are scheduled for deletion. Delete the site collection that you think is hosting the above backed up content databa using Remove-SPDeletedSite  command. From Get-SPDeletedSite you get the SiteID which will be used in Remove-SPDeletedSite.  Ch...

SharePoint 2010: Creating Term store, term groups, terms programatically using CSV

With SharePoint 2010 Metadata Managment Services, come few frequently used terminologies such as Termstore, Termgroup, Termset and Terms which normally you create them all in this manner. Now without going into the detail of this jargon (because a lot has been written already) and touching the implementational aspect of it, the easiest way of creating a term store consitituing of respective terms, is by importing a CSV file.  Wictor Wilen  gives a very interesting account of how to create a CSV that can easily be imported to the Metadata management service. Not only that but he also hosts a Macros Enabled Excel Sheet which generates the right CSV upon entering the right data. Technically in SharePoint, whatever is doable using out of the box SharePoint features, can be achieved programatically using custom solution. Following this principlem  what I'm trying to achieve is to do the same thing programatically that we do out of the box i,e Creating a TermStore and a ...

SharePoint 2010: Programmatically wokring with Calculated, Lookup and Hyperlink fields

While working on event receivers in SharePoint 2010, I was required to access thelook up fields and calculated fields in from a list. So here is how I accessed the value of both the fields. SPFieldLookupValue fieldValue = new SPFieldLookupValue(properties.ListItem["ProjectsList"].ToString()); SPFieldCalculated cf = (SPFieldCalculated)properties.ListItem.Fields.GetField("Auslastung"); properties.ListItem["EventHeading"] = fieldValue.LookupValue + ":" + cf.GetFieldValueAsText(properties.ListItem["Auslastung"]); Where as in case you intent to set value for Hyperlink type field it has it own class that can be used in the following manner. SPFieldUrlValue teamURL = new SPFieldUrlValue(); teamURL.Description = "View Team Calendar"; teamURL.Url = properties.Web.Url.ToString() + "\\" + item.Url + "?groupID=" + groupID.ToString(); ; properties.ListItem["ViewTeamCalender"] = teamURL; As you could se...

SharePoint 2010: Resetting Broken List Forms

Well that does not seem like a big deal. But rece ntly I did run in to a situation where I lost my list forms in an attempt to rearrange th e items on the form. So I finally sorted this out and I was able to achieve th is without needing SP Designer. Here are the steps I took: Navigate to the list under consideration. Move to List ribbon and click List Settings. Under General Settings, click Form Settings link. Select the Use the default SharePoint Form option. Here I also opted to delete the custom form by checking "Delete the InfoPath Form from the server" option. C h eers

SharePoint 2010: Setting Item Level Permission on a List Folder

Image
Scenario: Sometime we run into a situation where we got to set a item level permission on a particular folder in a list. Possible reason to that can be hiding data from other users, if the folder is owned by a specific user and contain some private information.  About the Code: In the following, I had a similar, aforementioned, requirement with a slight punch of a management group that was suppose to view everything and then I had normal users, among whom, the owner of the folder was suppose to have rights to viewing and contributing. Thus I had to set permissions for the users who owned the folder and then for the management group. BTW originally it was a sand-boxed solution.  private void setPermissions(SPFolder folder) { SPGroupCollection spc = web.SiteGroups; //Break the role inheritance in order to assign individual rights on folders if (!folder.Item.HasUniqueRoleAssignments) { folder.Item.BreakRoleInheritance(true); }...

SharePoint 2010: Retaining the values of Dynamically created Textboxes in a Sandboxed Visual WebPart

Image
If you instantiating your controls such as texboxes, on the runtime in a web part, chances are high that you would lose the values once a postback occurs. To retain the values in the text boxes, we ought to recreate them on every postback and get the values from the Form collection. In addition to the that the use of the ViewState variable is also helpful. So here goes my code: So suppose you have two buttons CreateTextbox Button: Create a new textbox for you  Save button: Searches for the text boxes and saves the value in the text boxes if any. private void Page_Load(object sender, System.EventArgs e) { if(Page.IsPostBack) ViewState["NumberOfTextboxes"] = 0; else this.createControls(); } private void createTextboxes() { for(int i = 0; i < count; i++) { TextBox tbx = new TextBox(); tbx.ID = "tbx" + i.ToString(); Page.Controls....

SharePoint2010: How to Manage Large Lists

General Guideline Although a  list or library  in SharePoint can have 5M items but when it grows larger than 2000 items, the performance of the list retrieval  deteriorates . Therefore one must  carefully plan a list which can possibly grow to this level. I f a list is well-managed    then it does not matter whether it contains thousands or even millions of items. As a general guideline, any list should not have more than 2,000 items per  list container i.e.  root of the list, or any folder inside it. So for example, if you have a list with 1,900 list items in the list root, plus 100 folders each containing 2,000 items, then still this would be an ideal situation. Similarly we also need to make  sure that our views do not show or edit more than 2,000 items at a time. Practical Scenarios: Recently  I had to develop a SharePoint website for maintaining the number of hours invested by company's employees on various projects. Sinc...

SharePoint 2010: Can SharePoint 2010 work as a CRM? The Complete Roadmap

Image
Can SharePoint 2010 work as a CRM? If you have already worked with MS Dynamics CRM, you would definitely know that this system has came a long way and grown into a a gigantic, robust and a mature application. As a SharePoint developer, I see SP2010 with comprising of all the  ingredients  with which one can  develope a CRM. So It is  possible. But having said that, i f you want a complete replica of MS CRM built on the top of SharePoint platform, you should ascertain amount of time you want to invest since it is a huge task and implementing such an application would take years.  Rather I would focus of the individual modules or  feature that we could actually implement.  Since implementing a selected module will definitely be feasible is couple of months' time.   Secondly, it totally depends on how robust of a CRM you want and also how much effort you want to put into making it happen in SP2010. In fact, I already came across two CRM prod...

SharePoint 2010: Fetching Current Username Programmatically

In order to get the current login user of the selected SharePoint website we can use the following code snippet. public string getUserName() { return SPContext.Current.Web.CurrentUser.Name; } Hope this helps Cheers

SharePoint2010: Inserting/Updating a Lookup Field in a SP List

Image
Problem  For values in a particular column in a SharePoint list, suppose list "A" , we can also refer to column in another list, suppose list B, simply by defining a column in list A as a lookup column of list B. As I assume you know how to do that. the further is step is to update or insert values into this lookup column programatically using SP's server object model.   Prerequisite The value in a look up field is made of the ID of the lookup filed concatenation with ;# and Name of the lookup field (that actually shows up in the). For example if we are refering to a list named Annoucement, in another list Projects then we to add a task programmatically, we concatinate, ID of the item in the Annoucement list + ;# + Title of the Annoucement (The column selected while creating the lookup column as shown in the figure). So we can have: 1;#Project Analysis being carried out Solution To do that we simply need to know the ID of the item in the l...

ASP.Net: How to Find Which Control Caused Postback?

At times in a webpage, we can have many controls that can possibly "Post-back". It can be a PITA to find which control actually posted back if the actual controls are dynamically created. So to find exactly which control posted back, a code snippet is given below which should be added to the page_load method of webpage: protected void Page_Load(object sender, EventArgs e) { if (Page.IsPostBack) { //Creates the dynamic button. the methods is given below addSaveButton(); string ctrlname = Page.Request.Params.Get("__EVENTTARGET"); Control control = null; control = Page.FindControl(ctrlname); if (control == saveButton) //Do whatever you what to do! } } void addSaveButton() { saveButton = new Button(); saveButton.Text = "Save"; saveButton.ID = "sb_1"; saveButton.UseSubmitBehavior = false; saveButton.Command += new CommandEventHandler(saveButton_Click); saveButton.CommandName = "saveButton"; } So that was a piece ...

SharePoint 2010: Accessing a Creating\Accessing a specific folder in Document Library

Here is the piece of code that I wrote to access a folder inside another folder. Although it could be  generalized to n folder by making it recursively call itself but for this specific project it was required to have only 2 folder i.e. we have only two levels of hierarchy. So I wrote a very simple code. Anyways the description can be found in the comments of the code. protected void Page_Load(object sender, EventArgs e) public static SPFolder CreateFolder(SPWeb web, string listName, string folderName) web.AllowUnsafeUpdates = true; SPList targetList = web.Lists[listName]; if (string.IsNullOrEmpty(folderName)) return targetList.RootFolder; SPFolder folder = targetList.ParentWeb.GetFolder(web.Url + "/" + targetList.RootFolder.Url + "/" + folderName); /Checking whether the first level folder exist. if (!folder.Exists) { if (!targetList.EnableFolderCreation) { targetList.EnableFolderCreation = true; targetList.Update(); // Since we could not find the folder so ...

Sharepoint 2010: Deleting all items in SPListItemCollection

SPListItemCollection objlstCollection = list.GetItems(qry); for (int i = 0; i < objlstCollection.Count; i++) { listCollection.Delete(i); } Above is the code that I initially wrote to delete the items in the list item collection and that was actually a very silly code. Since once I delete first item in the list the count of the list collection decreased.  So to resolve this problem I wrote the following code.   SPListItemCollection listCollection = list.GetItems(spQuery); int countItem = listCollection.Count; for (int i = 0; i <  countItem ; i++) { listCollection.Delete(0); } Reference http://martinlangrock.blogspot.com/2012/05/delete-items-from-splistitemcollection.html

SharePoint2010: Setting DateTime as Parameter to CAML Query

Well in case of CAML, normal datetime format doesnot work. For that reason we need to convert the input format as given below: public static String ToSPDate(String strDt)         {             if (strDt == String.Empty)                 return strDt;             else                 return (Convert.ToDateTime(strDt)).ToString("yyyy-MM-dd");         }         /* -- Format for DateTime Field -- */         public static String ToSPDateTime(String strDt)         {             if (strDt == String.Empty)                 return strDt;             else                 return (Convert.ToDateTime(strDt)).To...

SharePoint 2010: Error occured in deployment step 'retract solution' cannot start service SPUserCodeV4 on this computer

Image
Sometime while trying to deploy a sandboxed solution from VS 2010, we bump into the following error " Error occurred in deployment step 'Retract Solution': Cannot start service SPUserCodeV4 on computer...  In such as case you got to activate the "Microsoft SharePoint Foundation Sandboxed Code Service". To do that, we take the following steps: Move to Central Administration Select "System Settings Further navigate to "Manage services on server" Select the service “Microsoft SharePoint Foundation Sandboxed Code Service” Start the service  “Microsoft SharePoint Foundation User Code Service” If the problem persists, also try restarting the Service 'Windows Sharepoint Service user code Host v4' in the Computer Management -> Services tab. Hope this helps Cheers

SharePoint 2010:Farm's Forgotten Passphrase Recovery and Accessing lost Farm

Image
Well one fine morning, for some really weird reason, I changed the password of my database server from SQL Configuration Manager and thereafter I lost connection with my current SP 2010 Farm whose passphrase was something I never knew.  After  ransacking blogs and googling for around 5 hours, I came across a very awesome way to regain control of the lost farm without even knowing the passphrase ;). Well I won't make tall claims but I did get my web application back. I did not give it any further try but its going to serve as a food for thought and last  hope of success for someone in trouble.  Let me first say few words about Sharepoint_config. it is simply a configuration database that handles all administration stuff such as deployment, directing requests to the appropriate database, and managing load-balancing for the back-end databases. When a front-end Web server receives a request for a page in a particular site, it checks the configuration database to...

SharePoint 2010: Inline Editing of list items in SharePoint 2010

Image
Inline editing of List item comes very handy as we like to edit the item without opening that item in window. Just like ASP.NET grid that provides the way of editing and then updating by clicking edit button and then updating the record. We can do that same thing in SharePoint 2010 and it is easy to do that. First move to the view settings of the desired list and then enable the in line editing option. Check the in line editing option and save the settings. Now move back to list and hover the mouse cursor on the list item and you will notice an “edit” icon against each list item and upon pressing this button one can edit the list item then and there. 

SharePoint 2010 Migration Woes: Importing and exporting lists template between different SP2010 Servers

Image
Migrations of SharePoint contents from one server to another can be a big PITA. Once I came across a  scenario  where I had to export a couple of lists from SharePoint online i.e. Office 365 to the SharePoint 2010 on my local server.  What I did is to copy the required lists along with content by creating a list template i.e. via .stp file. Then I upload it to my local SharePoint 2010 server's list template gallery. Later I  successfully  created a new list with the uploaded template. For that I took the following steps: Open your SharePoint site in the SharePoint designer 2010. Select Lists and libraries. Select you desire list and the click on the "Save as Template" from the ribbon. You'll be redirected to the SharePoint site and there after filling in the required fields and pressing OK , .stp will be created. This template can be viewed in Site Action -> Site Setting -> Galleries ->List Template. Select the list template and then from ...

SharePoint2010: Working With Calculated Field/Column in SharePoint 2010 Lists

Image
Although each SP lists has a unique naming convention for each list item. It is called GUID i.e.  Globally Unique ID. We can address any item using this id but there are certain scenarios where one needs an auto generating column i.e. a number field that automatically increments after each new item. for instance someone may need a custom ID that constitutes of different pieces of information based on different other columns in the same list. To do that there are certain approach as given below: First approach is to reuse the every list's default "ID" column that is incremental and keeps track of the records. One can simply use this column. Second approach is to use a column of type "calculated" and then write a formula as illustrated in the image. For further aid, refer to MSDN  http://msdn.microsoft.com/en-us/library/bb862071.aspx  :  Jim Adcock has given a ver good example on his blog: http://dlairman.wordpress.com/2011/01/10/add-a-unique-auto-incr...

SharePoint 2010: Microsoft online Portal does not open in IE

The other day working on a new machine I come across a problem that I could not access  ( https://portal.microsoftonline.com/ ) i.e upon entering the site URL in IE I got a blank page. To sort out this problem, I tried the following steps. For adding Microsoft Online Portal   ( https://portal.microsoftonline.com/ ) into trust list Trusted Sites of IE, first navigate to Tools -> Internet Options.    Click the “Security” Tab. Click “Trusted Sites”. Click “Sites” Click “Add" After that again move to the Security tab, and click Internet. Click Custom Level. Scroll down to Active scripting. Click Enable or even Prompt Click OK. Click Yes.and voila....you are done