Restore SharePoint 2010 Farm to another Farm and then Access Denied

Backup and restore the SharePoint 2010 Farm more times to find a problem,if exchanged the service account when restored the SharePoint Farm, and the restored is success,enter the site will be directly Access Denied.
Log throw the related feature exception of Publishing, and find the Super User Account and Super Reader Account of Publishing feature are not updated, they are the original.
Run below command to update you will resolve this problem:
stsadm -o setproperty -pn portalsuperuseraccount –pv <New Service Account> –url <Web Application URL>
stsadm -o setproperty -pn portalsuperreaderaccount -pv <New Service Account> -url <Web Application URL>
iisreset



Javascript front-end to determine whether one user is the memeber of a permission group in SharePoint

last articl:Javascript front-end to start the SharePoint workflow ,Connected to a use SPservice some practice. When you need to do some low-level rights management, such as to determine whether the current user belongs to a permission group (Group) decided to display the UI. The following is the judgment function code:

function IsMemberOfGroup(strGroupName)
{
    var rt=0;
    var g_strCurrUser = "";
    $().SPServices({
            operation: "GetUserProfileByName",
            AccountName: $().SPServices.SPGetCurrentUser(),
            async: false,
            completefunc: function(xData, Status) {
        
            g_strCurrUser= $(xData.responseXML).find("Name:contains('PreferredName')").first().parent().find("Value").text();
        //alert(g_strCurrUser);
        $().SPServices({
                    operation: "GetUserCollectionFromGroup",
                    groupName: strGroupName,
                    async: false,
                    completefunc: function(xml, Status) {
                    
                            if($(xml.responseXML).find("User[Name='" + g_strCurrUser + "']").length > 0) 
                            {
                            //alert($().SPServices.SPGetCurrentUser({fieldName: "UserName"}));      
                            rt = 1;
                            }
                      
                    }
                }); /*close().SPServices({ */
            }
    }); /*close().SPServices({ */
      
    return rt;
}

First called by Jquery SharePoint webservice GetUserProfileByName "to get the user name and pass another one the webservice GetUserCollectionFromGroup" to determine whether the group members

Related Posts



Javascript front-end to start the SharePoint workflow

Within the enterprise, SharePoint requirement are immediate and small-scale, require fast realization. The front of the technology a lot of time to meet user needs, while avoiding the deployment of back-end development of the IIS restart, reducing the time of deliver. In many applications, I would like to do front-end using SPservice. SPservice based on JQuery javascript library to access the SharePoint the webservice CodePlex there is a lot of introduction. For example, to click a button to start a list of workflow code as follows:

<script type="text/javascript" language="javascript" src="http://server/JQuery/jquery-1.4.4.min.js"></script>
   <script type="text/javascript" src="http://server/jquery/jquery.SPServices-0.5.8.min.js"></script>

 

var g_workflow_templateid = "{d7b03357-1ad6-40b7-8d08-0c10d2935766}";
 
$().SPServices({
    operation: "StartWorkflow",
    async: true,
    item: "http://{ServerName}/sites/{SiteName}/Lists/{ListName}/" + itemID + "_.000" ,
    templateId: g_workflow_templateid ,
    workflowParameters:"<Data/>",
    completefunc: function(xData, Status) {
       //prompt("test",xData.responseXML.xml);
              
        alert("workflow has been started.");
                              
    }
});

The need to pay attention to the parameter is templateId: g_workflow_templateid,templateId will change every time when you pass the SharePoint designer to modify the workflow. It can find the configuration files from you through the URL of the page to manually start the workflow in the list settings, view the workflow through the SharePoint designer. In addition, a need to pass the itemID of course, is the current list item ID.

From: http://www.anhero.org/javascript-front-end-to-start-the-sharepoint-workflow/



Ribbon Customization in SharePoint 2010

SharePoint 2010 Resources - Ribbon Development

MSDN Documentation
http://msdn.microsoft.com/en-us/library/ee540027.aspx

Blogs/Articles

Customizing the ribbon - Chris O'Brien.
http://www.sharepointnutsandbolts.com/2010/01/customizing-ribbon-part-1-creating-tabs.html

Customizing and Extending the SharePoint 2010 Server Ribbon
http://msdn.microsoft.com/en-us/library/gg552606.aspx - Andrew Connell

Creating a SharePoint 2010 Ribbon extension - part 1 - Wictor Wilén
http://www.wictorwilen.se/Post/Creating-a-SharePoint-2010-Ribbon-extension-part-1.aspx

SharePoint 2010 Ribbon Controls - Part 1 - Summary (multi-part series) - Wictor Wilén
http://www.wictorwilen.se/Post/SharePoint-2010-Ribbon-Controls-Part-1-Summary.aspx

Using RefreshCommandUI with the Server Ribbon (Dallas Tester, Fred Mameri) - SharePoint Developer Team Blog
http://blogs.msdn.com/b/sharepointdev/archive/2011/02/17/using-refreshcommandui-with-the-server-ribbon.aspx

