Showing posts with label Best Practices. Show all posts
Showing posts with label Best Practices. Show all posts

Tuesday, 4 December 2012

SharePoint Create Page Layouts for Custom Content Types


Hi All,

If you want to create custom content types and page layouts from your custom content types then refer to the links below-

http://www.dotnetcurry.com/ShowArticle.aspx?ID=620
http://www.dotnetcurry.com/ShowArticle.aspx?ID=638

Thanks Sumit for this wonderful post.

Thanks.
Read More

Monday, 3 December 2012

AllowUnsafeUpdates VS RunWithElevatedPrivileges

AllowUnsafeUpdates: If your code modifies Windows SharePoint Services data in some way, you may need to allow unsafe updates on the Web site, without requiring a security validation. You can do by setting the AllowUnsafeUpdates property.
For detail click here AllowUnsafeUpdates

RunWithElevatedPrivileges : There are certain object model calls model that require site-administration privileges. To bypass access-denied error, we use RunWithElevatedPrivileges property when request is initiated by a nonprivileged user. We can successfully make calls into the object model by calling the RunWithElevatedPrivileges method provided by the SPSecurity class.
For detail click here RunWithElevatedPrivileges

Thanks!
Nikhil S.
Read More

SharePoint Adding a View More Link to the Web Part



When we’re designing or mocking up a SharePoint Intranet, Extranet or Internet we always talk about content roll up. SharePoint does a great job with content roll up OOTB (within the same Site Collection at least) using the Content Query Web Part. However, any time you show the client the power of the Content Query Web Part a typical question usually follows…
I love how I can see the top 5 most recent documents… but where is the link to “view more”? How do I get to the rest of the documents?
Like anything else with SharePoint it’s the 80-90% that’s easy and the little questions like this that cause the grief. Now, you could modify the Content Query Web Part styles but that’s not very manageable. Or you could drop a Content Editor Web Part on the page but that seems like a lot of work for one link. Heck, with SharePoint 2010 you could even use an inline Web Part in your main content area and just include the link yourself.

ISN’T THERE AN EASIER WAY?

What if you wanted something that looks like this:
Let’s keep this simple, make it flexible and allow you to use this technique on any Web Part, OOTB or custom.

THE WEB PART CONFIGURATION

First, we’re going to put the URL that we want the link to point to in the Title URL of the web part. Normally this would make the title of the Web Part clickable… but using some jQuery we can disable that link later.
Next we’re going to use the Description to hold the link caption (You we’re using the description anyways… were you?).
Now when we save the web part SharePoint will automatically display the tooltip of the Web Part title as “Web Part Title – Web Part Description”. We’re going to use this detail to our advantage next.

THE JQUERY

$('.ms-WPHeaderTd').each(function() {
     var title = $(this).attr('title');
     var titleIndex = title.indexOf(' - ');
 
     if (titleIndex != -1) {
          $(this).attr('title', title.substring(0, titleIndex));
          title = title.substring(titleIndex + 3);
   if ($(this).find('a').length) {
        var link = $(this).find('a');
        var url = link.attr('href');
               $(this).find('h3').html(link.html());
               $(this).parent().append('<td class="view-more"><a href="' + url + '">' + title + '</a></td>');
          }
     }        
});
The code above is going to perform the following:
  1. Loop through all Web Part Headers on the page
  2. Find the title of the Web Part
  3. Determine if the Web Part is using a description (we make some assumptions to do this)
  4. Remove the description from the Web Part title
  5. Make sure the Web Part has a Title URL configured
  6. Remove the link from the Web Part title
  7. Add a new table cell at the end of the Web Part title to show our view more link

THE CSS

