Tuesday, 28 May 2013

SQL Sever 2008 R2 has an unsupported version error in SharePoint product configuration wizard


I was trying to create a SharePoint 2013 development VM and came across this nasty error,

SQL server at "SQLSERVERNAME" has an unsupported version at "xxx.xxx.x.x" (IP address). Please refer to http://technet.microsoft.com/library/cc262485(office.15)?ocid=fwlink#section5 for more information on the minimum required SQL Server Versions and how to download them.






I also tried PowerShell to create a configuration database but got same error,



PS C:\Users\Administrator> New-SpConfigurationDatabase
cmdlet New-SPConfigurationDatabase at command pipeline position 1
Supply values for the following parameters:
DatabaseName: SharePoint_Config
DatabaseServer: MSSQLSERVER
FarmCredentials
Passphrase: myPass



I fixed the error by installing update for SQL Server by Microsoft to make it work with SharePoint 2013. I downloaded Microsoft® SQL Server® 2008 R2 Service Pack 1 from http://www.microsoft.com/en-us/download/details.aspx?id=26727

Running this setup will update your SQL Server R2 to SP1 which is requirement for SharePoint 2013.



Upgrading your MCITP : SharePoint Administrator 2010 to SharePoint 2013 Solution Expert


If you already earned MCITP : SharePoint 2010 Administrator certification then you can easily upgrade it to SharePoint 2013 Solution Expert by passing 417, 331 and 332 exams, as shown in picture below,



Source : http://www.microsoft.com/learning/en/us/mcse-sharepoint-certification.aspx#fbid=MDgfOwqPuct?upgradeable

There isn't any upgrade path came out yet(28-05-2013) for MCPD : SharePoint 2010 Professional developers to upgrade and get certified in SharePoint 2013.

Thursday, 23 May 2013

Capturing iPad or iPhone traffic using Fiddler2

Recently I have been given a task to find out why iPad application isn't getting the "correct" data from our SharePoint environment. I don't know much about how iPad has been developed but I been told it's consuming custom web services. Hence I downloaded Fiddler2 to analyse iPad traffic and see what has been requested by iPad and what is it getting in return.

Once you downloaded Fiddler2 on your computer, you can add proxy details to your iPad as shown in picture below,




Enter IP address of your computer in front of Server Make sure your port number matches one on Fiddler2 by default it's "8888". You can change default port by going to Tools > Fiddler Options > Connections > Fiddler listens on port:  as shown in picture below,




Now if you also want to capture HTTPS (secured) traffic then check boxes as shown in picture below,




Next step would be clicking on "Export Root Certificate to Desktop" and sending certificate you just exported on desktop to your iPad through email. Once you received it on your iPad just try opening the certificate and install it.

That's it, you can start capturing traffic now, one thing I would like to mention is that my iPad and Computer has been connected to same intranet network while I was debugging.


Tuesday, 21 May 2013

Restricting picture size in ItemAdding event receiver for SharePoint picture library


If you want to restrict user from uploading a picture larger then specified size (width x height) then you can use code below.

Please note it only works when user uploads a single picture file, when user uploads multiple files, SharePoint opens Microsoft picture manager to upload several pictures hence HTTP Context comes as null. I tried to find a fix for it but I couldn't so if someone reading this post please comment the solution. Until then you can disable multiple picture uploads to library.

Ways around would be create a custom list definition and then a custom upload form with all of code logic behind, you can make it work for single files or several files but depends on your code behind logic and requirements.



class PicLibraryImageSize : SPItemEventReceiver
    {
        HttpContext _current;
        public PicLibraryImageSize()
        {
            _current = HttpContext.Current;
        }

        public override void ItemAdding(SPItemEventProperties properties)
        {
            try
            {
                this.DisableEventFiring();

                if (IspicTooLarge())
                {
                    properties.Cancel = true;
                    properties.ErrorMessage = "Picture Too large to upload !";
                }
            }
            catch (Exception ex)
            {
                //Log it
            }
            finally
            {
                this.EnableEventFiring();
            }
        }

        private bool IspicTooLarge()
        {
            HttpFileCollection cFiles = _current.Request.Files;

            HttpPostedFile pFile = cFiles[0];

            using (System.Drawing.Image image = System.Drawing.Image.FromStream(pFile.InputStream))
            {
                if (image.Width > 800 ||  image.Height > 600)
                {
                    return true;
                }
                else
                    return false;
            }
        }
    }

Wednesday, 24 April 2013

Copying GAC before deployment on SharePoint Production WFEs servers


Few days back I needed to deploy few projects on production server's, since our SharePoint 2007 is properly customized and GAC is packed with custom solutions assemblies, and these solutions do get updated regularly. These DLLs depends on each other so if I update GAC with wrong version of a custom DLL it will break customized SharePoint which I don't want to happen therefore need a backup of GAC as part of backup plan.

Of course we have SharePoint Team foundation and we document each change, but when your farm is broken because of your newly deployed project solutions (which also updated few customized DLLs) you want to roll back quickly and without taking any risk of "wrong documentation" or if someone updated production server and forgot to update TFS somehow.

Copying DLLs out of GAC isn't really a difficult task and is really helpful when it comes to roll back. Follow these steps to backup everything in GAC folder or only the DLLs you think you need,


  • Click on Start and then on Run.
  • Put this command in text box and click "OK", as shown in figure below.
                %windir%\assembly\GAC_MSIL





  • A window will appear with several folders but only folders you might need are ones shown in picture below,


  • Now you can copy all folders for backup or just find particular DLLs you need using search box. 
I personally copy all of folders and then once everything get's deployed perfectly, I delete the backup.

Wednesday, 10 April 2013

Get user's Name and there SID using CMD command


I created a windows form application to test one of custom web services I created but web services were getting IUSR_ESHAREDEMO  when I tried to get UserId using code given below,


string userID = HttpContext.Current.Request.LogonUserIdentity.User.Value;


I managed to get user I wanted by disabling the anonymous access for the web application in IIS Manager. However I used following CMD command to check login users on a server (there names and SID).


wmic useraccount get name, sid


Tuesday, 26 March 2013

Adding details to database table using SharePoint List event receiver

Here's a sample code to give you idea about how to add item details to database table using SQL stored procedure and ItemAdded event receiver,




    class myClass : SPItemEventReceiver
    {
        public override void ItemAdded(SPItemEventProperties properties)
        {
            try
            {
                this.DisableEventFiring();

                AddToDataBase(properties);
            }
            catch (Exception ex)
            {
                //log here
            }
            finally
            {
                this.EnableEventFiring();
            }
        }

private void AddEntryToDataBase(SPItemEventProperties properties)
        {
using (SqlConnection con = new SqlConnection(dc.Con))
using (SqlCommand cmd = new SqlCommand("sp_Add_ListItem", con))
{
cmd.CommandType = CommandType.StoredProcedure;
cmd.Parameters.Add("@Title", SqlDbType.VarChar).Value = properties.ListItem.Title.ToStrinng;
cmd.Parameters.Add("@LastName", SqlDbType.VarChar).Value = properties.ListItem.Name.ToString;

con.Open();
cmd.ExecuteNonQuery();
}
}
}

Check this link on MSDN for more information or just leave a comment below,

http://msdn.microsoft.com/en-us/library/ms437502(v=office.14).aspx