Tokenization in the SharePoint 2010 Server Ribbon (Dallas Tester) - SharePoint Developer Team Blog
http://blogs.msdn.com/b/sharepointdev/archive/2010/12/09/tokenization-in-the-sharepoint-2010-server-ribbon.aspx

Enabling a Button on the Ribbon Based on Selection - Microsoft SharePoint Team Blog
http://sharepoint.microsoft.com/blog/Pages/BlogPost.aspx?PageType=4&ListId={72C1C85B-1D2D-4A4A-90DE-CA74A7808184}&pID=436

Fixed width layouts, the scrollbar and the ribbon in SharePoint 2010. A better way? - web.o
http://www.webpoint0.com/blog/fixed-width-layouts-scrollbar-ribbon-sharepoint-2010/

A Better Enhanced SharePoint 2010 Floating Ribbon - Greg Galipeau
http://www.greggalipeau.com/2011/01/28/a-better-enhanced-sharepoint-2010-floating-ribbon/

Code to Hide the Ribbon and Site Actions Menu for Anonymous Users - Elumenotion
http://www.elumenotion.com/Blog/Lists/Posts/Post.aspx?ID=106

Ribbon customization : Basics - Mano Mangaldas
http://howtosharepoint.blogspot.com/2010/06/ribbon-basics.html

How To Activate SharePoint Ribbon Tab by JavaScript Code - Ingo Karstein
http://ikarstein.wordpress.com/2010/06/15/how-to-activate-sharepoint-ribbon-tab-by-javascript-code/

Sample Visual Studio 2010 project for creating a custom SharePoint 2010 Ribbon tab on runtime (!) - Ingo Karstein
http://ikarstein.wordpress.com/2011/01/14/sample-visual-studio-2010-project-for-creating-a-custom-sharepoint-2010-ribbon-tab-on-runtime/

Additional Ribbon Sample: Custom Ribbon Tab generated by a delegate control that lists all associated list workflows and allow to start a workflow on a selected list item. (Part 3) - Ingo Karstein
http://ikarstein.wordpress.com/2011/03/03/additional-ribbon-sample-custom-ribbon-tab-generated-by-a-delegate-control-that-lists-all-associated-list-workflows-and-allow-to-start-a-workflow-on-a-selected-list-item-part-3/

SharePoint 2010 - Ribbon … becoming a SP2010 developer - Part 3 - Andreas Glasser
http://andreasglaser.net/post/2010/02/21/SharePoint-2010-Ribbon-e280a6-becoming-a-SP2010-developer-Part-3.aspx

Videos

Getting Started SharePoint 2010: Developing Ribbon Controls
http://www.bing.com/videos/watch/video/getting-started-sharepoint-2010-developing-ribbon-controls/10tv8hemv

Introduction to SharePoint 2010 UI Features
http://msdn.microsoft.com/en-us/SP2010DevTrainingCourse_UiEnhancementsIntro

The SharePoint Fluent User Interface
http://msdn.microsoft.com/en-us/SP2010DevTrainingCourse_TheSharePointFluentUserInterface

Module 10: Creating Dialogs and Ribbon Controls for SharePoint 2010
http://msdn.microsoft.com/en-us/sharepoint/ee513157.aspx

Codeplex projects

SharePoint 2010 Fluent Ribbon API
http://spribbon.codeplex.com/

Show or Hide SharePoint 2010 ribbon based on SharePoint Groups
http://spribbonvisibility.codeplex.com/

SharePoint 2010 Print List Ribbon Button
http://spprintlistbutton.codeplex.com/

SharePoint 2010 Custom Ribbon Demo
http://spcustomribbondemo.codeplex.com/

SharePoint 2010 Ribbon Customization with Web Parts for SharePoint
http://www.youtube.com/watch?v=YvAVMF-OBAU

Happy Coding!





SharePoint Workflows in Three Minutes

After every seminar I give, people come up and say: "you're the SharePoint Workflow guy – explain it to me in 3 minutes". Here's what you need to know:

SharePoint 2010 workflows can:

  • Automate common business steps
  • Help manage long-running processes
  • Route documents and forms
  • Collect feedback, approval, or notifications
  • Provide visual indicators of a process
  • Wash your car …

SharePoint 2010 Standard and Enterprise include a selection of 'out of the box' workflows. These tools help you automate the most common business tasks – sharing and collecting feedback on documents. I see the following workflows used most often:

  • Approval Workflow - Routes the content for approval. You can setup this workflow as serial or parallel plus preset the approvers.
  • Collect Feedback Workflow - Routes the content for feedback. When the workflow completes all the feedback is sent to the originator of the workflow.
  • Collect Signature Workflow - Rather than just sending content for approval, this workflow requires digital signatures on the content.

'Out of the Box' Workflows

'Out of the box' workflows can be added to any SharePoint document library. Simply select a template and pick a name. Your workflow can start whenever a document is added, whenever a document is changed, or both.

Built-in workflow templates make setup a snap