Last but not least let’s style our links! You can do anything you want at this point but here’s the CSS I’m using in the screenshot above:
.view-more { text-align: right; width: 70px; }
.view-more a { color: #29466F; }
.view-more a:hover { text-decoration: underline; }
jQuery to the rescue… again!

This was the cool Post by Cory Peters
Read More

SharePoint Feature List Type Registration ID's


RegistrationId List Template Type IDs:
InvalidType = -1
GenericList = 100
DocumentLibrary = 101
Survey = 102
Links = 103
Announcements = 104
Contacts = 105
Events = 106
Tasks = 107
DiscussionBoard = 108
PictureLibrary = 109
DataSources = 110
WebTemplateCatalog = 111
UserInformation = 112
WebPartCatalog = 113
ListTemplateCatalog = 114
XMLForm = 115 (InfoPath Forms Library)
MasterPageCatalog = 116
NoCodeWorkflows = 117
WorkflowProcess = 118
WebPageLibrary = 119
CustomGrid = 120
DataConnectionLibrary = 130
WorkflowHistory = 140
GanttTasks = 150
Meetings = 200
Agenda = 201
MeetingUser = 202
Decision = 204
MeetingObjective = 207
TextBox = 210
ThingsToBring = 211
HomePageLibrary = 212
Posts = 301
Comments = 302
Categories = 303
Pages = 850
(thanks to Anders Jacobsen for this one)IssueTracking = 1100
AdminTasks = 1200
Translation Management Library = 1300
Languages & Translations = 130
1
Read More

Tips for Dealing with Performance Issues in SharePoint



Hi All,

Please refer to the following link of you are looking for optimizing performance of SharePoint site.

http://social.technet.microsoft.com/wiki/contents/articles/7926.sharepoint-2010-tips-for-dealing-with-performance-issues.aspx

Thanks,
Nikhil S.
Read More

Advance paging in SharePoint 2010-2013 using Client Object Model and jQuery


Hi All,

Refer to this Link to see how to create custom paging by using SharePoint Client Object Model and JQuery without need to navigate between pages.

New idea,new Approach.   

Thanks,   Nikhil S.  

Read More

Get Client ID of Server Control in Javascript


Hi All,

Please find below simple JavaScript function to get client Id render by server control in html page via JavaScript.

          //function
function GetClientID(id, context) {
    var el = $("#" + id, context);

    if (el.length < 1)

    el = $("[id$=_" + id + "]", context);

    return el;

}
            //function call    
  var ctrlOk = GetClientID("btnOk").attr("id");

Where "btnOk" is the Id of your server control.

Thanks,
Nikhil S.
Read More

Sunday, 2 December 2012

Properly Populate and Retrieve SharePoint Field Data for Lookup, User and Choice Fields


SharePoint uses a lot of field types that have different underlying schemas, delimiters and formats. I see a lot of people reverse engineer the field information and “hack” the data into the list using a string such as “1;#Title” for a lookup field. Well this isn't exactly best practice so I've put together a reference table below to assist in using the correct data types for populating or retrieving information from a SharePoint list.


LOOKUP FIELD

Field Class: SPFieldLookup
Field Value Class: SPFieldLookupValue
Populating Information:
item["FieldName"] = new SPFieldLookupValue("Title"); // SharePoint will do the lookup as long as the LookupValue's are unique
item.Update();
or
item["FieldName"] = new SPFieldLookupValue(1, "Title");
item.Update();
Retrieving Information:
SPFieldLookupValue itemValue = item["FieldName"] as SPFieldLookupValue;
int id = itemValue.LookupId;
string value = itemValue.LookupValue;

MULTIPLE LOOKUP FIELD

Field Class: SPFieldLookup
Field Value Class: SPFieldLookupValueCollection
Populating Information:
SPFieldLookupValueCollection itemValues = SPFieldLookupValueCollection();
itemValues.Add(new SPFieldLookupValue(1, "Title"));
item["FieldName"] = itemValues;
item.Update();
Retrieving Information:
SPFieldLookupValueCollection itemValues = item["FieldName"] as SPFieldLookupValueCollection;
foreach (SPFieldLookupValue itemValue in itemValues)
{
int id = itemValue.LookupId;
string value = itemValue.LookupValue;
}

USER FIELD

Field Class: SPFieldUser
Field Value Class: SPFieldUserValue
Populating Information:
web.EnsureUser(@"domain\username");
SPUser user = web.AllUsers[@"domain\username"];
item["FieldName"] = user;
item.Update();
Retrieving Information:
string currentValue = item["FieldName"].ToString();
SPFieldUser userField = list.Fields.GetFieldByInternalName("FieldName");
SPFieldUserValue itemValue = (SPFieldUserValue)userField.GetFieldValue(currentValue);
SPUser user = itemValue.User;

URL FIELD

Field Class: SPFieldUrl
Field Value Class: SPFieldUrlValue
Populating Information:
SPFieldUrlValue urlValue = new SPFieldUrlValue();
urlValue.Url = "http://www.google.com";
urlValue.Description = "Google";
item["FieldName"] = urlValue;
item.Update();
Retrieving Information:
SPFieldUrlValue urlValue = new SPFieldUrlValue(item["FieldName"].ToString());
string url = urlValue.Url;
string description = urlValue.Description;

MULTIPLE CHOICE FIELD

Field Class: SPFieldMultiChoice
Field Value Class: SPFieldMultiChoiceValue
Populating Information:
SPFieldMultiChoiceValue itemValue = new SPFieldMultiChoiceValue();
itemValue.Add("Choice 1");
itemValue.Add("Choice 2");
itemValue.Add("Choice 3");
item["FieldName"] = itemValue;
item.Update();
Retrieving Information:
SPFieldMultiChoiceValue itemValue = new SPFieldMultiChoiceValue(item["FieldName"].ToString());
for (int i = 0; i < itemValue.Count; i++)
{
string choice = itemValue[i];
}




Read More

Translate

Total Pageviews

Powered By Blogger · Designed By Seo Blogger Templates