Something went wrong with your my site setup – SP2013

If you have installed SP 2013 environment and trying to use My Sites you may see the following error.

MySite.png

This could be for multiple reasons. First read the following article and make sure you have followed steps mentioned in it for configuring your My Site.

http://technet.microsoft.com/en-us/library/ee624362.aspx

If you have followed these steps correctly then it may be because of server is running low on resources.

State Machine Workflow in SharePoint 2010

I was thinking of writing a blog post on Step by Step State Machine Workflow. Lately I am busy with work and hence did not get chance.

I will definitely write that article in near future but meanwhile you can have a sample State Machine Workflow Project which I have created.

State Machine Workflow Sample

This is just a sample for your learning purpose only. This has not been tested for production use and this sample contains no warranties.

Getting ID of uploaded document or File in SharePoint 2010

If you are uploading a File​ to SharePoint 2010 programmatically and wanted to get the ID of that newly created file then you can use following code.

//Upload your File

SPFile myFile = spList.RootFolder.Files.Add
                (FileUpload1.PostedFile.FileName, StreamImage, replaceExistingFiles);

SPListItem item = imgFile.Item;

// Then you can use item.ID

I am not providing full code for file upload but the key here is to get SPListItem from SPFile class.

I hope it helps.

Set Default value for Enhanced Rich Text Box in SP 2010 using Jquery.

This one was tricky.

If you ever want to set default value for Enhanced Rich Text Box you can use following​ Jquery.

<script language="javascript" type="text/javascript" src="/sites/testsc/Style%20Library/jquery-1.9.0.min.js"></script>

    <script language="javascript" type="text/javascript">
    $(document).ready(function() {    
    
    $('nobr:contains("Desc")').closest('tr').find('input[id$="TextField_spSave"]').val('Hello World !!!');
    });
</script>

This is copied from the thread below.

http://social.msdn.microsoft.com/Forums/en-US/sharepointdevelopment/thread/ae414aec-1dd0-474b-bda7-04092f1c4908/

If you want to insert HTML inside you can simply inesert your HTML as part of setting up value.

$(‘nobr:contains(“Rich Text”)’).closest(‘tr’).find(‘input[id$=”TextField_spSave”]’).
val(‘<table border=”1″><tr><td>Hello </td><td><b>World !!!</b></td></tr></table>’);

Get Current User using Jquery in SP 2010

​This has already been posted many times but question still keeps coming up on how to get the current user using Jquery.

Here is the code.

<script src="/sites/devsc/Style%20Library/jquery-1.8.3.min.js" type="text/javascript"></script>
<script src="/sites/devsc/Style%20Library/jquery.SPServices-0.7.2.min.js" type="text/javascript"></script>
<script type="text/javascript">
    $(document).ready(function() {
      var thisUser = $().SPServices.SPGetCurrentUser();
       
  alert(thisUser);
    });
</script>

 

Make sure to reference Jquery and SPServices library. When you download Jquery library don’t download 1.9.x as it did not work with SPServices 0.7.2 (as of today).

Cheers

Programmatically adding My Site Quick Links in SharePoint 2010

I recently had this question on how to programmatically add My Site Quick Links in SharePoint 2010.

This can be achieved using QuickLinkManager Class to create quick links.

http://msdn.microsoft.com/en-us/library/microsoft.office.server.userprofiles.quicklinkmanager.aspx

public void AddQuickLinks()
        {
            SPSite site = new SPSite(“SITEURL”);
            SPServiceContext serviceContext =SPServiceContext.GetContext(site);
            UserProfileManager upm = newUserProfileManager(serviceContext);
            // This is just an example and hence username is hardcoded but basically you can loop through Users and pass their Username.
            string strUser = “DOMAIN\\USERNAME”;
            if (upm.UserExists(strUser))
            {
                UserProfile u = upm.GetUserProfile(strUser);
                QuickLinkManager qlm = u.QuickLinks;
                // I have hard coded the link but you will be reading these from your SQL DB.
                string strTitle = “mylink”;
                string sLinkUrl = “http://my”;
                string strGroup = “my group”;
                QuickLink ql = qlm.Create(strTitle, sLinkUrl, QuickLinkGroupType.UserSpecified, strGroup,Privacy.Public);
                ql.Commit();
            }
        }