Once your workflow is set up, it will auto-magically run when triggered. Users may also start a workflow manually – for example, James can start an Approval workflow on his report.

Manually start a workflow in SharePoint

When the workflow starts, it will ask the user to set some rules. Who should approve the document? Is there a due date? And my favorite! Send a reminder e-mail if SharePoint doesn't hear from an approver.

Workflow setup screen

Workflows with Visio or SharePoint Designer

When your needs become more complex, SharePoint power users and developers can create custom workflows using drag-and-drop tools. Workflows are composed of simple building block "activities" and conditional logic. Workflows run based on events and conditions affecting a document or SharePoint list item.

If you are comfortable with Visio, you can use familiar tools to snap together a SharePoint workflow. Various workflow actions are available, such as Assign Task, Send E-mail, Create List Item, Collect Data from User, Wait for Timer, and more.

SharePoint Workflow in Visio 2010

Once the workflow is laid out, a tool named SharePoint Designer allows you to further define the workflow and deploy it to your SharePoint site. A simple publishing process helps you link the workflow with a SharePoint List or Document Library

Editing a workflow in SharePoint Designer

Your workflow is ready! It will automatically run whenever a document or list item is added, or users can start the workflow when they need it. Your workflow can even be started from within a Microsoft Office document.

Start a workflow from within an Office document

Were you timing me? In just a few minutes I've explained how simple – yet powerful – workflows can help you automate your business processes. Workflows can be designed to improve almost any aspect of your business. My team at Concurrency has built workflows to manage projects, track engineering change orders, manage customer service, route mortgage documents, automate human resource tasks – even starting a bidding war between vendors during an RFP process.

Let's talk and find out how SharePoint 2010 workflows can change your life!



How to Create Offline Surveys in SharePoint 2010

Using surveys out of the box in SharePoint 2010 give site collection administrators an easy way to gather information from end users, for reporting purposes. Unfortunately, if you need any special features for your surveys, the stock survey functionality quickly falls short. Custom development would then be needed to extend or enhance the functionality needed for surveys.

One such scenario requiring custom development is how to extract survey questions for offline use, along with importing survey responses from a Windows forms-based application back into SharePoint. This blog will detail the steps needed to provide this functionality. I am using SharePoint 2010, along with Visual Studio 2010 Professional Edition.

Extracting Survey Information

The first step in providing surveys offline is to extract questions from a survey. This can be done using event receivers in SharePoint 2010. Ideally you would create an event receiver that would fire when an item in a list is added, updated, or deleted, so you can capture any changes made to the survey questions. I am checking theBaseTypeof the list being added, as the event receiver will fire for other list types:


public override void FieldAdded(SPListEventProperties properties)
{
try
{
base.FieldAdded(properties);
// Only process XML Definition file for surveys
if (properties.List.BaseType == SPBaseType.Survey)
ProcessSurveyQuestions(properties.List, properties.Web.Site.RootWeb, properties.Web);
}
catch (Exception ex)
{
// Handle exception
}
}

Once you've determined that the list is a survey, getting all the information from that survey is just a matter of iterating through the list. There is a field property called SchemaXML that holds all the information for each question in the survey (in XML format), so it is a simple matter to create an XML document that represents all the survey questions contained in a survey:

int x, y;

int fCount = localSurveyList.Fields.Count;

string strFinalXML = "<Survey>";

strFinalXML += "<Title>" + localSurveyList.Title + "</Title>";

strFinalXML += "<URL>" + localSurveyList.DefaultViewUrl + "</URL>";

strFinalXML += "<SurveyURL>" + localSurveyList.DefaultViewUrl + "</SurveyURL><SurveyQuestions>";

// All questions and info are contained in list; just need to iterate through it

for (x = 0; x < fCount; x++)

{

// Do not process if fields are "Order" or "MetaInfo"

if ((localSurveyList.Fields[x].StaticName != "Order") &&

(localSurveyList.Fields[x].StaticName != "MetaInfo"))

{

// Fields need to be one of the SPFieldTypes specified in order to process

if (!localSurveyList.Fields[x].ReadOnlyField &&

(localSurveyList.Fields[x].Type == SPFieldType.Text ||

localSurveyList.Fields[x].Type == SPFieldType.Note ||

localSurveyList.Fields[x].Type == SPFieldType.Choice ||

localSurveyList.Fields[x].Type == SPFieldType.MultiChoice ||

localSurveyList.Fields[x].Type == SPFieldType.Boolean ||

localSurveyList.Fields[x].Type == SPFieldType.Currency ||

localSurveyList.Fields[x].Type == SPFieldType.DateTime ||

localSurveyList.Fields[x].Type == SPFieldType.GridChoice ||

localSurveyList.Fields[x].Type == SPFieldType.Lookup ||

localSurveyList.Fields[x].Type == SPFieldType.Number))

{

// Use SchemaXml to determine characteristics of the question

XmlDocument xmlDoc = new XmlDocument();

xmlDoc.LoadXml(localSurveyList.Fields[x].SchemaXml);

switch (localSurveyList.Fields[x].Type)

{

case SPFieldType.Text:

// question with a single line of text answer

strFinalXML += localSurveyList.Fields[x].SchemaXml;

break;

case SPFieldType.Lookup:

// Cannot use XMLSchema, so individual attributes are created

// and lookup list is retrieved manually

strFinalXML += "<Field Type=\"Lookup\" ";

strFinalXML += "DisplayName=\"" + xmlDoc.DocumentElement.Attributes["DisplayName"].Value + "\" ";

strFinalXML += "Required=\"" + xmlDoc.DocumentElement.Attributes["Required"].Value + "\" ";

strFinalXML += "EnforceUniqueValues=\"" + xmlDoc.DocumentElement.Attributes["EnforceUniqueValues"].Value + "\" ";

strFinalXML += "List=\"" + xmlDoc.DocumentElement.Attributes["List"].Value + "\" ";

strFinalXML += "ShowField=\"" + xmlDoc.DocumentElement.Attributes["ShowField"].Value + "\" ";

strFinalXML += "StaticName=\"" + xmlDoc.DocumentElement.Attributes["StaticName"].Value + "\" ";

strFinalXML += "Name=\"" + xmlDoc.DocumentElement.Attributes["Name"].Value + "\">";

// Load appropriate lookup list, using GUID

Guid listGUID = new Guid(xmlDoc.DocumentElement.Attributes["List"].Value);

SPList localList = localSurveySite.Lists[listGUID];

int fListCount = localList.ItemCount;

strFinalXML += "<CHOICES>";

for (y = 0; y < fListCount; y++)

strFinalXML += "<CHOICE>" + localList.Items[y].Title + "</CHOICE>";

strFinalXML += "</CHOICES></Field>";

break;

default:

break;

}

}

}

}

strFinalXML += "</SurveyQuestions></Survey>";

// Replace any ampersands with proper syntax

strFinalXML = strFinalXML.Replace("&", "&amp;");

A few things to note are that I skip fields in the field collection with the StaticName of "Order" or "MetaInfo", as those fields do not hold information concerning the survey questions. Additionally, the code snippet is not extracting the information from every question type. This was done for brevity in the article, and it is up to the reader to extend the code to handle all question types.

Also note that for lookup question types, I cannot use the SchemaXML information directly, so I am forced to extract the individual attributes I need separately. This is necessary in order to extract all the possible choices that the survey question presents (as the lookup type is a dropdown, radio buttons or check boxes). The GUID of the lookup list is provided, and I am using that to reference the list in SharePoint, in order to iterate through the items in that list, to save them to my XML string.

Once the XML string is created for all the survey questions, we need to do something with that information. I am saving this XML as a document in a document library in SharePoint that I've created (named SurveyDefinitions), as seen below:

try

{

string strSurveyFileName = "FinalSurveyXML.xml";

string onlineSurveySiteRootURL = "http://yoursite.com/";

string surveySiteURL="";

string targetDocLibrary = "Survey Definitions";

using (SPSite site = new SPSite(onlineSurveySiteRootURL))

{

site.AllowUnsafeUpdates = true;

using (SPWeb web = site.OpenWeb(surveySiteURL))

{

web.AllowUnsafeUpdates = true;

SPDocumentLibrary lib = (SPDocumentLibrary)web.Lists[targetDocLibrary];

// Upload survey file to document library (for processing)

// Open and read XML data file into a byte array

System.Text.ASCIIEncoding encoding = new System.Text.ASCIIEncoding();

byte[] content = new byte[strFinalXML.Length];

content = encoding.GetBytes(strFinalXML);

SPFileCollection col = web.Files;

SPFile file = col.Add(onlineSurveySiteRootURL + surveySiteURL + targetDocLibrary + "/" + strSurveyFileName, content,true);

file.Update();

web.AllowUnsafeUpdates = false;

}

}

localSurveySite.AllowUnsafeUpdates = false;

}

catch (Exception ex)

{

}

}

Displaying Surveys Offline

Now that we have our XML file for a survey, we need to use it outside of SharePoint. We can create a Windows Forms-based application to display the survey questions, and allow the user to enter responses for the survey.

The main challenge of displaying surveys offline is that we don't know beforehand what questions are in a survey, so any application will have to render the controls associated with the survey questions dynamically. Here is where the XML file generated earlier comes into play. We can iterate through the XML file to determine what type of survey questions are contained within, and render the proper controls dynamically in our application:

// Read XML Definition file and iterate through it, rendering controls

XPathNavigator nav;

XPathDocument docNav;

// Open the XML.

docNav = new XPathDocument(ConfigurationManager.AppSettings["XMLDefinitionFilesLocation"] + strSurveyFile);

// Create a navigator to query with XPath.

nav = docNav.CreateNavigator();

// Initial XPathNavigator to start at the root.

nav.MoveToRoot();

// Move to the first child node

nav.MoveToFollowing("SurveyQuestions", "");

// Find the first element (must be 'SurveyQuestions')

if ((nav.NodeType == XPathNodeType.Element) && (nav.Name == "SurveyQuestions"))

{

nav.MoveToFirstChild();

yPos = yCtlSpacerValue;

xCtlMaxWidthValue = (pnlContainer.Width – xLeftSpacerValue – xRightSpacerValue);

// Iterate through Fields listed

do

{

// Get control info from XML file

strControlType = nav.GetAttribute("Type", "");

strDisplayName = nav.GetAttribute("DisplayName", "");

// Render label control for question text

lblQuestion = new Label();

lblQuestion.Name = "lbl" + strDisplayName;

lblQuestion.Text = strDisplayName;

lblQuestion.AutoSize = false;

// Add the question text label to the form

pnlContainer.Controls.Add(lblQuestion);

lblQuestion.Location = new System.Drawing.Point(xLeftSpacerValue, yPos);

lblQuestion.Size = lblQuestion.GetPreferredSize(new Size(xCtlMaxWidthValue, yCtlHeightValue));

yPos += (lblQuestion.Height + yCtlSpacerValue);

switch (strControlType)

{

case "Text":

bRequired = Convert.ToBoolean(nav.GetAttribute("Required", ""));

if (nav.GetAttribute("MaxLength", "").Trim() != "")

nMaxLength = Convert.ToInt32(nav.GetAttribute("MaxLength", ""));

else

nMaxLength = -1;

txtField = new RegExTextBox();

txtField.Required = bRequired;

txtField.Name = nav.GetAttribute("DisplayName", "");

if (nMaxLength != -1)

txtField.MaxLength = nMaxLength;

txtField.Multiline = false;

txtField.Tag = strControlType; // Holds the control type

txtField.ThemeName = ConfigurationManager.AppSettings["TelerikControlThemeName"];

txtField.Validating += new CancelEventHandler(ControlFields_Validating);

// Add the new control to the form

pnlContainer.Controls.Add(txtField);

txtField.Size = new System.Drawing.Size(xCtlMaxWidthValue, yCtlHeightValue);

txtField.Location = new System.Drawing.Point(xLeftSpacerValue, yPos);

// Set ErrorProvider Icon location to be left of the control

this.errorProvider1.SetIconAlignment(txtField, System.Windows.Forms.ErrorIconAlignment.MiddleLeft);

// Increment y position for next control

yPos += (yCtlHeightValue + yCtlSpacerValue);

break;

default:

break;

}

} while (nav.MoveToNext());

}

else

{

// Throw exception stating XML Definition file is not in correct format

throw new Exception("Definition file is not in the correct format. File=" + strSurveyFile);

}

Our application also allows the user to save his/her responses for the survey they have selected, and this response information is saved to a different XML file. Please note that for lookup lists, radio buttons and multiple selection checkboxes, there is a specific format that you must follow when saving your responses to the XML file. This is necessary when importing the survey responses back into SharePoint, which I will describe in the next section.

// This method retrieves the survey question responses (from the controls on the form)

// and saves them to an XML Data file

public static void SaveSurveyResponses(Panel pnlContainer, string strSurveyFile, string strSurveyTitle, string strDestFile, string strCustomerSelected)

{

string strFinalXML = "<Survey>";

string strDateTimeIdentifier = DateTime.Now.ToString("MM-dd-yyyy-mm-ss");

string strLocalSurveyTitle;

// Strip out unique identifier (after the '_')

if (strSurveyTitle.IndexOf("_") > 0)

{

strLocalSurveyTitle = strSurveyTitle.Substring(0, strSurveyTitle.IndexOf("_"));

strDateTimeIdentifier = strSurveyTitle.Substring((strSurveyTitle.IndexOf("_") + 1));

}

else

strLocalSurveyTitle = strSurveyTitle;

// Retrieve list of survey questions, and calc max label width needed

List<string> strQuestions = SurveyInfo.GetSurveyQuestions(strSurveyFile);

XmlDocument xmlFinalDoc = new XmlDocument();

strFinalXML += "<DefinitionFile>" + strSurveyFile + "</DefinitionFile>";

strFinalXML += "<Title>" + strLocalSurveyTitle + "</Title>";

strFinalXML += "<UniqueName>" + strLocalSurveyTitle + "_" + strCustomerSelected + "</UniqueName><SurveyQuestions>";

#region Create XML for Controls

// All questions and info are contained in controls; just need to iterate through them

foreach (Control c in pnlContainer.Controls)

{

// Do not process labels

if (!(c is Label))

{

string strControlType = c.Tag.ToString();

// Single, multiple line textbox question; also number or currency textbox

if (c is RadTextBox)

{

RadTextBox localControl = (RadTextBox)c;

strFinalXML += "<Field Type=\"" + strControlType + "\" DisplayName=\"" + SurveyInfo.Encode(localControl.Name) + "\" ";

// Question is single line textbox

if (strControlType == "Text")

strFinalXML += "MaxLength=\"" + localControl.MaxLength.ToString() + "\">";

else

strFinalXML += ">";

// Add field value to XML string

strFinalXML += SurveyInfo.Encode(localControl.Text) + "</Field>";

}

// Choice – Listbox questions (multichoice lookup question)

if (c is RadListBox)

{

RadListBox localControl = (RadListBox)c;

// Question is Lookup

if (strControlType == "Lookup")

{

strFinalXML += "<Field Type=\"Lookup\" ";

strFinalXML += "DisplayName=\"" + SurveyInfo.Encode(localControl.Name) + "\">";

foreach (RadListBoxItem rlbi in localControl.SelectedItems)

{

//1;#11102;#6;#11204;#7;#11210

//strFinalXML += localControl.SelectedIndex.ToString() + ";#" + SurveyInfo.Encode(localControl.Text) + "</Field>";

strFinalXML += rlbi.Value.ToString() + ";#" + SurveyInfo.Encode(rlbi.Text) + ";#";

}

// Remove final ";#' from string

strFinalXML = strFinalXML.Remove((strFinalXML.Length – 2), 2);

strFinalXML += "</Field>";

}

}

}

}

strFinalXML += "</SurveyQuestions></Survey>";

// Replace any ampersands with proper syntax, _x0020_ with a space

strFinalXML = strFinalXML.Replace("_x0020_", " ");

SharePoint 2010 Content Organizer

One of the most powerful features within SharePoint 2010 for document management is the Content Organizer. This feature allows for the automatic routing of documents to different libraries and folders within those libraries based on pre-defined rules.

The core strength of this tool is the management of document libraries and the flow of documents into these locations. Building upon the SharePoint 2007 Records Center, it expands routing to allow for the use of managed metadata as a key document property. Documents can be routed to document libraries within other Site Collections if the Content Organizer is activated in both the sending and receiving Site Collection. A threshold can also be set for the folders within a document library to limit the number of items it can hold. When the threshold is met, a new folder is automatically created and configured with a pre-formatted naming convention.

In order for routing to occur, routing rules must be in place. Creation of routing rules is based on content types and can contain multiple conditions. Using managed metadata in conditions allows for a centralized source to manage large amounts of descriptive document information. Routing rules are stored in the Content Organizer Rules list for ease of creation and editing.

Sample Content Organizer Rule Setting

SharePoint 2010 Content Organizer

Successful use of the Content Organizer depends on several key factors. A few suggestions are as follows:

Gain a keen understanding of how your users organize documents.

Understanding how users organize documents is critical to laying out the technical foundation for routing. Determine the folder structure and folder naming conventions currently used by your organization. Example: If users in the Sales department store documents by client name and then by document type, use this folder structure as baseline for determining if this structure is effective or if another structure is better suited for your centralized document libraries.

Discover the document types and descriptions for documents.

Document types can range from drafts and memos to finalized estimates and proposals. Users also refer to these documents by different descriptions. Example: A proposal could be referenced as "Microsoft Proposal", "Proposal 2-22-10", "Proposal V5", or "Proposal – Final Version". It is imperative to come to a consensus document type and description naming convention for documents. Doing so will make it easier for users to properly tag and describe documents. They will also be able to locate and access these documents quickly and effectively.

Use managed metadata to properly tag documents.

Once you have determined the document type and description naming convention, use these terms to populate the appropriate managed metadata term set. Use managed metadata to control the metadata placed on documents. This ensures that documents will have the correct description and be routed to the correct location. Example: Users open document templates which include metadata for client name and document type. Their choices for client name and document type are determined by the managed metadata values in SharePoint. Once they select the client name and document type, the document will be routed to the appropriate folder.

Create meaningful folder structures and routing rules.

Create a folder structure that reflects how your users should organize and access documents. Be specific as possible and avoid the use of general buckets for documents. Your routing rules should be based on predefined managed metadata. Example: If the client name is "Microsoft" and the document type is "Proposal" route the document to the "Proposals" folder within the "Microsoft" folder.

Conclusion

With the Content Organizer in place, and the logical aspect of where and how you want to route documents determined, great efficiencies come into play as documents are sent to the correct location and users no longer ask the question "Where is that document?".



Permissions and Security in SharePoint 2010

Microsoft SharePoint Server 2010 includes six permission levels by default. You can customize the permissions available in these permission levels (except for the Limited Access and Full Control permission levels), or you can create customized permission levels that contain only the specific permissions you need.

Although you cannot directly edit the Limited Access and Full Control permission levels, you can make individual permissions unavailable for the entire Web application, which removes those permissions from the Limited Access and Full Control permission levels.

The following tables from TechNet illustrate the various permissions for team and non-team sites:

Permission levels for team sites

Permission level Description Permissions included by default
Limited Access Allows access to shared resources in the Web site so that the users can access an item within the site. Designed to be combined with fine-grained permissions to give users access to a specific list, document library, item, or document, without giving them access to the entire site. Cannot be customized or deleted.
  • Browse User Information
  • Use Client Integration Features Open
Read Allows read-only access to the Web site.
  • View Items
  • Open Items
  • View Versions
  • Create Alerts
  • View Application Pages
  • Use Self-Service Site Creation
  • View Pages
  • Browse User Information
  • Use Remote Interfaces
  • Use Client Integration Features
  • Open
Contribute Create and edit items in the existing lists and document libraries.
  • Read permissions, plus:
  • Manage Unsafe Content
Design Create lists and document libraries and edit pages in the Web site.
  • Approve permissions, plus:
  • Manage Lists
  • Add and Customize Pages
  • Apply Themes and Borders
  • Apply Style Sheets
Full Control Allows full control of the scope. All permissions

If you use a site template other than the team site template, you will see a different list of default SharePoint groups. For example, the following table shows additional permission levels provided with the publishing template.

Permission levels for non-team sites

Permission level Description Permissions included by default
Restricted Read View pages and documents. For publishing sites only.
  • View Items
  • Open Items
  • View Pages
  • Open
View Only View pages, list items, and documents. If the document has a server-side file handler available, they can only view the document by using that file handler.
  • Limited Access permissions, plus:
  • View Items
  • View Versions
  • Create Alerts
  • Create mobile alerts
  • View Application Pages
Approve Edit and approve pages, list items, and documents. For publishing sites only.
  • Contribute permissions, plus:
  • Override Checkout
  • Approve Items
Manage Hierarchy Create sites; edit pages, list items, and documents. For Publishing sites only.
  • Design permissions minus the Approve Items permission), plus:
  • Manage permissions
  • View Usage Data
  • Create Subsites
  • Manage Web Site
  • Manage Alerts

Unmanageable security is one of the primary factors which leads to "SharePoint Creep", as users create new sites when they are unsure of the current sites security level. The following guidance is intended to assist with creating a security model that is effective, scalable, and manageable.

  1. Centrally create SharePoint security groups and add Active Directory (AD) groups to the SharePoint groups.

    By creating a SharePoint Security Group and then adding Active Directory (AD) groups to the SharePoint Group, you will essentially encapsulate any AD groups or individuals into one manageable container. This will help prevent "one off" security setting in which the administration time of trying to manage multiple groups or individuals is severely reduced as security is controlled at the container level. This is known as the "group within a group" approach for SharePoint security modeling. The groups should be created at the root of SharePoint Site Collection and then inherited down across sites. Break inheritance only when SharePoint groups should not have permissions to a site and need to be removed. If you break inheritance and create a new group, you have broken the centralization of your security model and lost a large portion of the capability to track which SharePoint groups have been created.

  2. Avoid adding individuals. Use Active Directory groups instead.

    By adding groups from Active Directory to SharePoint, individuals still receive permissions and if they leave a group (ex. an employee changes from Marketing to Sales) they are automatically removed from the sites the group they belonged to had access to. If an individual is added, they will need to be removed at one a time from any SharePoint sites or objects they were given access to. Even if a group has only one individual, try to create a group so that security is set with a role based methodology (ex. there is only one person who undertakes quality control in the organization. They should be added to a Quality Control group with Active Directory, and then the AD Quality Control group should be added to the SharePoint Quality Control Group that has "Contribute" access to the Sales site).





What is Delegate Controls in SharePoint 2010

SharePoint provides a mechanism that allows developers to customize out-of-the-box functionality in pages, without the need for modifying the pages that come with SharePoint. This mechanism is provided with delegate controls. I am going to show you how to create a delegate control that you can use to override the Global Navigation bar at the top of standard SharePoint pages.

Definition

First off, it's important to understand what a delegate control is, so we can properly create and apply it in the specific situation we are developing for. A delegate control defines a region in an aspx page that allows the content to be replaced with our custom content. This custom content is created via a SharePoint feature, and when deployed and activated, replaces the standard content at runtime.

Development

The Global Navigation bar is located at the top of all the pages in a site, and the master page uses a delegate control in a placeholder to determine what to render at runtime. Here is the markup for the delegate control:

<SharePoint:DelegateControl runat="server" ControlId="GlobalNavigation"/>

Note that the ControlId value determines what delegate control is, so for our example the Global Navigation bar has a ControlId value of GlobalNavigation.

Once we know the name of the delegate control we are working with, we are ready to write code for our delegate control.

Open Visual Studio 2010 and create a new Empty SharePoint project. Map a folder to the CONTROLTEMPLATES directory in the SharePoint root (the 14 hive). Add a new SharePoint 2010 User Control by right-mouse clicking the CONTROLTEMPLATES mapped directory, from the Solution Explorer. Give the user control an appropriate name (I named it ucGlobNavDelegateControl). Once the control is created, open it in the Designer and add some markup:

Custom Delegate Control

You will also need to create an Elements.xml file, so add a module to the project, which will create the Elements.xml file as part of it (you can delete the Sample.txt file created).

Delete the markup between the Elements tags, and add the following markup:

<Control Id = "GlobalNavigation" Sequence="90"  ControlSrc="~/_ControlTemplates/ucGlobNavDelegateControl.ascx" />

This markup associates the delegate control we are creating with the delegate control placeholder defined in the master pages in a SharePoint site collection. Note that the ControlId value equals GlobalNavigation, which specifies that our custom delegate control is overriding the Global Navigation control. The Sequence value must be less than 100, since SharePoint will render the control with the lowest sequence (the default control is set at 100). The ControlSrc value indicates the location to our custom delegate control.

Deployment

Deploying our custom delegate control is done using a feature, so create a feature in Visual Studio and name it MyCustomGlobalNavigationFeature. Add the module you created to it, and set the feature scope to Web. Compile and deploy the project to your SharePoint site.

Once your feature is deployed successfully, you should be able to verify that your feature has been deployed and activated in your site by managing the Site Features, under Site Settings. Look for your deployed feature, as shown here:

Activating Feature

If your feature is properly activated, you should now see the Global Navigation replaced by your custom delegate control:

SharePoint Page with Custom Delegate Control

Conclusion

And that's all there is to it! Of course, the example here is basic, so there is a lot more that can be done with delegate controls. I am also including a screenshot of my Solution Explorer in Visual Studio, so you can get an idea of how my example project was structured:

Solution Explorer



How to Add jQuery to SharePoint 2010

In this article I'll show you how to create a nice SharePoint 2010 wsp Feature that you can deploy to any SharePoint site you'd like, and when activated, it will "turn on" jQuery for all of your webs in the site collection (without editing the MasterPage)! Let's get started:

Creating the Project

  1. In Visual Studio, create a new SharePoint 2010 "Empty SharePoint Project"
  2. Name it "jQueryFrameworkFeature"
  3. Enter your local site address and choose "Deploy as a farm solution" in the SharePoint Customization Wizard.

Prepping the Project

You should be looking at a new Empty SharePoint Project. Now, let's prep the project:

  1. Right click on your jQueryFrameworkFeature project node in the solution explorer, choose "Add > SharePoint Mapped Folder…"
  2. Expand the "TEMPLATE" node, choose "CONTROLTEMPLATES" and click OK.
  3. In the Solution Explorer, right click the newly added mapped folder, "CONTROLTEMPLATES" and add a new folder named "jQueryFrameworkFeature"
  4. Add another SharePoint Mapped Folder again, this time chose TEMPLATE\IMAGES

We now have our basic folder structure that we'll need and so the overall project should now look like this:

The next thing we want to do is have a cool icon that will be used in our feature list in SharePoint to set it apart from the other generic looking features. I've created my own that will immediately scream jQuery! when you see it in the list:

Save the image above into your IMAGES/jQueryFrameworkFeature folder.

Adding the jQuery

The next thing that we'll need to do is add a user control to our jQueryFrameworkFeature folder in our CONTROLTEMPLATES folder. Follow these steps:

  1. Right click on jQueryFrameworkFeature folder in our CONTROLTEMPLATES folder, and choose "Add > New Item…"
  2. Under SharePoint > 2010, select "User Control"
  3. Name it jQueryRef.ascx, click the Add button.
  4. Delete the jQueryRef.ascx.cs file (this will also delete the .designer file too, which is OK).
  5. Open the Source code view for the jQueryRef.ascx file and remove every single line of code except for the "<%@ Control …" line (should be the last line of code). You should now have something like this:
  6. Remove the CodeBehind="jQueryRef.ascx.cs" property completely.
  7. Directly after the Control declaration line, add the following line of code:
    < script type="text/javascript" src="http://ajax.aspnetcdn.com/ajax/jQuery/jquery-1.5.1.min.js "></script>
  8. Save, and then close this file.

Getting it on the MasterPage

So you might wonder how we're going to get jQuery onto the MasterPage without editing it. Well as you've seen already, we've got a User Control with our jQuery reference sitting in it. Because of this, we can put this user control into one of the MasterPage's content control areas, specifically the "AdditionalPageHead" area. Here's how:

  1. Right click on your project, choose "Add > New Item…"
  2. In SharePoint > 2010 choose "Module"
  3. Name it "jQueryFrameworkModule"
  4. Within the module we've just added, remove the "Sample.txt" file.
  5. Open the elements.xml file and edit to look like this:

Creating the Feature

In the previous section, when adding the module, you may have noticed that it created a feature for us, named "Feature1." We'll use this to complete the process:

  1. Rename "Feature1″ to "jQueryFrameworkFeature"
  2. Double click on the first node of this feature to edit its properties. You should see in the "Item in the Feature" list on the right our "jQueryFrameworkModule" module.
  3. Enter, for the title, "jQuery Framework"
  4. Enter, for the description, "Enables the user of jQuery framework across pages in the current site collection.
  5. Change the Scope to "Site"
  6. In the properties window in the lower right, find the "Image Url" property, and enter the following URL
    jQueryFrameworkFeature/jQueryFrameworkFeature.gif

If you right click on your project and deploy you will now have jQuery in your SharePoint!